views:

163

answers:

4

Today someone asked me what was wrong with their source code. It was obvious. "Use double equals in place of that single equal in that if statement. Um, i think..." As i remember some languages actually take a single equals for comparison. Since i sometimes forget or mix up the syntax details among the several languages i use, i stepped over to my laptop to try a quickie experiment...

It costs a bit of time and is a break in the flow to try "quick" experiments (though maybe the practice is good for memory.) What tips do you have for keeping straight in your mind the syntax (and other) details of multiple languages?

(And nowadays, this applies just as well to the many wiki-like markups!)

+1  A: 

In my case it's just experience. I think once you code in a language for long enough your brain seems to be able to do language-context-switching with it.

MDCore
well that's disappointing! you mean i hafta actually *do work* instead of hanging out at S.O.? 8P
DarenW
Hey, just sharing my experience! Maybe someone else will give you a link to some software which solves all your problems :)
MDCore
+1  A: 

IDEs that can draw red and yellow squiggles can help, until you develop that mental muscle memory.

One of the annoying things with XCode (for Cocoa/ObjectiveC) is that you don't get said squiggles until you compile. (As opposed to Eclipse/Java where you get live squiggles).

tunaranch
A: 

Indeed, on SO I advised not to forget avoiding if (a = b) in Java, and someone reminded me that it is legal only if a and b are boolean! Of course, the advice is good for C, C++, JavaScript and a number of other C-like languages.

Likewise, I realized only recently that var v in JavaScript have a function-level scope only, not a brace-level scope.

Somehow, that's the pitfall of having similar syntaxes, but different behaviors.

For the anecdote, some people in the Lua mailing list complain that this language isn't C-like, with the terse and familiar curly braces, the += and ++, the bitwise operators. They say it hurts adoption of the language, because people are more familiar with C-like syntax.

That's non-sense, Basic was (and still is) widely used with its verbose syntax. And so is Pascal (Delphià. And lot of people find the Lua syntax readable and easy to learn, good for those non familiar to programming (game AI specialists, for example).

Moreover, and to the point, Lua is designed to be integrated to C/C++ programs and to be extended with C[++] functions. And people say the quite different syntaxes helps in the mindset shifting.

PhiLho
+2  A: 

To me, the hardest part isn't the syntax -usually you get into the mode when looking at the code you're working on. The really hard part is remembering the library of the language so you don't go inventing the wheel over and over again. Now if only people would organize their help files so it was easy to search for particular stuff in the library.

Niklas Winde