Cancer of the semicolon


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 12 12311 ... LastLast
Results 1 to 15 of 172

Thread: Cancer of the semicolon

  1. #1
    John Proffitt Guest

    Cancer of the semicolon


    "Patrick Troughton" <Patrick@Troughton.com> wrote:
    >
    >For me, there are two primary reasons I don't care for the C-style syntax....
    >
    >- Excessive use of symbols instead of English keywords
    >- Use of brackets to dilineate all forms of scope instead of specific >keywords

    for specific scopes
    >


    For programmers used to languages like COBOL, BASIC or Pascal, C and C++
    do seem almost like something escaped from an algebra text. It's full of
    strange symbols like '+=', '>>' and '!', operators like '++' that can be
    prefixed or postfixed. It takes a while to learn how to parse it, let alone
    understand it.

    Once you get over the hump, though, you can develop an appreciation for the
    terse, economical syntax. Brackets more than suffice in place of 'Begin...End'
    syntax. After all, Python subsists on indentation alone.

    To me, the biggest problem with C-style syntax is those semicolons. Having
    started with BASIC myself, I can't get over the notion that the end of the
    lexical line is best denoted by... a linefeed.

    JBP


  2. #2
    Jonathan Wood Guest

    Re: Cancer of the semicolon

    John,

    > To me, the biggest problem with C-style syntax is those semicolons.

    Having
    > started with BASIC myself, I can't get over the notion that the end of the
    > lexical line is best denoted by... a linefeed.


    From another perspective, VB requires you to type underscores when a
    statement exceeds one line. That's one advantage to semi-colons: you can
    break lines (even quoted strings) whereever you like.

    Jonathan




  3. #3
    Patrick Troughton Guest

    Re: Cancer of the semicolon


    See, that's the funny thing, it's different things for different people. I
    don't mind the semi-colon. In fact, when I'm writing JavaScript, I happily
    add them in even though I know they're not required. I can't see any justification
    for using && instead of And. Sure, it saves 1 keystroke - big deal. I'll
    happily type an extra keystroke if it makes my code readabile. And of course,
    using || instead of Or doesn't save me anything.

    /Pat

    "John Proffitt" <bogon@earthlink.net> wrote:
    >
    >For programmers used to languages like COBOL, BASIC or Pascal, C and C++
    >do seem almost like something escaped from an algebra text. It's full of
    >strange symbols like '+=', '>>' and '!', operators like '++' that can be
    >prefixed or postfixed. It takes a while to learn how to parse it, let alone
    >understand it.
    >
    >Once you get over the hump, though, you can develop an appreciation for

    the
    >terse, economical syntax. Brackets more than suffice in place of 'Begin...End'
    >syntax. After all, Python subsists on indentation alone.
    >
    >To me, the biggest problem with C-style syntax is those semicolons. Having
    >started with BASIC myself, I can't get over the notion that the end of the
    >lexical line is best denoted by... a linefeed.
    >
    >JBP
    >



  4. #4
    William Cleveland Guest

    Re: Cancer of the semicolon

    Patrick Troughton wrote:
    >
    > See, that's the funny thing, it's different things for different people. I
    > don't mind the semi-colon. In fact, when I'm writing JavaScript, I happily
    > add them in even though I know they're not required. I can't see any justification
    > for using && instead of And. Sure, it saves 1 keystroke - big deal. I'll
    > happily type an extra keystroke if it makes my code readabile. And of course,
    > using || instead of Or doesn't save me anything.
    >

    Actually, you don't save any typing, because you need the shift key...

    Bill

  5. #5
    William Cleveland Guest

    Re: Cancer of the semicolon

    John Proffitt wrote:
    >
    > To me, the biggest problem with C-style syntax is those semicolons. Having
    > started with BASIC myself, I can't get over the notion that the end of the
    > lexical line is best denoted by... a linefeed.
    >

    Semicolons are ugly, but the " _" line continuation is just hideous.
    I think the best way to do it would be to allow either a linefeed or
    a semicolon to end a statement (the colon to conbine lines pretty much
    does that in VB). Add to that, if a statement starts with a semicolon,
    it has to end with one. That way, you wouldn't need a continuation for
    every single line.

    a = b + c + d + _
    d + e + f + _
    g + h + i + _
    j + k + l + _
    m

    would become

    ; a = b + c + d +
    d + e + f +
    g + h + i +
    j + k + l +
    m;


    Maybe my example isn't the greatest, but I think it would be better.
    And it wouldn't bother you with remembering semicolons when you don't
    get anything out of it.

    Bill

  6. #6
    John Proffitt Guest

    Re: Cancer of the semicolon


    "Jonathan Wood" <jwood@softcircuits.com> wrote:
    >
    >From another perspective, VB requires you to type underscores when a
    >statement exceeds one line. That's one advantage to semi-colons: you can
    >break lines (even quoted strings) whereever you like.
    >


    I suppose it's a matter of style, but I seldom find a need to wrap a line
    of VB code. Sometimes I do it just because it can be done:

    msg$ = "Error " & CStr(Err) & " in " & Err.Source & vbLf _
    & Err.Description

    One can argue that this is more WYSIWYG. It's a long way from exceeding
    the maximum length of a line in VB. People writing sample code for magazines
    (or folks constrained to code in 640x480) do this a lot to avoid running
    off the page (or screen). But with a reasonable screen resolution most lines
    are amply visible, and I don't normally worry about the length.

    In VB I use an indentation of two spaces for code blocks. This is enough
    for clear demarcation of the block but doesn't cause nested blocks to jog
    right too quickly. I could see tabbing over three spaces in C/C++ because
    it takes two characters to begin a comment, but the default four-space indentation
    in VB's IDE is too much.

    People writing C and C++ often extend a function declaration over several
    lines in order to individually document the parameters. I think this is
    good practice, but VB won't let you insert a comment following a line continuation
    character. You have to comment either above or below; having the capability
    to break the line doesn't help.

    John


  7. #7
    John Proffitt Guest

    Re: Cancer of the semicolon


    William Cleveland <WCleveland@Mediaone.Net> wrote:
    >
    >Actually, you don't save any typing, because you need the shift key...
    >


    As long as you're in the IDE, typing all lower (OR UPPER) case works. The
    editor will fix it all pretty.

    Unless it's an Enum. (Grr!)

    John


  8. #8
    David A. Rothgery Guest

    Re: Cancer of the semicolon

    John Proffitt <bogon@earthlink.net> wrote:
    >
    > William Cleveland <WCleveland@Mediaone.Net> wrote:
    > >
    > >Actually, you don't save any typing, because you need the shift key...
    > >

    >
    > As long as you're in the IDE, typing all lower (OR UPPER) case works. The
    > editor will fix it all pretty.


    I think he was talking about in C/C++ (for && and || -- though 'and' and
    'or' are valid C keywords now, I think).

    --
    Dave Rothgery
    Picking nits since 1976
    drothgery@myrealbox.com
    http://drothgery.editthispage.com

  9. #9
    John Proffitt Guest

    Re: Cancer of the semicolon


    David A. Rothgery <drothgery@myrealbox.com> wrote:
    >
    >I think he was talking about in C/C++ (for && and || -- though 'and' and


    >'or' are valid C keywords now, I think).
    >


    It's debatable. In general you would tend to save keystrokes in the language
    that was not case sensitive. In practice it might be slightly easier to
    hit a single key ('&' or '|') twice than to hunt for a different key on the
    second stroke.

    I know: picky, picky...

    JBP


  10. #10
    Jason Thorn Guest

    Re: Cancer of the semicolon

    Is a line terminator even needed?

    If all functions and subroutines are delimited by commas and enclosed within
    parenthesis, and statements have a fixed number of operands, couldn't a
    compiler tell what the end of the statement should be?

    "William Cleveland" <WCleveland@Mediaone.Net> wrote in message
    news:3A945A19.25802219@Mediaone.Net...
    > John Proffitt wrote:
    > >
    > > To me, the biggest problem with C-style syntax is those semicolons.

    Having
    > > started with BASIC myself, I can't get over the notion that the end of

    the
    > > lexical line is best denoted by... a linefeed.
    > >

    > Semicolons are ugly, but the " _" line continuation is just hideous.
    > I think the best way to do it would be to allow either a linefeed or
    > a semicolon to end a statement (the colon to conbine lines pretty much
    > does that in VB). Add to that, if a statement starts with a semicolon,
    > it has to end with one. That way, you wouldn't need a continuation for
    > every single line.
    >
    > a = b + c + d + _
    > d + e + f + _
    > g + h + i + _
    > j + k + l + _
    > m
    >
    > would become
    >
    > ; a = b + c + d +
    > d + e + f +
    > g + h + i +
    > j + k + l +
    > m;
    >
    >
    > Maybe my example isn't the greatest, but I think it would be better.
    > And it wouldn't bother you with remembering semicolons when you don't
    > get anything out of it.
    >
    > Bill




  11. #11
    Jeff Peil Guest

    Re: Cancer of the semicolon


    "David A. Rothgery" <drothgery@myrealbox.com> wrote in message
    news:MPG.14fe32431436dd18989698@news.devx.com...
    >
    > I think he was talking about in C/C++ (for && and || -- though 'and' and
    > 'or' are valid C keywords now, I think).
    >


    In C, ISO646.H (which was added in C89 amendment 1) does define a set of
    macros ("#define and &&", "#define or ||", etc) However those are not
    keywords in C, they are preprocessor macros defined in a standard header
    (that you'd need to explicitly include.).

    C++ did make these alternative tokens (and thus reserved words), but C++ is
    not C, and even in C++ there is a small distinction between the these
    alternate tokens and keywords.



  12. #12
    Jonathan Allen Guest

    Re: Cancer of the semicolon

    > Once you get over the hump, though, you can develop an appreciation for
    the
    > terse, economical syntax.


    That is not necessarily true. If you count tokens instead of characters, the
    VB style is more compact that the C style.

    Lets look at C# vs VB.Net and the If construct

    C#: 6 Tokens
    if ( x )
    {
    //code
    }

    VB.Net: 5 Tokens
    If X Then
    //code
    End If

    Now lets look at a compound if.

    C#: 16 Tokens, 12 Lines
    if ( x )
    {
    //code
    }
    else if ( y )
    {
    //code 2
    }
    else
    {
    //code 3
    }


    VB.Net: 9 Tokens, 7 Lines

    If x Then
    //code
    ElseIf y Then
    //code 2
    Else
    //code 3
    End if




    --
    Jonathan Allen




  13. #13
    John Proffitt Guest

    Re: Cancer of the semicolon


    "Jonathan Allen" <greywolfcs@bigfoot.com> wrote:
    >
    >If you count tokens instead of characters, the VB style is more compact
    >than the C style.
    >


    Interesting point.

    Don't you think, given programmers of roughly equal skill in both languages,
    and given a task that was doable in both languages, that it would be easier
    to write mistake-free code in VB? It's much easier to hide bugs in C. That's
    why you see those ads, "Can you spot the bug in this C code?"

    John


  14. #14
    Steve Dee Guest

    Re: Cancer of the semicolon

    John,
    the one problem I have with VB is "no semicolons"! Joking....that
    seems to be the one mistake I always make (I use C/VB in tandem). I never
    have problems with switching gears, except I always try and stick semicolons
    in my VB code....dang it!



  15. #15
    Steve Dee Guest

    Re: Cancer of the semicolon

    Question.....what's the big deal about saving on typing? I require VB
    programmers to put parens in If statements....ie.

    if (LarryEllisonIsAPainInThButt()) then
    debug.print "what else is new?"
    end if

    New programmers always complain....what's the deal? Can't anyone type fast
    anymore?

    "William Cleveland" <WCleveland@Mediaone.Net> wrote in message
    news:3A945697.C1C26B0D@Mediaone.Net...
    > Patrick Troughton wrote:
    > >
    > > See, that's the funny thing, it's different things for different people.

    I
    > > don't mind the semi-colon. In fact, when I'm writing JavaScript, I

    happily
    > > add them in even though I know they're not required. I can't see any

    justification
    > > for using && instead of And. Sure, it saves 1 keystroke - big deal. I'll
    > > happily type an extra keystroke if it makes my code readabile. And of

    course,
    > > using || instead of Or doesn't save me anything.
    > >

    > Actually, you don't save any typing, because you need the shift key...
    >
    > Bill




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center