Hacker News new | past | comments | ask | show | jobs | submit login

One of the comments is good. Basically, it asks, why the need for semicolons at all?



Probably to make it easier for programmers who end lines with them as a knee jerk reaction. After a stint of java or javascript, I find myself doing it too.


And you can put two or more commands on one line.


I use them for this purpose in both Python and Ruby when there's a formatting win to be had.


Yeah. Often it's bad style, but IMHO if you just need to do something like:

    x = 0; y = []; z = None
Then it is actually clearer to group them together, it means more "real code" on screen at a time.


In this case you could just use:

x, y, z = 0, [], None


I do not know whether that was a good example to show the benefits of the semicolon:

    x, y, z = 0, [], None


While the semicolon is only a convenience it has some common use cases. For example shoot-and-forget invokations of third party modules:

  import sys; sys.exit()
  import pdb; pdb.set_trace()
  import cgitb; cgitb.enable()
  import psyco; psyco.full()
  import pygtk; pygtk.require('2.0')
And of course it's pretty useful in environments where one-liner are easier to handle:

  $ python -c "import mymod; mymod.test()"


Now that I look in my code I actually have:

    import matplotlib; matplotlib.use('Agg'); from matplotlib import pyplot




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: