views:

600

answers:

10

Are there any benefits to languages that terminate statements with a semicolon (C, Perl, etc.) compared with those that don't (Python, Ruby, etc.), or vice versa?

(Note to late-comers: the original title and question asked about "do you trust languages that don't use a semi-colon"; it was rewritten to be less argumentative. Some of the answers address the first version of the question.)

+4  A: 

Erlang uses ,; and . for different aspects.

BASIC doesn't require them.

I don't understand the obsession with ; In any well formatted code it is identical to a newline.

Rob Elsner
I agree with you...
featureBlend
A: 

Personally I think semicolons make code a bit easier to read, but in a language where they aren't required, such as Python, it wouldn't make me lose my trust in the language. If the code is formatted well enough, a new line is just as good as a semicolon.

John T
+2  A: 

In scala and javascript, they're optional!

Chad Okere
and also in Haskell
finnw
+3  A: 

I think it's a matter of habit, you get used to the syntax of the languages you more use...

CMS
A: 

I won't say "I don't trust a language" because of semicolon. But I do not like a language which without a termination mark.

A ";" does make lines easier to read.

For example, we my align code like this.

var a_very_very_long_variable_name_on_a_long_list = 1;
var short                                         = 1;

Without a ";", you may over look the value at the end of line on the other side. A line break is an invisible character.

For another example, we do have long if case occasionally

bool = ( a==b || c==d || e==f || .....);
   vs
bool =(  a==b
      || c==d  // comment of this 
      || e==f  // comment of that
      || .....
      );
   vs
bool = a==b
if(!bool) bool = c==d  // comment of this 
if(!bool) bool = e==f  // comment of that
bool = bool || e==f

I prefer the 2nd one, as I can do better description on each case without a lot "IF" or assign.

Dennis Cheung
+9  A: 

To suggest one doesn't trust languages without semicolons indicates a 'trust' in languages that have semicolons which is such a bizarre concept I can't get my head around it.

duncan
+4  A: 

According to wikipedia, the following languages are not semicolon terminated:

  • ALGOL
  • Pascal
  • Object Pascal (Delphi)
  • Javascript
  • Windows PowerShell
  • Perl
  • S-Lang
  • OCaml
  • Haskell
  • (I know there are plenty of others, like modula2 and oberon)

These languages are semicolon separated

I see no reason not to trust these languages because they are not semicolon terminated. :-)

http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(syntax)

Wouter van Nifterick
Perl is semi-colon terminated by any reasonable definition of the term.
Jonathan Leffler
I'm using this definition of the term: The last statement in blocks don't need a semicolon after it. What definition do you use?
Wouter van Nifterick
I wasn't aware that Perl allowed dropped semi-colons before '}' at the end of a block. I've never seen anyone use that liberty. I'd never sanction Perl code isubmitted for review with a missing semi-colon at that position. But since it is legal, I guess that Perl is not simply semi-colon terminated.
Jonathan Leffler
Add Visual Basic.
Cyril Gupta
+1  A: 

I've used a lot of different languages with lots of different characteristics:

  • Some use semicolon as a statement terminator - C, Perl, ...
  • Some use newline as a statement terminator - Python, Ruby, ...
  • Some use a semicolon as a statement separator - Pascal
  • Some use a continuation character on the next line - Fortran 66 (aka Fortran IV)
  • Some use a keyword to introduce each statement - Informix 4GL

The statement separator is really hard because you have to remember when a semi-colon is needed and when it is not required.

The worst case was a language that required semi-colons as statement separators but also used keywords to introduce each statement; that was (still is) truly frustrating to work with on occasion.

Between the various styles, there's not a lot to choose. On average, I like the semi-colon as terminator; I'm perfectly happy with newline as terminator. I can and do switch between the two without problem, and would expect most experienced programmers to do the same. Granted, a novice might find the difference confusing. But after the fourth programming language, it all seems perfectly reasonable if the rest of the language is sane.

Jonathan Leffler
A: 

Having a newline as the statement terminator kinda prevents you from sticking a whole bunch of statements on one line, which is a good thing.

It also makes it harder to create junk statements which span a large number of lines. I don't like the VB:

This is a really long line _
and I'm going to continue on this line

(not sure if the new one does it) stuff though. That's simpy wrong :-)

billybob
I don't think your argument against VB is valid. It's not 'simply wrong', and yes, the new one does it.
Cyril Gupta
A: 

My favorite languages are all semicolon-optional. My second favorite languages allow for semicolon as a terminator or separator at the choice of the programmer (Modula-3, Objective Caml). I can live with semicolon as separator only by using Dave MacQueen's layout:

{ stuff
; more stuff
; still more stuff
}

Semicolon as terminator is OK but it is irritating to deal with languages like C that make an exception for BEGIN/END blocks. (For you youngsters, that's those curly braces which must not be terminated with a semicolon on pain of changing the meaning of your program.) Being unable to terminate curly braces with a semicolon is especially annoying when writing macros because it requires the hellish idiom

#define LOOKS_LIKE_A_STATEMENT(...)  do { ... stuff ... } while(0)
Norman Ramsey