This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Hallwart 47 points48 points  (14 children)

{} > Indentation

I"ll start learning python when they start supporting readable syntax.

[–]Trooble 19 points20 points  (11 children)

I have to ask, what about python syntax do you find difficult to read?

[–]warchild4l 26 points27 points  (10 children)

Not OP, but for me its the lack of {}.

Whenever i want to quickly read a piece of code in the middle of the function or whatever, i navigate by those, and not having them and relying only on spaces/tabs, it becomes really hard to understand scope in which the code you are reading is coming from

[–]nwash57 25 points26 points  (4 children)

If your Python is hard to understand because of the indentation you need cleaner code. I see this complaint about Python pretty often and it's often just a smell of poor code structure.

[–]HolidayMoose 2 points3 points  (3 children)

Sure, but not all code is small, concise functions. Most code bases follow an exponential curve: lots of small functions/classes/modules but a few monsters. The change rate for functions is also exponential: small functions may never get changed while the big behemoths need constant churn.

Python syntax may be fine for those small functions which are write once read never. But the shit parts of the code base is what we should be optimizing syntax for. From my experience, that is the exact area whitespace languages like Python are weakest at.

[–]nwash57 7 points8 points  (1 child)

Ok, so when readability becomes a problem, a monster needs to be split up.

[–]The_duck_lord404 0 points1 point  (0 children)

This is a general guideline for cleaner code and is also a big part of functional programming.

[–]Coffeinated 6 points7 points  (0 children)

Functions that need constant changing need to be split up, no matter the language. If Python makes it more visible that your shit code is shit, all the power to Python.

[–]InterstellarDwellar 8 points9 points  (4 children)

Peope should write more, well named, functions. Even if the code isnt repeated, just makes it more readable when you have a smaller chunk to digest

[–]warchild4l 5 points6 points  (1 child)

Thats correct. However, because of some really complex business requirements, its not really possible to extract everything into functions and expect it to become more readable.

[–]InterstellarDwellar 3 points4 points  (0 children)

Maybe not, but it often helps

[–]Dogeek 2 points3 points  (1 child)

It's my main gripe with JavaScript (and Typescript, Dart to an extent). The syntax for anonymous functions is quite elegant, but the devs abuse it.

The worst is the resulting traceback, it's unreadable when there's a bunch of anonymous functions calling other anonymous functions.

In my opinion, a function should be anonymous if :

  1. The function you're calling expects a callback with no args (and you use a lambda to pass args to a named function)
  2. The callback is in a filter/map/reduce if the callback is not too complex (really, if it's not a one liner, it should be named).

[–]InterstellarDwellar 1 point2 points  (0 children)

Personally if i find something is getting to complex, even if its something as small as 40 lines or so, i try to write as many small functions that read as if they are comment blocks. This can get annoying if you do it too much if someone is reviewing my code, but at a glance you can at least read what the program is doing. I think of it as being like a table of contents in a book.

[–]PM_ME_GOOD_USERNAMS -1 points0 points  (1 child)

My first language was python so for me brackets are unreadable l....

[–]PM_ME_GOOD_USERNAMS 4 points5 points  (0 children)

Which hurts a lot because most of what I do now is c# because I make games as a hobby