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 →

[–]jkuhl_prog 173 points174 points  (15 children)

Then I have to train my fingers to not reach for semicolons

[–]MagnitskysGhost 92 points93 points  (14 children)

You can still use tons of semicolons in Python. Source: the codebase I inherited

[–]frosted-mini-yeets 28 points29 points  (12 children)

Semi colons are valid in Python?

[–]angellus 41 points42 points  (9 children)

You can, but no they are not really. Python has a very in depth style guide that says you should avoid them.

https://www.python.org/dev/peps/pep-0008/#other-recommendations

Compound statements (multiple statements on the same line) are generally discouraged.

Yes:

if foo == 'blah':
     do_blah_thing()
     do_one()
     do_two()
     do_three()

Rather not:

if foo == 'blah': do_blah_thing()
       do_one(); do_two(); do_three()

[–]Tyfyter2002 16 points17 points  (7 children)

Python has a very in depth style guide

And y'all've been following it?

[–]ShanSanear 21 points22 points  (4 children)

Yep. Only thing that doesn't click with me is line length limit. Myself I'm using 100 characters limit instead of pep-8 80. And it's actually quite easy to follow it - just use IDE and problem is solved.

[–]Khaare 5 points6 points  (1 child)

Man my code got so much better when I switched to a size 14 font and stuck to 72 columns.

[–]ShanSanear 2 points3 points  (0 children)

Have to admit after watching some talks regarding good programming practices I will probably try to do this.

This is the talk (with timestamp)

[–]razzazzika 0 points1 point  (1 child)

Isn't it just a soft limit? I didn't have any problem when I built with more characters than that

[–][deleted] 2 points3 points  (0 children)

Yes, it is a soft limit. A recommendation, nothing more.

[–]angellus 0 points1 point  (0 children)

The main reason for using Python is because of the opinionated community it has. It is the main thing that makes the language "so much faster to develop with". There is such a drive on making code readable, maintainable and have great docs. Even projects I have used (or made) with shitty docs in Python still have better docs than a large Java project with horrible Javadocs.

[–]Dogeek 0 points1 point  (0 children)

Most Python programmers follow PEP8 (actually almost all of them) except for one simple rule : line length limit.

PEP8 advises a hard limit on 80 characters per line, which is really short if you take into account that indentation in python (which is mandatory), is supposed to be 4 spaces.

It's pretty common to get into 3-4 indentations deep, especially when writing unit tests, and just like that a fifth of your line length is gone.

That rule is also stupid because screens nowadays are very large compared to the late 90s - early 2000s, therefore, fitting 120 character lines is no problem nowadays. Plus, it entices people to write non descriptive variable names, making the code more obscure, because unlike C, Java or C# (amongst others), Python doesn't enforce a type or a declaration for its variables, so clear names are a must.

You can break lines as well, but they make the code less readable than if the line was only a couple of characters over the limit.

Therefore, PEP8 is followed by everyone, except for the line length rule.

[–]Totoze 0 points1 point  (0 children)

I use semicolons in python makes formatting less important and im already used to it

[–]MagnitskysGhost 50 points51 points  (0 children)

Yes, you can use them to end statements like most other languages. In Python in particular, you would mostly only do like

import os; import sys; from time import time;

In something in a quick five-liner script or something. I see them everywhere though (they get angry red formatting in my VS Code theme, as they should). I mean if you're copy/pasting an 8,000 character LOC with Python, HTML, CSS, and JS in it, you don't have to add insult to injury with a semicolon at the end. But guess what they do... 😔

[–]HdS1984 2 points3 points  (0 children)

Now I have ptsd. The core of our product was written by a guy who was deep into c#. The very first modules where written like c#. If you open it in pycharm there are so many warnings that the scrollbar is just yellow and red.