C Syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kieran Simkin

    #16
    Re: [OT] Chinese Syntax

    "C# Learner" <csharp@learner .here> wrote in message
    news:euOxH13QEH A.3744@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Alex Moskalyuk wrote:
    >[color=green]
    > > Have you ever looked into Perl or Lisp code?
    > >
    > > C suddenly starts making perfect sense.
    > >
    > > What's uneasy to you? Curly braces, parentheses, keywords, or something
    > > else?[/color]
    >
    > One of the biggest flaws in C syntax, in my opinion, is the required
    > parentheses for test conditions.[/color]

    I think you confuse a flaw with part of the language specification.
    [color=blue]
    >
    > Here's a very simple example:
    >
    > void Foo
    > {
    > if (FooBar(Parse(P rocess(GetInput ())))
    > DoSomething();
    > }
    >
    > Imagine if, instead, we could write the following:
    >
    > void Foo
    > {
    > if FooBar(Parse(Pr ocess(GetInput( ))):
    > DoSomething();
    > }
    >[/color]

    I'm imagining, and I'm reminded of BASIC.
    [color=blue]
    > Python uses such a construct for test conditions.
    >
    > Another nicety about Python is the fact that whitespace is used for
    > defining code blocks. This makes code much clearer than the equivalent
    > C code, which requires block being/end markers.
    >
    > Here's a very simple Python code sample:
    > http://www.kernelthread.com/hanoi/html/py.html .
    >
    > Try staring at it for one minute.
    >[/color]

    Have just done so, this code (admittedly having never even looked at Python
    before) seems completely unreadable to me. Maybe I'm just used to C syntax.
    [color=blue]
    > After having done so, take a look at this:
    > http://www.kernelthread.com/hanoi/html/c.html .
    >
    > Even if one's accustomed to C syntax, the former is still clearer and
    > easier-to-read, don't you think?[/color]

    No, not really. Python may be easier for you because that may be what you're
    used to looking at, but C and PHP are what I do (PHP's syntax is more
    similar to C's than Python's) and their syntax makes perfect sense to me. It
    seems to me there may not be a "better" way; just different ways - although
    it does seem to me that Python code would be prone to breaking when cnped
    between things which do not preserve tab formatting for example (such as
    some newsreaders).

    One of the things I like about C is that whitespace most often doesn't
    matter and I can control exactly how I want my program to look and read
    rather than have it laid out for me by the language specification.
    [color=blue]
    >
    > Every time I see code that conforms to C's basic syntax, I cringe; yet I
    > write such code every day.
    >
    > Why C? Why?![/color]

    This is the kind of question which could easily attract a lot of annoyance.


    Obviously this entire post is off-topic. Python is not C, C will never be
    Python and you've cross-posted to C# which is not C either.



    Comment

    • Jack Klein

      #17
      Re: C Syntax

      On Wed, 26 May 2004 19:56:05 -0400, Lew Pitcher
      <lpitcher@sympa tico.ca> wrote in comp.lang.c:
      [color=blue]
      > -----BEGIN PGP SIGNED MESSAGE-----
      > Hash: SHA1
      >
      > Eric Sosman wrote:
      > | C# Learner wrote:
      > |
      > |> Why is C syntax so uneasy on the eye?
      > |>
      > |> In its day, was it _really_ designed by snobby programmers to scare
      > |> away potential "n00bs"? If so, and after 50+ years of programming
      > |> research, why are programming languages still being designed with C's
      > |> syntax?
      > |>
      > |> These questions drive me insane. Every waking minute...
      > |
      > |
      > | If you want COBOL, you know where to find it.
      > |
      >
      > I resemble that remark! :-)
      >
      > FWIW, if you want a computer language that's really "uneasy on the eye", try
      > APL or RPG2. Even Lisp isn't very easy to read.[/color]

      You haven't liven until you've seen badly written PL/M (note the 'M').

      Their equivalent of C's switch...case still gives me nightmares after
      all these years.
      [color=blue]
      > OTOH, I've had to read through pages of Java recently (analysis and design of
      > a new web component for my corporate masters, requiring review of our current
      > j2ee web apps), and if Java is the new "readabilit y", then give me C any day.
      > Worse spaghetti code than you could find in any assembly program. I have no
      > doubt that C# and C++ are just as bad.[/color]

      --
      Jack Klein
      Home: http://JK-Technology.Com
      FAQs for
      comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
      comp.lang.c++ http://www.parashift.com/c++-faq-lite/
      alt.comp.lang.l earn.c-c++

      Comment

      • C# Learner

        #18
        Re: [OT] Chinese Syntax

        Kieran Simkin wrote:
        [color=blue]
        > "C# Learner" <csharp@learner .here> wrote in message
        > news:euOxH13QEH A.3744@TK2MSFTN GP10.phx.gbl...[/color]

        [...]
        [color=blue][color=green]
        >>After having done so, take a look at this:
        >>http://www.kernelthread.com/hanoi/html/c.html .
        >>
        >>Even if one's accustomed to C syntax, the former is still clearer and
        >>easier-to-read, don't you think?[/color]
        >
        > No, not really. Python may be easier for you because that may be what you're
        > used to looking at,[/color]

        Aha, but I only saw Python code for the /first/ time yesterday. :-)
        [color=blue]
        > but C and PHP are what I do (PHP's syntax is more
        > similar to C's than Python's)[/color]

        Cool.
        [color=blue]
        > [...][color=green]
        >>Every time I see code that conforms to C's basic syntax, I cringe; yet I
        >>write such code every day.
        >>
        >>Why C? Why?![/color]
        >
        > This is the kind of question which could easily attract a lot of annoyance.[/color]

        Okay, I accept that. I don't mean to annoy -- it's just my style of
        writing. If I've annoyed then I apologize to all those affected.

        Also, I guess I'm just trying to make a point and get heard here; and,
        at the same time, I want to hear what those who are more experienced
        than me have to say on the matter -- especially C gurus!

        For the record, I don't /hate/ this C syntax of which I talk. I just
        have a feeling of disbelief, perhaps, that some badly-implemented (in my
        opinion) syntactial elements of the C language have passed through to
        modern programming languages.
        [color=blue]
        > Obviously this entire post is off-topic. Python is not C, C will never be
        > Python and you've cross-posted to C# which is not C either.[/color]

        Hmm... I have to disagree. I feel that this discussion is about C's
        basic syntax and its ubiquity in popular modern-day languages.

        If such a discussion is off-topic for comp.lang.c, then I honestly don't
        know quite where it would be /on/-topic. In fact, I even considered
        renaming the subject of this post to 'Re: C Syntax', but didn't want to
        enrage people by doing so.

        In any case, this was also posted to
        microsoft.publi c.dotnet.langua ges.csharp since I wanted to hear some
        opinions from those people too, and that is also the group which I read
        more.

        Comment

        • Stephen Sprunk

          #19
          Re: Chinese Syntax

          "C# Learner" <csharp@learner .here> wrote in message
          news:euOxH13QEH A.3744@TK2MSFTN GP10.phx.gbl...[color=blue]
          > One of the biggest flaws in C syntax, in my opinion, is the required
          > parentheses for test conditions.[/color]

          Without the parens you would need a "then" keyword of some kind. It seems
          like an even trade.
          [color=blue]
          > Another nicety about Python is the fact that whitespace is used for
          > defining code blocks. This makes code much clearer than the equivalent
          > C code, which requires block being/end markers.[/color]

          OTOH, C not using whitespace to mean anything gives programmers lots of
          flexibility in how they format their source code to improve readability.

          Block begin/end markers are very useful, and having such things explicit
          arguably makes things easier for both the compiler and subsequent coders.
          [color=blue]
          > Here's a very simple Python code sample:
          > http://www.kernelthread.com/hanoi/html/py.html .
          >
          > Try staring at it for one minute.
          >
          > After having done so, take a look at this:
          > http://www.kernelthread.com/hanoi/html/c.html .
          >
          > Even if one's accustomed to C syntax, the former is still clearer and
          > easier-to-read, don't you think?[/color]

          That depends on the reader; the C version is far clearer to me. You also
          put error-checking into the C version that's not in the Python one, which is
          unfair when considering code length.

          S

          --
          Stephen Sprunk "Stupid people surround themselves with smart
          CCIE #3723 people. Smart people surround themselves with
          K5SSS smart people who disagree with them." --Aaron Sorkin

          Comment

          • I. Appel

            #20
            Re: [OT] Re: C Syntax

            "C# Learner" <csharp@learner .here> wrote in message
            news:eSPUPt4QEH A.1388@TK2MSFTN GP09.phx.gbl...
            [color=blue][color=green]
            > > These are trivialities. Learn five or six computer languages (or three
            > > or four
            > > that are entirely unrelated to each other), /then/ formulate your[/color][/color]
            opinion.[color=blue]
            >
            > Well, I have learned BASIC, C-like languages (C and C++), Delphi
            > (formerly named 'Object Pascal') and Smalltalk.
            >
            > So, basically, I've learned a couple of procedural languages, and a
            > couple of OO ones.[/color]

            And which one do seems you the best?
            Which one seems to have the best syntax?

            All your languages are Algol-derivative, so they share equivalent
            syntactic constructs and all them are similar.

            Try to learn something truly alternative. Try FORTRAN 77, the language
            without any flame wars about indentation. Try LISP, the language with
            syntax based on two symbols. Then come back.

            When personally I met C, I already knew BASIC and Pascal and I was amused
            by the expressiveness and brevity of C's syntax. I still think that
            for (i=0;i<10;i++) {...}
            is much better than
            for i:=0 to 9 do begin ... end;
            [color=blue][color=green]
            > > Some languages are exceedingly suscinct (i.e. APL or RPG), and
            > > some are very verbose (i.e. COBOL, SNOBOL, PL/I, Assembly (any[/color][/color]
            processor)).[color=blue][color=green]
            > > Some languages are procedural, some are OO, some are list processors,
            > > some are
            > > macro languages. Learn a few, see what they do and where they are used.
            > >
            > > Only then can you conduct a reasonable conversation on the topic.[/color]
            >
            > I don't understand why I'd need to learn a few more languages to
            > understand that C's basic syntax could be nicer.[/color]

            Suggest some improvements and I'll say you, why you're wrong ;-)





            Comment

            • C# Learner

              #21
              Re: [OT] Re: C Syntax

              [I'll do the courtesy of a reply at the risk of getting flamed by the
              comp.lang.c police.]

              I. Appel wrote:
              [color=blue]
              > "C# Learner" <csharp@learner .here> wrote in message
              > news:eSPUPt4QEH A.1388@TK2MSFTN GP09.phx.gbl...
              >[color=green][color=darkred]
              >>>These are trivialities. Learn five or six computer languages (or three
              >>>or four
              >>>that are entirely unrelated to each other), /then/ formulate your[/color][/color]
              >
              > opinion.
              >[color=green]
              >>Well, I have learned BASIC, C-like languages (C and C++), Delphi
              >>(formerly named 'Object Pascal') and Smalltalk.
              >>
              >>So, basically, I've learned a couple of procedural languages, and a
              >>couple of OO ones.[/color]
              >
              > And which one do seems you the best?
              > Which one seems to have the best syntax?[/color]

              I'd say Delphi has the clearest syntax.

              [...]
              [color=blue][color=green]
              >>I don't understand why I'd need to learn a few more languages to
              >>understand that C's basic syntax could be nicer.[/color]
              >
              > Suggest some improvements and I'll say you, why you're wrong ;-)[/color]

              Simply:

              1) Remove the need to specify parentheses for test conditions --
              substitute a test condition terminator, such as Python's ':'.

              2) Remove begin/end code block markers and require indentation instead.

              Comment

              • Irrwahn Grausewitz

                #22
                Re: [OT] Re: C Syntax

                C# Learner <csharp@learner .here> wrote:[color=blue]
                >[I'll do the courtesy of a reply at the risk of getting flamed by the
                >comp.lang.c police.][/color]

                [No police around, only conscious people.]
                [color=blue]
                >I. Appel wrote:
                >[color=green]
                >> "C# Learner" <csharp@learner .here> wrote:[/color][/color]
                <snip>
                [color=blue][color=green][color=darkred]
                >>>Well, I have learned BASIC, C-like languages (C and C++), Delphi
                >>>(formerly named 'Object Pascal') and Smalltalk.
                >>>
                >>>So, basically, I've learned a couple of procedural languages, and a
                >>>couple of OO ones.[/color][/color][/color]
                <snip>

                Note:
                "Procedural " and "OO" are not mutually exclusive language concepts.
                Smalltalk is a functional language.
                [color=blue][color=green][color=darkred]
                >>>I don't understand why I'd need to learn a few more languages to
                >>>understand that C's basic syntax could be nicer.[/color]
                >>
                >> Suggest some improvements and I'll say you, why you're wrong ;-)[/color]
                >
                >Simply:
                >
                >1) Remove the need to specify parentheses for test conditions --
                > substitute a test condition terminator, such as Python's ':'.
                >
                >2) Remove begin/end code block markers and require indentation instead.[/color]

                Who or what is keeping you from designing a language incorporating the
                worst of BASIC/Pascal/Python/FORTRAN/etc. worlds? Not that it will
                ever have a fighting chance to be used by anyone for anything but as
                an example of a language with a syntax "uneasy to the eye".

                "Doctor, it hurts when I look at C."
                "Well, then don't."

                Regards
                --
                Irrwahn Grausewitz (irrwahn33@free net.de)
                welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
                clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
                clc OT guide : http://benpfaff.org/writings/clc/off-topic.html

                Comment

                • Richard Bos

                  #23
                  Re: C Syntax

                  C# Learner <csharp@learner .here> wrote:
                  [color=blue]
                  > Why is C syntax so uneasy on the eye?[/color]

                  Beware the troll! This is cross-posted inappropriately .

                  Richard

                  Comment

                  • Paul Hsieh

                    #24
                    Re: Chinese Syntax

                    "Justin Rogers" <Justin@games4d otnet.com> wrote:[color=blue]
                    > Note that they point out you can leave out parens only when it won't lead to
                    > ambiguity. C doesn't make that mistake. They make sure there is no
                    > ambiguity, and if you leave out a parens it doesn't make the statement
                    > ambiguous, it makes it a different or erroneous statement altogether.[/color]

                    C has plenty of ambiguity:

                    - Braces are optional if there is only one statement for if() or for() or
                    while(). (But not for do ... while(), switch, or structure/union
                    declarations.)

                    - If a statement has multiple side effects, the order in which those side
                    effects take place can be unknown.

                    - The right shift operator may or may not sign extend signed integers. Its
                    implementation defined.

                    - The size of an integer is platforms specific.

                    - The number of bits in a bytes is platform specific.

                    - Try this one on for size:

                    char a = -1, b = -2;
                    unsigned short x = (1 > 0) ? a : b;

                    printf ("x = %d\n", x);

                    What do you think is printed out? Explain it.

                    --
                    Paul Hsieh
                    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.


                    Comment

                    • Jeremy Yallop

                      #25
                      Re: Chinese Syntax

                      Paul Hsieh wrote:[color=blue]
                      > "Justin Rogers" <Justin@games4d otnet.com> wrote:[color=green]
                      >> Note that they point out you can leave out parens only when it won't lead to
                      >> ambiguity. C doesn't make that mistake. They make sure there is no
                      >> ambiguity, and if you leave out a parens it doesn't make the statement
                      >> ambiguous, it makes it a different or erroneous statement altogether.[/color]
                      >
                      > C has plenty of ambiguity:
                      >
                      > - Braces are optional if there is only one statement for if() or for() or
                      > while(). (But not for do ... while(), switch, or structure/union
                      > declarations.)[/color]

                      The braces are also optional on switch and do-while statements:

                      do something(); while (not_finished() );

                      switch (expression)
                      statement;

                      Struct or union declarations are not relevant: their components are
                      declarations, not statements.

                      None of your other examples were syntactically ambiguous.

                      Jeremy.

                      Comment

                      • Dan Pop

                        #26
                        Re: C Syntax

                        In <uLRM6T2QEHA.37 32@TK2MSFTNGP11 .phx.gbl> C# Learner <csharp@learner .here> writes:
                        [color=blue]
                        >Why is C syntax so uneasy on the eye?[/color]

                        Uneasiness is in the eye of the beholder...

                        Dan
                        --
                        Dan Pop
                        DESY Zeuthen, RZ group
                        Email: Dan.Pop@ifh.de

                        Comment

                        • Grumble

                          #27
                          Re: [OT] Re: C Syntax

                          C# Learner wrote:
                          [color=blue]
                          > Simply:
                          >
                          > 1) Remove the need to specify parentheses for test conditions --
                          > substitute a test condition terminator, such as Python's ':'.[/color]

                          #define if if (
                          #define then )

                          int main(int argc, char **argv)
                          {
                          if argc-1 == 0 then return 666;
                          return 0;
                          }

                          Comment

                          • Michael Wojcik

                            #28
                            Re: C Syntax


                            In article <V7atc.31023$sr 3.886959@news20 .bellglobal.com >, Lew Pitcher <lpitcher@sympa tico.ca> writes:[color=blue]
                            >
                            > FWIW, if you want a computer language that's really "uneasy on the eye", try
                            > APL or RPG2. Even Lisp isn't very easy to read.[/color]

                            APL?!! APL is beauty itself, manifesting as a swell set of new
                            keyboard caps. C'mon - just look at that cute little rho, or the
                            noble edifice of the dotted-quad.

                            Of course, few languages can produce source as readable as ETA's.[1]
                            [color=blue]
                            > OTOH, I've had to read through pages of Java recently (analysis and design of
                            > a new web component for my corporate masters, requiring review of our current
                            > j2ee web apps), and if Java is the new "readabilit y", then give me C any day.
                            > Worse spaghetti code than you could find in any assembly program. I have no
                            > doubt that C# and C++ are just as bad.[/color]

                            It's possible to write highly readable code in Java, of course, just
                            as it is in C, but many Java programmers for some reason seem to suffer
                            from a variety of common style deficiencies. I've seen a lot of Java
                            source which was apparently written in an editor with a 200-character
                            line length, for example.

                            As untold commentators have pointed out untold times, a talented
                            programmer can produce a mess in any language. There *are* languages
                            which make it more or less convenient to produce readable source, but
                            for all but the worst offenders it's possible. (The only real
                            counterexample I can think of would be an evil esoteric language,
                            even then perhaps only if it didn't permit comments. I don't think
                            Unlambda[2] has any provision for comments, for example. If it had
                            them, even an Unlambda program might be rendered readable, for
                            suitably small values of "unreadable ".)

                            1. http://www.miketaylor.org.uk/tech/eta/doc/
                            2. http://www.eleves.ens.fr:8080/home/m...rams/unlambda/

                            --
                            Michael Wojcik michael.wojcik@ microfocus.com

                            Vinegar keeps more flies away than honey does.

                            Comment

                            • I. Appel

                              #29
                              Re: [OT] Re: C Syntax

                              "C# Learner" <csharp@learner .here> wrote in message
                              news:eF2uqF6QEH A.1340@TK2MSFTN GP12.phx.gbl...
                              [color=blue][color=green][color=darkred]
                              > >>>These are trivialities. Learn five or six computer languages (or three
                              > >>>or four
                              > >>>that are entirely unrelated to each other), /then/ formulate your[/color]
                              > >
                              > > opinion.
                              > >[color=darkred]
                              > >>Well, I have learned BASIC, C-like languages (C and C++), Delphi
                              > >>(formerly named 'Object Pascal') and Smalltalk.
                              > >>
                              > >>So, basically, I've learned a couple of procedural languages, and a
                              > >>couple of OO ones.[/color]
                              > >
                              > > And which one do seems you the best?
                              > > Which one seems to have the best syntax?[/color]
                              >
                              > I'd say Delphi has the clearest syntax.[/color]

                              Delphi is boring. IMO syntax of C is much more funny.
                              [color=blue]
                              > [...]
                              >[color=green][color=darkred]
                              > >>I don't understand why I'd need to learn a few more languages to
                              > >>understand that C's basic syntax could be nicer.[/color]
                              > >
                              > > Suggest some improvements and I'll say you, why you're wrong ;-)[/color]
                              >
                              > Simply:[/color]

                              Well, rephrasing Paul Graham, I should say "Don't wait until C will become
                              as
                              clear as Python, use Python instead".
                              [color=blue]
                              > 1) Remove the need to specify parentheses for test conditions --
                              > substitute a test condition terminator, such as Python's ':'.[/color]

                              Actually in C it is permitted to build much more complicated conditions.
                              It's generally bad programming style, but that feature requires parenteses.
                              [color=blue]
                              > 2) Remove begin/end code block markers and require indentation instead.[/color]

                              Block markers vs. indentation is IMO eternal flame war.


                              Comment

                              • Francois Beaussier

                                #30
                                Re: Chinese Syntax

                                "Paul Hsieh" wrote :
                                [color=blue]
                                > - Try this one on for size:
                                >
                                > char a = -1, b = -2;
                                > unsigned short x = (1 > 0) ? a : b;
                                >
                                > printf ("x = %d\n", x);
                                >
                                > What do you think is printed out? Explain it.[/color]

                                the same as in c# :

                                unchecked
                                {
                                char c = (char) -1;
                                ushort x = c;
                                Console.WriteLi ne(">> " + x);
                                }
                                [color=blue][color=green]
                                >> 65535[/color][/color]

                                wich is the way -1 is represented in 16 bits unsigned data ;)

                                what is your point ? what else where we supposed to expect ? 255 ?

                                --
                                Francois Beaussier
                                Francois@3ie.or g.remove


                                Comment

                                Working...