1

I love the semicolons and curly brackets from C and PHP.

Now I am starting to program with Python and when the code gets bigger it seems to me very messy without them (the curly brackets and semicolons).

The orientation in PHP or C is much efficient and faster, at least for me.

On the other hand I like many features of Python.

However, I think that maintaining the code will be very hard after some time.

How do you write readable code when there are no semicolons and braces?

Is there any plugin for Eclipse or Netbeans which will emulate semicolons and curly brackets.

ADDITIONAL QUESTION: Is there a version of Python with semicolons and curly-braces?

SOLVED !!!

I have found something which looks like an improved version of Python http://writeonly.wordpress.com/2010/04/01/whython-python-for-people-who-hate-whitespace/

I will give it a try.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
marian
  • 479
  • 3
  • 9
  • 17
  • Python can stay readable, thanks to a couple rules documented [here](http://www.python.org/dev/peps/pep-0008/). However, a curly braced Python is impossible. – Thaddee Tyl Jul 22 '11 at 08:03
  • And what when my line of code is too long or my monitor is small? I think nothing can beat curly brackets and semicolons. It is straightforward and clear for everybody. I used to have similar problems with Visual Basic too. Is there a version of Python with braces? – marian Jul 22 '11 at 08:06
  • You can still use the backslash at the end of line, which removes the end of line. – Thaddee Tyl Jul 22 '11 at 08:08
  • 2
    If your line is too long, use that big key right above Right Shift. – Jacob Jul 22 '11 at 08:08
  • Maybe this is what I am looking for http://writeonly.wordpress.com/2010/04/01/whython-python-for-people-who-hate-whitespace/ – marian Jul 22 '11 at 08:10
  • 1
    Ok, this is too much. You are messing with us right? Look at the date of that post. – Jacob Jul 22 '11 at 08:14
  • see how to use braces in python at: http://stackoverflow.com/questions/1936190/is-it-true-that-i-cant-use-curly-braces-in-python well, sort of :) – HongboZhu Jul 22 '11 at 08:15
  • see how to use braces in python at: http://stackoverflow.com/questions/1936190/is-it-true-that-i-cant-use-curly-braces-in-python well, sort of. – HongboZhu Jul 22 '11 at 08:16
  • @marian: if a line is too long to fit on screen, that's an indication that the line is too complex and should be broken down. Python aims for simplicity of expression. – outis Jul 22 '11 at 08:24

3 Answers3

16
>>> from __future__ import braces
  File "<stdin>", line 1
SyntaxError: not a chance
Jacob
  • 41,721
  • 6
  • 79
  • 81
  • 4
    This happens because `Python` doesn't have `__past__` module (which braces should belong to). – Nemoden Jul 22 '11 at 08:08
3

there is semicolon:

a=3; b=4

I don't see how braces make the code any more readable.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • And on that matter, I don't see how semicolons (especially this use of them) make the code any more readoable. –  Jul 22 '11 at 10:37
2

One thing that makes code less readable is cluttering up your code by saying things twice.

Indentation to clarify block structures is good practice in most languages (notable exception - the language that shall not be named, first syllable "brain").

Given that the indentation is there to describe the block structure anyway, why repeat yourself by adding braces?

C++ is my main language, and I'm not going to call this duplication evil, but it's a happy thing to get rid of this small annoyance and minor clutter (and get slightly more readable code) when I use Python.

It's also nice that Python makes a particular extreme evil impossible - cases where the braces are inconsistent with the indentation, so that the indentation is misleading.

BTW - a lot of the old prejudice about significant whitespace is due to languages like Fortran - which have an entirely different (and evil) approach to significant whitespace. A lot of old-timers have a kneejerk response because of that - and a lot of youngsters have a kneejerk response because it's not what Java (or whatever) does, of course.

Haskell also has a similar style of significant whitespace to Pythons. In Haskell, the braces are still valid - you can use braces to keep a block on one line, or you can use indentation only, or you can use both. It's not just Python and its imitators that make indentation syntactically significant.