Python Forum
It seems like the overall Python syntax would be error prone
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
It seems like the overall Python syntax would be error prone
#11
(Apr-01-2020, 08:18 PM)bowlofred Wrote: The interpreter requires only that the spacing is consistent. But for readability by others, there are standards that should be followed unless there is a good reason to deviate. 4 spaces per level is suggested. https://www.python.org/dev/peps/pep-0008/#indentation

I used a code editor some time ago that had an indentation default of 4 spaces and tab settings to make that easy. I found that my code was getting indented so much that a lot of lines wouldn't fit on one line. I ended up changing it to 2 spaces.

Is there any problem if I use 2 rather than 4 for my code?
Reply
#12
(Apr-22-2020, 01:30 PM)CynthiaMoore Wrote: Is there any problem if I use 2 rather than 4 for my code?
it will be difficult to distinguish different levels.
(Apr-22-2020, 01:30 PM)CynthiaMoore Wrote: I found that my code was getting indented so much that a lot of lines wouldn't fit on one line
that may be indicative of poor code structure. Probably it's possible to refactor the code to more flat code
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#13
(Apr-02-2020, 12:12 AM)CynthiaMoore Wrote:
(Apr-01-2020, 08:29 PM)stullis Wrote: One main benefit of Python's syntax: it forces coders to properly indent their code.
I am 100% behind proper indentation and all other readability measures, but I'll be interested to see how many times I get a maddeningly elusive bug because I realized that a line of code in one level of nesting belonged in a different level and didn't quite get the indentations lined up correctly.

I guess if I were designing a language today, I'd look at including the End statements and then having the IDE enforce the indentation. With modern graphic tools, the IDE could also do something with color or font or highlighting or something. It's very different from when I used to type BAL statements onto punch cards on an 029. Tongue

Hi,

I have already forked Python to have proper { } blocks and get rid of this fancy indentation rules. If is there anybody interested I can make my git become public or share the diff file. To be clear, the forked version can still continue to work on indented-style files, you can just decide every time you open a statement if you want to use the indent-style or { }.
Reply
#14
davide73_italy,
Python is not C -- brackets are used for other purposes.
Sets use brackets, and they are used to indicate formatted attributes in an f-string.
Python's been around now for 31 years, and has made it to the top with indentation only, no brackets.
I'm an old C programmer, and didn't like indentation at first. Now it just feels natural.
Give it a chance, you'll soon learn to love it.
Reply


Forum Jump:

User Panel Messages

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