Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Possible Duplicate:
Why are statements in many programming languages terminated by semicolons?

I just found out that R Programming Language, which is somewhat belong to the C family (I'm not sure about this but it uses {} instead of begin end), uses a new line as a delimiter for a new line of code instead of the semi-colon ;.

Why is some programming language designed to use a new line instead of a symbol like semi-colon which I think will make the code more readable?


Phyton

total = item_one + \
        item_two + \
        item_three

C

total = item_one +
        item_two +
        item_three;
share|improve this question

marked as duplicate by BЈовић, littleadv, Yannis Rizos Apr 12 '12 at 7:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
This isn't a duplicate at all.The other question is about symbology in languages that use a line ending delimiter. This one is about why you would delimit line-endings at all. I was going to ask a question along the lines of "What is the benefit of NOT having a line-ending delimiter in a language," but this question pretty much covers that. The other one doesn't. –  naught101 Jul 31 '12 at 4:57
1  
@naught101 This really isn't what is being asked here, but I actually like the question you proposed. Perhaps you should post your own question about this? –  maple_shaft Jul 31 '12 at 11:33
    
@maple_shaft: it may not be being asked here directly, but it is kind of implied, and the answers pretty much cover it... –  naught101 Jul 31 '12 at 11:52
add comment

3 Answers

The semicolon in C and languages that adopt its syntax is used to terminate statements. Put simply it's the symbol the compiler looks for to know where a statement ends, and by association where the next one begins.

It's mostly a quirk of the language, a convention. Whether it makes code more readable or not depends a lot on your personal preferences, I don't think there is a valid metric that can be applied objectively. Wikipedia has an extensive list of languages organized per their statement terminator, and some of the popular newline terminated / separated languages are:

  • Haskell,
  • BASIC,
  • Eiffel,
  • Fortran,
  • Visual Basic

and others.

You can find a very interesting discussion on whether semicolons or newlines should be used as statement separator/terminator here: http://www.cs.nmsu.edu/~jeffery/godiva/semi.html. Sum of the discussion is that Larry Wall really likes his semicolons ;)

share|improve this answer
    
Heh. "Forgetting a trailing semicolon is a common goof in a variety of languages..." That's probably the best argument against termination characters. Having optional semi-colons based on preceeding syntax seems like a stupid idea - there's plenty of cases where it's not clear at first glance what's an expression and what's not.. –  naught101 Jul 31 '12 at 5:31
add comment

Any answer to this is going to be subjective. There was a big discussion about why the semicolon was used to terminate statements in this question. The bottom line is that any scheme can be made parseable and it is up to the language designer to choose their own statement termination scheme. This choice will be influenced by the emotional baggage that they attach to each scheme. Some people have a pathological loathing for semicolons or other explicit statement termination characters, while others see utility in having an explicit, visible termination character.

share|improve this answer
add comment

The idea behind semantic whitespace in Python is that the program structure as seen by the interpreter should match the structure as seen by humans as closely as possible. Consider the following C program:

if ( foo )
    bar;
    baz;

At first glance, you'll assume that bar and baz are both conditional; they aren't, however, due to misleading indentation. The C way of thinking is "make your whitespace match semantics". The Python way is more along the lines of thinking DRY: "whitespace already expresses program structure, just parse it".

share|improve this answer
    
Good answer, hadn't thought of it that way before. I guess the requirement of a \ for line continuation as opposed to a ; for line termination is also a lot less typing, in the long run. It must be a PHP-related hang-up of mine that line continuation just looks damn ugly :) –  naught101 Jul 31 '12 at 5:02
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.