19 Réponses
+ 11
HonFu [#GoGetThatBugChamp!] Simple things like placing multiple lines of code within a new block, such as an if condition or for loop, etc, it requires properly maintaining the relative indents while moving all lines one indent over.
I've been in situations where I've lost track of which lines to manually indent and having to troubleshoot the missing indent. It's a silly pain to deal with.
However, that doesn't compare to having to restore indents when pasting code snippets from a website like SO or Python docs to Code Playground where all the line breaks and extra spaces are removed.
That's a fun experience. 🤣😂
+ 9
...continued
If you wanted a technical analysis while coding. Check the following links. Originally shared by David Carroll in some other post-- which i can't remember...
Some of the scoping and binding related issues aren't present in other languages.
http://docs.python-guide.org/en/latest/writing/gotchas/
https://www.toptal.com/python/top-10-mistakes-that-python-programmers-make
https://sopython.com/wiki/Common_Gotchas_In_Python
https://stackoverflow.com/questions/1011431/common-pitfalls-in-python
https://www.safaribooksonline.com/library/view/learning-python/1565924649/ch04s06.html
https://franklingu.github.io/programming/2016/01/11/common-python-gotchars/
https://pythonconquerstheuniverse.wordpress.com/2008/06/04/gotcha-%E2%80%94-forgetting-parentheses/
http://blog.notdot.net/2009/11/Python-Gotchas
https://franklingu.github.io/programming/2016/01/11/common-python-gotchars/
https://www.quora.com/What-are-common-programming-errors-or-gotchas-in-Python
+ 9
Tibor Santa Indeed... I take for granted how taxing this can be for those expanding beyond their core languages. For me, it's more apparent if I haven't been in the language for a few months.
I also think my own challenge has to do with my typing pace and style. Often times, as I'm rearranging code blocks at a time, shift down arrow several times, ctrl+x, up arrow a few times, ctrl+v, repeat several times more.
After a while, I need to reset my indents, so I'll tab+shift several blocks to the left margin and begin to work my cursor from top to bottom gradually applying indents back to their appropriate nested arrangement.
Doing this in Python is not possible and therefore, I have to be more meticulous about my rearranging of code.
Still yet, I've managed to fumble an indent here and there doing standard refactoring at a fast pace and need to slow it down as there aren't any end of block markers available in Python in case I lose my relative indent place.
+ 8
1. Indentation based syntax: Code must be formatted a specific way else it won't run. If it's handled efficiently by your text editor/ide then good! But most of the time needs manual formatting and is a nightmare without editor assistance(e.g, codeplayground).
2. Flexibility: Not allowing statements inside expressions print(a*=10).
3. Speed: A bit slow.
4. Size: The interpreter is heavy ~32mb installed (i prefer light...).
5. Rigidity: Syntax is fixed you can't modify or add additional constructs to the language unlike others: forth, lisp etc.
(How do i add lb for lambda keyword ?)
Re: debugging
It does have a debugger built-in. Plus strong types. So it may not be an issue.
Continued...
+ 8
@Honfu
Having it as an requirement vs it being optional is different.
I prefer not having artificial limitations in my language.(yes, i like adding numbers with strings 2+'hi', 3*'hi')
Plus when typing in repl & other places without editor support i'm not restricted by this one. Pasting code which has tabs is also an issue.
Python was my 2nd language after JS. But due to this and a few others issues.(Also found it a strain to continue...) jumped to ruby.
BTW, i'm not manually indenting my code. My editor does that for me. But It will still run even if there's a space or two more. Or perhaps, the tabs got collapsed for reasons...
+ 8
HonFu [#GoGetThatBugChamp!] It's the latter point. While I do indent for readability, things won't break if I don't. Moreover, I have to indent everything before I can even test the code, then restore it if I change my mind.
To make this more interesting, I created 3 codes with a function sumEachSet() that appends the sum of 2 numbers within a set of inner lists.
Starts with:
[[1,2],[3,4],[5,6]]
Ends with:
[[1,2, 3],[3,4,7],[5,6,11]]
I refractored function sumEachSet() to print addition info when the parameter is 1.
Review Code A to see the original sumEachSet() function.
Run Code C to review the expected output with additional logging info.
Then Run Code B and see if you can spot the 2 lines in the function sumEachSet() with incorrect indents causing the listed issues.
Links to Each Code:
https://code.sololearn.com/cH14rqyvm8hb/?ref=app
https://code.sololearn.com/cpOKX6kyN13c/?ref=app
https://code.sololearn.com/c1z8lcsc8T41/?ref=app
+ 8
The point I'm making is Python's dependency on code formatting makes it highly brittle with simple refactoring and increases the risk for bugs like no other language that uses explicit block endings.
Again... it's one of the many reasons I can't consider using Python on serious commercial application development where the code base is much larger and more complex.
This contrived demo reveals the need to closely inspect and compare the before and after changes as well as evaluate whether indents across the entire code are correct or not. This would be insane to maintain if refactoring was completed across many files.
+ 7
HonFu [#GoGetThatBugChamp!]
Formatting is something i let the editor(emacs) do for me--adding matching braces, indenting on a newline, etc.
It would start to become tedious if i was to manually do that for every line or code.
Tabs could reduce it but it would still exist. And i can't reliably paste in a webpage, or even here.
+ 6
HonFu [#GoGetThatBugChamp!] This is just a simple example to demonstrate how easy it is to overlook.
Realistically, I would be working in PyCharm with better tools and tab controls.
However, I've found myself, on the occassion, editing something simple in Code Playground and cursing myself for overlooking an indent issue.
It breaks my momentum, focus on the logic, and ultimately my productivity.
I think that might be the difference. If I was slow in any language, I probably wouldn't mind. But, I'm actually quite fast as writing code. When I stumble on something silly like a missed indent, it's hard to be forgiving as this isn't an issue in other languages.
Also, it would be interesting to see how the industry would have handled minification and obfuscation if Eich went with something like Python with indents. It simply wouldn't be possible.
Anyway, I'm thinking of this from a larger project sense. Also, spaghetti code would be the bane of any language. However, I'm assuming well written code. 😉
+ 4
One of my colleagues is a Lisp programmer. His main criticism on python was the usage of indentation as a syntactic element.. That made the language totally unattractive to him. :)
from __future__ import braces
https://code.sololearn.com/crfeEud14KTX/?ref=app
+ 4
Lord Krishna, okay, I see your point.
I haven't faced these issues too much, but the reason might be that I tend to indent by hand, like almost everything else (I don't like the 'help' of programs like IDE's or word processors at all and turn them all off as soon as I can).
Also Python was my first language (after a little C64 basic 30 years ago ^^), so maybe I'm just used to it.
+ 4
But isn't that rather a text format problem?
I saw that people posted stuff from their email provider or something and it didn't run because there was some strange whitespace thingy going on.
But as long as you don't do it, but just copypaste a consistently indented text to another window... I've done it between text editors, IDLE, QPython, and Sololearn, back and forth, and it never led to problems...
+ 4
David Carroll, okay, if you quickly want to copypaste a code from some homepage, it won't run if you don't repair the indentation.
But in any regular usecase, like when you refactor some C code and an outer loop suddenly becomes an inner loop; wouldn't you normally still indent it? So that people reading the code will understand it?
Or would you just leave it as it is, like this?
{
code
{
code
{
code
}
}
}
Point being: How is adding this whitespace different to doing it in Python?
Okay, or is your point, even if it isn't indented perfectly, at least it will still run?
(Personally I feel like I might search for a missing } or ; just as long as for a wrong indentation.)
+ 3
I always find that amusing.
As if it was SO hard to hit tab!
Where I come from, there's a proverb:
'The farmer doesn't eat what he doesn't know.'
+ 3
One question though, Krishna.
I have read quite often in this place and others, that writers of C, Java or any other language should indent properly, because otherwise it will be unreadable.
So if we do this anyway, why is it bad to abolish the {}; babble and just indent?
+ 3
David Carroll funny because I found myself in the same situation but with Java.
When I started picking up programming recently, I began with Python. And I just got used to the indentation quickly so it never occured to me as an annoyance, simply just a set of rules you follow when writing code. And I did follow (with the support of pycharm usually) and I don't remember encountering any indentation errors in my own code.
However when I switched to learning Java, I had a hard time remembering the semicolons at the end of each line... And I cursed a lot when I got those syntax errors.
Being fluent in several languages and especially switching between them, I think that is a rare skill and it puts a heavy tax on your brain :) So I also understand your point, that the indents having semantic meaning instead of just decoration to help readability, can pose a certain risk to a project, even if all developers are consistently using the coding guidelines.
+ 2
Hard to debug?
Types may be not static, but they're strong, and generally the code is simplified, so usually you should do fine imo with the exception handling.
+ 2
Isn't it just line 20 that's incorrect?
Ah, and line 15. :)
But don't you normally just have to watch the indentation within one coherent block of code, let's say a function or a class?
As long as these modules remain intact each, they should also cooperate.
Of course you could write ultralong spaghetti code functions or classes, but that would make no sense in any language.
0
1. Slow
2. Hard to debug because of not having static types
3. Cannot be run without Python interpreter installed (if you don't use stuff like cx_freeze)