Simon McAuliffe wrote:
> It's OK. But it is encumbered by one overriding and crippling original
> design decision: that code blocks should be decided purely by
> indentation. I originally considered Python for RepRap, but the
> indentation thing is so utterly dumb (just like tabs in Makefiles) that
> I voted against it.
I think this is one of the great things about Python. I agree make's use of tab is insane because it is an invisible character which gets modified by editors etc. Python uses indentation level to indicate blocks rather than curly braces or "begin ... end". This is fantastic for the following reasons: -
1. If it looks right then it is right, you don't have to search for hard to spot missing braces etc.
2. It saves screen lines so you can fit more code on the screen at a time making it easier to read.
3. It forces people to indent their code uniformly. With {} languages there are lots of different ways of indenting it and everybody has different preferences.
I use the original K&R style:
..if(something) {
.....do_something();
..}
More common but wastes a line is:
..if(something)
..{
.....do_something();
..}
Less waste but ugly:
..if(something)
..{ do_something();
..}
Insane:
..if(something)
.....{
.....do_something();
.....}
There are even more permutations, I always omit the braces when the block is a single statement but a lot of people don't. Hardly any two programmers like the same format and millions of man hours must be wasted by people reformating code to their prefered format so that they can read it and modify it. Then when you do a source control diff it looks like every line has changed.
In contrast, the only way to make a block in python is by positive indent, the only choice is by how much.
...if something:
.....do_something
Much easier to read, shorter, more like natural language, hard to get wrong, easy to see if it is wrong. When did you ever see an English paragraph denoted by braces or begin / end?
Granted you do need an editor where you can select a block of text and hit tab to indent it of shift tab to un-indent but that is common these days. Also you must not use tab characters as everybody sets up the their editor differently. It would have been better if Python rejected tabs in the source code. Commenting out code is a bit of a pain but apart from that I love it.
Other things going for it are it is very easy to learn and very productive. It also seems a lot easier to write portable code looking at the problems people are having with the Java host stuff. You don't need a complicated developement and build platform like Eclipse and Ant, or any fancy packaging. You just edit it with a text editor and run it, then zip it up and unzip it anywhere and run it.
Just my opinion but I have been writing software for 30 years now and I would always now use Python first choice, C++ then C then assembler, depending on how powerful the hardware was. I hear good things about Ruby from friends who's opinion I respect so I may learn that sometime.
PS.
The forum removes leading whitespace so I replaced it with dots.
Edited 2 time(s). Last edit at 06/21/2007 07:28PM by nophead.
[
www.hydraraptor.blogspot.com]