Is C++ the best language?

For a long time I have debated with my friends/colleagues my reasons for thinking that C++ is the best all round programming language. I finally got round to posting this on my blog ([link=http://outofthetriangle.wordpress.com/2007/10/18/is-c-the-only-real-language/]Is C++ The Only Real Language?[/link]). I
«13

Comments

  • Comments about the blog:

    - Why isn't C evaluated? It gets 10.5 points on that scale, losing 0.5 points for lacking inheritance, though it supports every other aspect of OO, although not in a syntax-appealing way.

    - Nobody in the computer industry but the americans give a damn about ANSI any longer. ISO is what matters.

    ---

    My own opinion about programming languages is, in order to qualify as one of the best, the language shall:

    - Have somewhat logical syntax. Excludes VB. C/C++ [italic]barely[/italic] qualifies :-).

    - Be platform-independant. This is as fundamental as it can get, it is the least you can require of a general-purpose language.

    - Have no need of an interpreter or runtime junk. VB, Java and .NET are typical examples of why. And why make slow and memory consuming programs requiring a load of bulky files, when you can make fast ones without the need of additional files instead?

    - Lack garbage collection. Not sure about anyone else, but garbage collection just makes me laugh. What comes to my mind is "I have such a hard time finding my memory leak bugs, and instead of learning how to program properly, I would rather have my program actively finding them for me in runtime." (I'm not counting smart pointers as garbage collection - those are another story)

    - Support multi-threading on a language level, or by including POSIX threads as part of the standard.
  • : - Have somewhat logical syntax. Excludes VB. C/C++
    : [italic]barely[/italic] qualifies :-).

    Makes me curious what language you think has a logical syntax?

    I agree that *most* of the time, C/C++ has a more logical syntax than VB. VB mostly lacks blocks ( { ...} ), in which case you get constructions like "Something ... End Something" which is a bit messy imo.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • : Comments about the blog:
    :
    : - Why isn't C evaluated? It gets 10.5 points on that scale, losing
    : 0.5 points for lacking inheritance, though it supports every other
    : aspect of OO, although not in a syntax-appealing way.
    :
    : - Nobody in the computer industry but the americans give a damn
    : about ANSI any longer. ISO is what matters.
    :
    : ---
    :
    : My own opinion about programming languages is, in order to qualify
    : as one of the best, the language shall:
    :
    : - Have somewhat logical syntax. Excludes VB. C/C++
    : [italic]barely[/italic] qualifies :-).
    :
    : - Be platform-independant. This is as fundamental as it can get, it
    : is the least you can require of a general-purpose language.
    :
    : - Have no need of an interpreter or runtime junk. VB, Java and .NET
    : are typical examples of why. And why make slow and memory consuming
    : programs requiring a load of bulky files, when you can make fast
    : ones without the need of additional files instead?
    :
    : - Lack garbage collection. Not sure about anyone else, but garbage
    : collection just makes me laugh. What comes to my mind is "I have
    : such a hard time finding my memory leak bugs, and instead of
    : learning how to program properly, I would rather have my program
    : actively finding them for me in runtime." (I'm not counting smart
    : pointers as garbage collection - those are another story)
    :
    : - Support multi-threading on a language level, or by including POSIX
    : threads as part of the standard.

    - I agree that interpreters and VM's are often the cause of many head-aches. For Java there are several ahead-of-time (AOT) compilers, which will remove that problem.
    - Garbage collection is great to reduce memory-leaks, but it doesn't completely remove memory leaks due to bad programming. It is possible to make self referencing objects, which certainly will create memory leaks if left unchecked by the programmer. They also help to keep the code more readable, by removing the need to include deallocation code.
  • : - Garbage collection is great to reduce memory-leaks, but it doesn't
    : completely remove memory leaks due to bad programming. It is
    : possible to make self referencing objects, which certainly will
    : create memory leaks if left unchecked by the programmer. They also
    : help to keep the code more readable, by removing the need to include
    : deallocation code.


    That can all be solved with smart pointers (auto_ptr and similar).
  • : : - Have somewhat logical syntax. Excludes VB. C/C++
    : : [italic]barely[/italic] qualifies :-).
    :
    : Makes me curious what language you think has a logical syntax?


    VB... arrays start at index 0 or 1, take a chance. File handling uses a completely different syntax than the rest of the language. Plenty of loop syntax lacking purpose. Variables don't need to be declared, and their type might be random or huge "variants". You can pass variables by reference, but not use a reference of a variable in the code. Functions and sub-routines are different things. Error handling is handled by goto. And so on...

    C/C++: Type sizes of integers is a mess. if/for/while statements dont need {} if there is only one instruction following. Switch-case statements and their completely illogical syntax. Argument lists, printf/scanf. The funky ?: operator. Bitwise & has lower priority than ==. Assignments may be done inside statements. The ',' operator. The macro syntax!! Strings declared with "" adds invisible null termination. The magical NULL in C (which might be the most fuzzy thing ever made). C++ inheritance in general with virtual/private/protected/public all over the place, meaning completely differnt things depending on the situation. Multiple inheritance. new and new[] are different operators. friends. The pure evil syntax of STL. And so on...

    Thinking of it, I definitely don't think C/C++ qualifies as logical. :-)

    Java and C# would be good examples of logical syntax. (Except Java's file handling which was clearly designed by a madman.)
  • : : : - Have somewhat logical syntax. Excludes VB. C/C++
    : : : [italic]barely[/italic] qualifies :-).
    : :
    : : Makes me curious what language you think has a logical syntax?
    :
    :
    : VB... arrays start at index 0 or 1, take a chance. File handling
    : uses a completely different syntax than the rest of the language.
    : Plenty of loop syntax lacking purpose. Variables don't need to be
    : declared, and their type might be random or huge "variants". You can
    : pass variables by reference, but not use a reference of a variable
    : in the code. Functions and sub-routines are different things. Error
    : handling is handled by goto. And so on...
    :
    : C/C++: Type sizes of integers is a mess. if/for/while statements
    : dont need {} if there is only one instruction following. Switch-case
    : statements and their completely illogical syntax. Argument lists,
    : printf/scanf. The funky ?: operator. Bitwise & has lower priority
    : than ==. Assignments may be done inside statements. The ','
    : operator. The macro syntax!! Strings declared with "" adds invisible
    : null termination. The magical NULL in C (which might be the most
    : fuzzy thing ever made). C++ inheritance in general with
    : virtual/private/protected/public all over the place, meaning
    : completely differnt things depending on the situation. Multiple
    : inheritance. new and new[] are different operators. friends. The
    : pure evil syntax of STL. And so on...
    :
    : Thinking of it, I definitely don't think C/C++ qualifies as logical.
    : :-)
    :
    : Java and C# would be good examples of logical syntax. (Except Java's
    : file handling which was clearly designed by a madman.)

    Java's file handling looks a bit illogical at first, but it is ver logical and flexible. As a programmer one can decide for himself which reading capabilities the program needs. By separating the actual source of the data from the way it is perceived by the program, Java has a single way of reading from files, networks, memory, pipes, etc.
    I found this easier than using one way to read from a file, and another to read from the network.
    Other filehandling commands are just as logical: Create a representation using the File object. Then perform an action on that representation. This is not that illogical way of doing things for an OO language.
  • In my opinion the problem is that you have way too many fuzzy "streams" or whatever they call them, that you need to connect together in the right order. When I wrote Java, it was always a pain to get it working, compared to the rest of the language which is very intuitive.

    Instead, I think they should just have passed a big bunch of arguments to one standard "i/o object", and let the user configure it for file handling, port i/o, pipes or whatever he wants it to use. Kind of like CreateFile() in Windows, but not restricted only to files and ports.
  • : For a long time I have debated with my friends/colleagues my reasons
    : for thinking that C++ is the best all round programming language. I
    : finally got round to posting this on my blog
    : ([link=http://outofthetriangle.wordpress.com/2007/10/18/is-c-the-only
    : -real-language/]Is C++ The Only Real Language?[/link]). I
  • : 3- Templates in C++ are error prone and soo complicated comparing to
    : Java Object type

    The Java Object type is not something to brag about. Both C++ and C# have better ways.

    C++ templates accepts primitive data types, Java Objects don't, you need to use real ugly wrapper classes to even be able to pass common integers, since Java isn't a pure object-oriented language, unlike C# where everything's objects.

    As for C++ templates, they are complicated, but way more powerful once you have them working. Take this example:

    [code] ifstream fin("dummy.txt");
    if(!fin.is_open())
    {
    /* error handling */
    }
    istream_iterator fin_it (fin), end;
    ostream_iterator cout_it(cout, "
    ");
    copy(fin_it, end, cout_it);
    fin.close();[/code]

    This opens a file containing custom "SomeType" objects, reads them and prints them all to the screen in a type-specific manner. In 6 lines of code. Need another i/o source? Change one argument to the constructors. Need another type? Change the template type. Add another copy() line and you can get the data inside any container type of your choise, sorted in any way you like.

    Hardly complicated, though the complexity is hidden among operator overloading, function objects etc, and those are things that Java lacks, for good and bad.


    : 4- pointer in C++ are not safe as java's pointers

    Java references are very much unsafe, since you don't explictly write that you are passing the argument by reference. They expect that everyone simply knows that, and thinks of it when they are writing a function. So if you step in straight from C/C++, Pascal or whatever and start writing Java, you will almost certainly trash a fair amount of function parameters since they look as if they were passed by value. Or forgetting to compare the passed parameter with "this" when writing an "equals" function.


    If you want to preach Java over C++, you should mention inheritage, inferfaces, intuitive OO design etc, because that is where Java gets the real advantage, being way more clean and logical. And of course the platform independance, as well as and the Java applets that can run from any modern web browser.
  • : : 3- Templates in C++ are error prone and soo complicated comparing to
    : : Java Object type
    :
    : The Java Object type is not something to brag about. Both C++ and C#
    : have better ways.
    :
    : C++ templates accepts primitive data types, Java Objects don't, you
    : need to use real ugly wrapper classes to even be able to pass common
    : integers, since Java isn't a pure object-oriented language, unlike
    : C# where everything's objects.
    :
    : As for C++ templates, they are complicated, but way more powerful
    : once you have them working. Take this example:
    :
    : [code]: ifstream fin("dummy.txt");
    : if(!fin.is_open())
    : {
    : /* error handling */
    : }
    : istream_iterator fin_it (fin), end;
    : ostream_iterator cout_it(cout, "
    ");
    : copy(fin_it, end, cout_it);
    : fin.close();[/code]:
    :
    : This opens a file containing custom "SomeType" objects, reads them
    : and prints them all to the screen in a type-specific manner. In 6
    : lines of code. Need another i/o source? Change one argument to the
    : constructors. Need another type? Change the template type. Add
    : another copy() line and you can get the data inside any container
    : type of your choise, sorted in any way you like.
    :
    : Hardly complicated, though the complexity is hidden among operator
    : overloading, function objects etc, and those are things that Java
    : lacks, for good and bad.
    :
    :
    : : 4- pointer in C++ are not safe as java's pointers
    :
    : Java references are very much unsafe, since you don't explictly
    : write that you are passing the argument by reference. They expect
    : that everyone simply knows that, and thinks of it when they are
    : writing a function. So if you step in straight from C/C++, Pascal or
    : whatever and start writing Java, you will almost certainly trash a
    : fair amount of function parameters since they look as if they were
    : passed by value. Or forgetting to compare the passed parameter with
    : "this" when writing an "equals" function.
    :
    :
    : If you want to preach Java over C++, you should mention inheritage,
    : inferfaces, intuitive OO design etc, because that is where Java gets
    : the real advantage, being way more clean and logical. And of course
    : the platform independance, as well as and the Java applets that can
    : run from any modern web browser.
    :
    Here's the Java object reader and printer, for those who are interested:
    [code]
    ObjectInputStream ois = ObjectInputStream(new FileInputStream("dummy.txt"));
    Object o = ois.readObject();
    while (o != null) {
    System.out.println(o.toString());
    }
    o.close();
    [/code]
    This works for all objects, which implement the Serializable interface.
  • : [code]:
    : ObjectInputStream ois = ObjectInputStream(new FileInputStream("dummy.txt"));
    : Object o = ois.readObject();
    : while (o != null) {
    : System.out.println(o.toString());
    : }
    : o.close();
    : [/code]:
    : This works for all objects, which implement the Serializable
    : interface.


    Isn't that just one object though? Perhaps you ment to place it inside the while loop, or...? And you would need different code depending on if you want to print to screen or to a file.
  • : : [code]: :
    : : ObjectInputStream ois = ObjectInputStream(new FileInputStream("dummy.txt"));
    : : Object o = ois.readObject();
    : : while (o != null) {
    : : System.out.println(o.toString());
    [red] o = ois.readObject();[/red]
    : : }
    : : o.close();
    : : [/code]: :
    : : This works for all objects, which implement the Serializable
    : : interface.
    :
    :
    : Isn't that just one object though? Perhaps you ment to place it
    : inside the while loop, or...? And you would need different code
    : depending on if you want to print to screen or to a file.

    You're correct. There's one line missing. If you want to explicitly control where the output is going then the code becomes 1 line longer:
    [code]
    ObjectInputStream ois = ObjectInputStream(new FileInputStream("dummy.txt"));
    PrintStream tos = System.out;
    Object o = ois.readObject();
    while (o != null) {
    tos.println(o.toString());
    o = ois.readObject();
    }
    o.close();
    [/code]
    It is possible to shorten the code by inserting the assignment of o into the while condition, but I simply hate that because it decreases readability.
    It is also possible to use a for()-loop, but I'm not used to use those without a counter.
  • Thanks to everyone one for their replies and comments. I have posted my response to some of them as a comment on [link=http://outofthetriangle.wordpress.com/2007/10/18/is-c-the-only-real-language/]my original blog post[/link].

  • : For a long time I have debated with my friends/colleagues my reasons
    : for thinking that C++ is the best all round programming language. I
    : finally got round to posting this on my blog
    : ([link=http://outofthetriangle.wordpress.com/2007/10/18/is-c-the-only
    : -real-language/]Is C++ The Only Real Language?[/link]). I
  • [color=Blue]Let me rephrase the famous quote:
    [b]Language does not produce bugs, bad programmers do.[/b]
    In other words, C++ is fine, as long as one is a good programmer. Same can be said of all other languages as well.

    ..."continuous bug hunt" was not a good argument. There are simply too many mediocre programmers boomed into the profession, that's all. It will pass eventually.
    [/color]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories