Wednesday, December 30, 2015

Code in Different Languages

The other day I found an older blog post by Rob Underwood called Code Syntax Compared. In it he wrote a very simple program in 5 different languages. He used Python, Ruby, JavaScript, PHP and Java. No .NET languages. So since I was interested I wrote samples of the same program in C# and Visual Basic. Hey why not.

The most interesting thing to me is the typing. That is to say that some of the languages that Rob used are dynamic type languages while Java, C# and Visual Basic are statically typed languages. Which is better? Well like so many things in computer science – it depends. There is a good paper (the link is to a PDF)  on the topic - Static Typing Where Possible, Dynamic Typing When Needed: The End of the Cold War Between Programming Languages by Erik Meijer and Peter Drayton.

Anyway, if you are curious my samples are below:

C# example

image

Visual Basic Example

image

5 comments:

Mike Zamansky said...

Rob is trying to write all the code the same way but I'd probably write the Javascript version more like (sorry the formatting is getting clobbered):

var triangleArea = function triangleArea(base, height) {
var area = (½) * base * height;
return area;
}

which is although on the surface looks the same, in some ways is very different. More similar to how I might write it in scheme:

(define triangeArea
(lambda (base height)
(* base height 1/2)))


A wonderful related to this is Rosetta Code.

For example: http://rosettacode.org/wiki/Function_definition

Garth said...

This is why I think it is important for CS kids (those thinking of going on in CS at the college level) to see several languages in high school. Not to get "good" at the languages but to get good enough to see the differences and not be freaked out because of the differences. Most of my kids see primarily Scratch, Small Basic and Python. But I make sure we dabble a little in VB just for the GUI and variables. For some reason I have never figured out VB (or C#) is not well liked by university CS departments as a teaching language but for certain applications it is the best language to use.

Alfred Thompson said...

I like to see students exposed to different languages as well. I think it helps them a lot.

One of the problems with exercises like this one though (and Mike Z points this out to some extent) is that it ignores idiomatic ways of doing things in different languages. I don't want kids to write FORTRAN programs in many languages.

Rob Underwood said...

(Cross-posted on http://cestlaz.github.io/2016/01/01/different-languages.html#disqus_thread)

Thanks for referencing my blog post. I had meant for that to be the start of me blogging at least weekly and you can see how that worked out. Good push to get going again. Thanks.

I wrote the post primarily for an individual friend but largely with some of the NYC tech/start-up community in mind, namely those who chase after the next "hot" technology.

I lived in the valley for a year 15 years ago ('99-2000). A year is not a ton of time, but I worked at a startup (Pandesic) and got a sense of the place. When I was consulting I had a couple projects that kept back there for for 35-40 weeks a year for 4-5 years straight in the latter part of the last decade.

I think because of the historic roots of tech there in the universities, and that tech is simply not such a new industry, there is less chasing after the next fashion in tech. Don't get me wrong - it absolutely does happen there. But in the valley I feel in general like there are on the whole a greater concentration of sophisticated and mature (and outright older) programmers who don't necessarily throw out everything as soon as a new framework comes along.

This has struck me in NYC with things like Rails and Node. Mongo and NoSQL more generally too. A few years ago, Rails was **it** in NYC. Now in the NYC startup community Rails is about as cool as being over 30 (i.e., very uncool). Now it's Node. If you're hip, you're doing node, and - no surprise - the bootcamps have followed that trend. Ironically Ruby on Rails is probably a much surer technology choice now than when it was "hot".

But as Mike and I have discussed in person, I worry about new developers who don't take the time to learn the fundamentals, especially as a follow up to a bootcamp. No, you probably don't need to know how to do detailed circuit design. You can probably get by I guess not knowing what a flip-flop is. But maybe knowing a bit of boolean algebra, and understanding how logic gates fit in could be helpful. And if schools are going to insist that you do everything at the command prompt and in vi, then it would be good to learn while you're at the shell a little DNS, routing, port and protocols, and IP topology too so you can do some basic network troubleshooting when your web app won't connect to the database.

So a point of my post was to show just how superficial the initial syntax differences are. Of course, once you get past the initial syntax the differences are substantial. Mike's JavaScript syntax is more standard -- mine was an effort to make my code look as much like the original Python and Ruby examples as the start.

Frameworks are perhaps when this fashion comes in most. At Relay Graduate School of Education, where I was CTO until this past July, we used a PHP framework called Symfony. Not very popular in NYC - long story how we ended up with it, but somewhat popular in Europe. Quite a good MVC framework though. And if you knew another framework like Rails (e.g., you know the *concepts*) you could pick it up pretty quick. But we'd interview folks fresh out of bootcamps who would say "Oh, I don't want to do that -- I only want to do Rails" and then, after a while "I only want to do Node". They just didn't realize that the comparative work of learning another framework might make them a much strong overall development AND a better RoR developer.

Another wrinkle to my post is I wanted to include JavaScript and PHP which are not as often seen at the command prompt as Python and Ruby.

To Alfred's point, my bad on not doing a .NET language, the NYC tech fashionista equivalent of being over 40 and living in Park Slope (supreme uncoolness!), especially as my most substantive hands-on development work was in ASP and VB back in the day at Pandesic, getting MS technology to play nice with SAP and ABAP (and Japanese SJIS). Oh boy, have I dated myself now!

Mike Zamansky said...

(Cross posted my comment to Rob on my blog)

Rob - thanks for commenting - you should certainly pick up the blogging (and this comment could be a great post to kickstart with).

I see a lot of the superficial stuff coming out of the coding schools (including very well regarded ones).

That's fine in that it's preparing people for entry level jobs that they otherwise wouldn't have been able to get and it's also a good business model since they can charge another arm and a leg to teach the new hotness next time around.

It get's me when they presume they are actually experienced knowledgable teachers -- it's easy when you have a group of people who have been creamed and who have to complete pre-work thus ensuring a self starter who wants to learn the stuff and could probably do much of it on their own. It's another to do this with a random assortment of kids.

I've seen kids who have come out of some of these programs and I've seen teachers "taught to teach CS" from them as well - not pretty.
• Edit• Reply•Share ›