logo

 

     
 
Home
Site Map
Search
 
:: Bitwise Courses ::
 
Bitwise Dusty Archives
 
 
 

rss

 
 

ruby in steel

learn aikido in north devon

Learn Aikido in North Devon

 


Section :: Rants and Raves

- Format For Printing...

Programming With Style

Idioms and Standards....
Thursday 14 July 2011.
 

Over the years I have written articles, tutorials and books on a wide variety of different programming languages – everything from Pascal to Prolog. These days, as my company programs IDEs for Ruby and the Flash Platform, my programming is largely restricted to three languages: Ruby, ActionScript (for Flash) and C# for the development of Visual Studio tools.

So, when I switch from one programming language to another do I change my coding style to fit the language? The answer is: up to a point. Or, to put it another way: as little as possible.

Obviously, a language such as Ruby is syntactically very different from a language such as C#. To take a couple of simple examples: Ruby does not require typed variable definitions, C# does; Ruby uses keyword..end pairs to delimit many language constructs whereas C# uses curly braces, and so on.

But beyond that, what about the specific ‘idioms’ applicable to specific languages? I came across this (largely negative) review of my Ruby programming book recently, which reminded me of just how fiercely devoted to language-specific idioms some programmers are. The truth of the matter is, I am not. I don’t make a habit of setting different tab-settings when I switch from one language to another (4 spaces per tab in C#, say, but 2 in Ruby) nor do I change my naming conventions for methods and variables any more than is absolutely required by the syntax of the language.

I have to say that, for purely aesthetic reasons, I have never liked excessive use of underscores in my method names but I have no objection if other people use them. Here is a passage from the introduction to The Book Of Ruby that explains my approach:

Matters of Ruby Style

Some Ruby programmers have very fixed—or even obsessive—views on what constitutes a “Ruby style” of programming. Some, for example, are passionately wedded to the idea that method_names_use_underscores while variableNamesDoNot. The style of naming in which separate words are indicated by capital letters likeThis is called camel case—and that is the last time it will be mentioned in this book.

I have never understood why people get so worked up about naming conventions. You like underscores, I can’t stand them; you say po_ta_toes, I say poTaToes. As far as I am concerned, the way in which you choose to write the names of identifiers in Ruby is of no interest to anyone but you or your programming colleagues. That is not to say that I have no opinions on programming style. On the contrary, I have very strong opinions. In my view, good programming style has nothing to do with naming conventions and everything to do with good code structure and clarity.

Language elements such as parentheses, for instance, are important. Parentheses clarify code and avoid ambiguity that, in a highly dynamic language such as Ruby, can mean the difference between a program that works as you expect and one that is full of surprises (also known as bugs). For more on this, refer to the index entries on “ambiguity” and “parentheses.”

In more than two decades of programming, one thing I have learned through bitter experience is that the most important characteristics of well written code are clarity and lack of ambiguity. Code that is easy to understand and easy to debug is also likely to be easier to maintain. If adopting certain naming conventions helps you achieve that goal, that’s fine. If not, that’s fine too. The Book of Ruby does not preach on matters of style.

Quite often, over the years, Ruby programmers have suggested that my stylistic preferences derive mainly from Java. That is simply not the case. For some insight into my stylistic preferences, however, you may want to take a look at a series of articles I wrote called Ruby The Smalltalk Way. I would also recommend the book ‘Smalltalk With Style’ by Klimas, Skublics and Thomas. You can download a copy of this book from Stephane Ducasse’s excellent repository of free Smalltalk texts: http://stephane.ducasse.free.fr/FreeBooks.html. While I don’t slavishly follow the stylistic ideals outlined in that book, I think the fundamental ideas are sound.

Actually, I suppose I should own up to one pretty strong stylistic prejudice and it is this: if you want to develop a good object oriented programming style, learn Smalltalk! :-)

Squeak Smalltalk: Still beautiful after all these years.
AddThis Social Bookmark Button


Home



 

http://www.actuabd.com/?order=829594 buy generic avanafil buy fluticasone inhaler enalapril malaete bactrim plus fmg buy lipitor online rifaximin pricing cialis super active 100mg metronidazole norvasc 2.5mg buy amlodac online http://www.actuabd.com/?order=904510 buy modalert no prescription overseas pharmacies in usa fludrocortisone buy andriol fast cheap online in usa prilosec sale in canada 10 lipitor mg http://www.actuabd.com/?order=420167 nizonide for sale buy tenofovir disoproxil fumarate information lumigan 0.01 bactrim 250 in mexico bactrim 800 mg more info about buy finasteride online buy lithosun online buspin 5 buy piracetam capsules in mexico http://www.actuabd.com/?order=344662 sustanon sale buy bactrim cotrim septra buy gleevec uk http://www.actuabd.com/?order=448531 generic urimax order simvastatin online quinine sulphate 300mg in new york http://www.actuabd.com/?order=805514 budeprion sr 150mg where to buy andriol testosterone pills http://www.actuabd.com/?order=696079 modalert 200 cheapest natamet flagyl online no prescription in uk gleevec price omeprazole 40mg generic 10mg lipitor lasix 40mg buy zhewitra canada malegra buy ciprofloxacin online without a prescription diflucan sale buy sustanon low prices 1300 mg of quetiapine low cost diflucan imatinib mesylate 400mg kamagra oral jelly budeprion xl generic amitriptyline sale