Is Python the new BASIC?
-
Hmm, not strictly true, as you would know if you'd ever used it in anger! 8) Having progressed through FORTRAN/Assembler/Algol60/68R/C/C++ etc, I too was surprised at the use of spacing to delineate blocks of code, but (and especially with a good IDE) it really isn't an issue, and is certainly no worse than the (to me completely daft) Java convention of opening a block at the end of a line, but closing it at the beginning of some random line later on. The number of times I've misread a piece of code because I didn't notice the brace at the end of a long line (yes, I know, my failing!)... Having done extensive dev in Python over some years now, everything from responsive web apps to OS loaders to processing compressed files too large to unpack to disk, in umpteen environments and OSs, I've come to appreciate just how good it is. Like every language it has its quirks and sillinesses, but the indentation isn't really one of them! As always, for most dev, the language is unimportant, its the programming that matters - but you won't convince the religious (language) nutters of that, of course! All IMHO, of course 8)
But IDE doesn't have mind reader ability. When we delete some spaces accidentally, at the last line of a code block in particular, how can it know that it was a mistake? How can it know that line of code should be a part of above block, and not simply the next line of execution?
-
But IDE doesn't have mind reader ability. When we delete some spaces accidentally, at the last line of a code block in particular, how can it know that it was a mistake? How can it know that line of code should be a part of above block, and not simply the next line of execution?
As I said, every language has its own quirks. In C type languages accidentally inserting or omitting a semicolon can completely change the meaning of a block of code, and adding/omitting '=' or forgetting a 'break;' can completely screw your conditional statements and an IDE wouldn't know about that either. In Javascript objects assigned from another object are references, not copies; this can be useful, but also makes it very difficult to ensure that data is atomic or immutable when that's necessary (ie code inside a deeply nested function can change apparently unrelated variables by 'remote control' if you are not careful). No language is perfect, and I have indeed had Python code behave unexpectedly due to indentation issues, but this has not been any more of a problem than things like those above, in fact, less. It is very easy to write tests for things in Python (because the language is so versatile) and that catches such things readily. For my web apps I use selenium for testing the 'user' interactions and my own internal tests for the model code. At the end of the day, very domain specific stuff possibly excepted, programming is programming and the language you use irrelevant. You are testing your code, aren't you 8)
-
As I said, every language has its own quirks. In C type languages accidentally inserting or omitting a semicolon can completely change the meaning of a block of code, and adding/omitting '=' or forgetting a 'break;' can completely screw your conditional statements and an IDE wouldn't know about that either. In Javascript objects assigned from another object are references, not copies; this can be useful, but also makes it very difficult to ensure that data is atomic or immutable when that's necessary (ie code inside a deeply nested function can change apparently unrelated variables by 'remote control' if you are not careful). No language is perfect, and I have indeed had Python code behave unexpectedly due to indentation issues, but this has not been any more of a problem than things like those above, in fact, less. It is very easy to write tests for things in Python (because the language is so versatile) and that catches such things readily. For my web apps I use selenium for testing the 'user' interactions and my own internal tests for the model code. At the end of the day, very domain specific stuff possibly excepted, programming is programming and the language you use irrelevant. You are testing your code, aren't you 8)
Really?
var foo = "Hello";
var bar = "World";
var message = foo + " " + bar + "!";I am pretty sure the IDE will throw an error right away if I deleted an ; Compare it to Python:
price = 1100
discount = 50
qty = int(input('How many do you want to buy? '))
total_price = qty * price
if qty > 10:
discount = discount + total_price/100 * 5
total_price = total_price - discount
print(total_price)The IDE won't find out anything if the indentation TAB on 2nd last line is accidentally deleted. But you are right, we should have made unit tests for everything. Only that I got lazy sometimes, especially if it's just a simple function. Ha ha ha.
-
Really?
var foo = "Hello";
var bar = "World";
var message = foo + " " + bar + "!";I am pretty sure the IDE will throw an error right away if I deleted an ; Compare it to Python:
price = 1100
discount = 50
qty = int(input('How many do you want to buy? '))
total_price = qty * price
if qty > 10:
discount = discount + total_price/100 * 5
total_price = total_price - discount
print(total_price)The IDE won't find out anything if the indentation TAB on 2nd last line is accidentally deleted. But you are right, we should have made unit tests for everything. Only that I got lazy sometimes, especially if it's just a simple function. Ha ha ha.
It's easy to find similar examples in any language 8) Javascript: var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}; var me = person; me.firstName = "mike"; What does person.firstName hold now? Would an IDE warn you that me was a reference? What if the assignment to firstName is miles away in other code? Compare that with similar code in C++, which by default will make a deep copy of the object so that person and me are not pointers to the same memory. In C: a = 1; b = 1; c = 0; if (a != b); { c = 1; } What value does c hold? I'm not saying a good IDE doesn't help, because it does - but that's true with any language, including Python. You can write bad code in any language (BTDTGTTS!), so my point remains: Python is different, but that doesn't make it better (or worse). You should use the most appropriate tool for the job, and for which you have the most skill. FORTRAN code is (was) position dependent too...