Python Forum
compiling to python-- should ; be used or not?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
compiling to python-- should ; be used or not?
#1
the way i code uses ; a lot-- it puts statements together like this:

print(5) ; print (12)
the reason i do this is because it fits more code per page, which makes it easier (for me) to read what im doing.

of course, the convention / recommendation is to not do that:

print(5)
print (12)
im aware that there are various ways to combine these statements together in purpose, but two print statements was just an example.


if you were writing (or cleaning up) a compiler that output python code, and it combined (some, not all) statements with ; like that, would you change it from the first way?

print(5) ; print (12)
and have it output python code the second way?

print(5)
print (12)
if so, why? and if not, why?


not a quiz, im very interested in peoples opinions (brief or otherwise) on this sort of thing in general. im always trying to understand peoples opinions on this. my preferences are already noted, im asking should i learn something. im sure that happens more often than its expected, at least.

i never even indented code (for almost 20 years) until i learned python. now i prefer it.
Reply
#2
Quote:the reason i do this is because it fits more code per page, which makes it easier (for me) to read what im doing.
Its easier for me to read without semi-colons.

In fact when i copy and fix someones code on the forum, i go through and remove the semi-colons as they bug me before i post it back on the forum.

It even bugs me that there was a space between print and the pareth
print(5)
print(12)
To me its better to have readability even at the expense of speed...which in that case does not.

But it can in list comps. I would say that its better to "unpack" list comps that are long and complicated to regular for loops for the same reason. Its better to be able to read it. And the speed increase is probably not worth it.

Same thing about regex. Some are simple and too simple that python has builtins for. Its easier to read without using regex in most cases. But yes, sometimes you just have to live with regex though.

for numerous imports i would do
from .states import (
    stats_screen,
    blackjack, 
    craps, 
    bingo, 
    keno, 
    video_poker
)
instead of spreading them off in a one liner.

The zen of python states...
Quote:Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Recommended Tutorials:
Reply
#3
If you want to write everything in one line, Python is the wrong language.

You can write mostly all languages in a single long line. But even then the programmers don't do it, because programming code is made for humans and not for Computers.

The concept of Python is, that we are enforced to use whitespace as indentation for blocks.
You should avoid using ; in Python, even when there are only two very short statements.
We are limited to width (79 chars, but more is possible), but not limited to vertical space. Your computer is strong enough to handle it. Just look for some Python code of famous projects in GIT There you'll see how to handle it.

If you reach the 79 char limit, it's maybe a miss-construction of code. If you release code, which does hit this limit, you'll be pepified. Many programmers don't see the elephant in the root.

Just look this Videos:
https://www.youtube.com/watch?v=wf-BqAjZb8M
https://www.youtube.com/watch?v=OSGv2VnC0go
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
considering going single-line for future (and major) code.

yes, theres a personal preference here, though perhaps with practice doing it another way...
Reply
#5
If you're writing a complier that outputs python code, then you may as well have it emit idiomatic python code. It's not like you're going to open it up and edit it anyway, right? So what's it matter?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  compiling with an undefined variable Skaperen 0 977 Nov-10-2022, 11:59 PM
Last Post: Skaperen
  compiling numpy, getting C source Skaperen 10 3,636 Nov-20-2021, 12:41 AM
Last Post: Skaperen
  python compiling and sql? abrogard 2 2,233 Oct-27-2020, 06:37 AM
Last Post: buran
  cross-compiling python with zlib support michelebucca 5 5,831 Aug-25-2020, 08:19 PM
Last Post: carterb
  compiling various versions of Python, which toolchain? Skaperen 4 2,670 Jun-06-2019, 06:28 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020