Saturday, March 10, 2012

I was wrong

about syntax - semicolons and curly braces are a good idea.

I used to prefer line breaks to delimit lines of code and indentation to delimit blocks (as in Python, but without the colons, or Haskell). I've changed my mind.

Semicolons are a good idea, because logical lines of code should not be forced to be physical lines of code. It is nice to limit physical lines of code to a certain number of characters, say 80, this is useful for doing side by side diffs, etc. But often a logical line of code will be much longer than 80 chars, especially if you are using descriptive names for functions and variables, which is usually a good idea. Thus, you need to break a logical line into several physical lines, and this means you need a delimiter - enter the semicolon. Also, frankly, it is not much effort to type a semicolon, it is so far down my list of daily worries it barely registers.

My argument for curly braces over indented blocks is much more intuitive, after working on a large-ish Python project, I simply found indented blocks (for large methods/classes) too hard to read. Braced blocks are not perfect either, and can easily be abused, but the make reading easier for me. Perhaps this is just down to habit, after all, I am much more used to reading braced code, but I did a fair amount of Python programming and reading indented code never got easier.

Bonus thing I was wrong about - you will always need style guidelines, you can't hope to always codify such things in the compiler, see combining indentation with braces. But, this is something your IDE should really be doing anyway.

7 comments:

Vale Co Xenia said...

Great Article
B.Tech Final Year Projects for CSE in Python
FInal Year Project Centers in Chennai


Python Training in Chennai
Python Training in Chennai

Rathinam said...

I recently visit this blog and I gain more knowledge from this blog.
Unix Training in Chennai
Unix Certification in Chennai
Oracle DBA Training in Chennai
Social Media Marketing Courses in Chennai
Pega Training in Chennai
Tableau Training in Chennai
Spark Training in Chennai
Linux Training in Chennai
Primavera Training in Chennai
Power BI Training in Chennai

jamuna said...

Interesting blog. Got a lotb of information about this technology.
Spoken English Classes in Chennai
English Coaching Classes in Chennai
IELTS Training in Chennai
Japanese Language Course in Chennai
TOEFL Training in Chennai
best english coaching in chennai
chennai spoken english classes
French Language Classes in Chennai
content writing course in chennai
spanish courses in chennai
Spoken English Classes in Porur
Spoken English Classes in Adyar

merlin said...

The blog is very good to read. I like this blog. Thankyou.
Selenium Training in chennai | Selenium Training in annanagar | Selenium Training in omr | Selenium Training in porur | Selenium Training in tambaram | Selenium Training in velachery

Unknown said...

wonderful article. Very interesting to read this article. I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries. keep it up.


Java Training in Chennai

Java Course in Chennai

rajmohan1140 said...

I have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective.

Java Training in Chennai

Java Course in Chennai

Tamil Typing said...

Thanks for sharing informative post. Are looking for best Tamil typing tool online, make use of our Tamil typing software to make translation faster. Thirumana Porutham in Tamil | Samacheer Kalvi Books PDF