Slashdot Mirror


Someone on Medium Just Said C++ Was Better Than C (medium.com)

Developer David Timothy Strauss is publishing a call to code "straightforward, easy-to-reason-about approaches" -- in an essay titled "Choosing 'Some C++' Over C". (Alternate title: "C++ for Lovers of C." The problem with just picking C++ is that most criticism of it is legitimate. Whether it's the '90s-era obsession with object orientation and exceptions or the template errors that take up an entire terminal window, there have been -- and remain -- rough edges to C++. But, these rough edges are avoidable, unlike the problems in C that get worse with modern event and library programming. The opinionated essay calls for "adopting a subset of C++ to smooth out C's rough edges," arguing that C++ offer a better, type-safe approach for event-driven design (as well as destructors to avoid memory allocation leaks). Are there any readers who'd like to weigh in on the advantages of C versus C++?

315 comments

  1. Indeed by hcs_$reboot · · Score: 5, Funny

    "C++" > "C" (as long as > has not been overloaded..)

    --
    Slashdot, fix the reply notifications... You won't get away with it...
    1. Re:Indeed by allo · · Score: 4, Funny

      In fact, it is not. Try it yourself:

      #include <stdio.h>
      int main(int argc, char **argv) {
          int C=0x11;
          if(C++ > C) {
              printf("C++ is greater than C\n");
          } else {
              printf("C++ is not greater than C\n");
          }
      }

      $ ./a.out
      C++ is not greater than C

    2. Re:Indeed by david.emery · · Score: 3, Informative

      And this highlights the difference between C and C++, and better specified/more tightly defined languages.

      Two C programmers will ask, "What will this program do?"
      Two Ada programmers will ask, "Will this program compile?" Because if it does compile, they both know (and agree on) exactly what the legal program will do.

    3. Re:Indeed by Anonymous Coward · · Score: 0

      In fact, it is not.

      Correct, that is the entire point of post-increment. ++C > C should work, barring any overflow.

    4. Re:Indeed by Anonymous Coward · · Score: 0

      The problem is that you already turned it up to 11. 11 is already one louder. You broke the system.

    5. Re:Indeed by Jamu · · Score: 1

      The result of "C++" > "C" is undefined because the pointers point to different objects?

      --
      Who ordered that?
    6. Re:Indeed by Anonymous Coward · · Score: 0

      Nuh-uh.....

      (17)

    7. Re:Indeed by Anonymous Coward · · Score: 0

      no, it is defined, because C is defined as an int above. the ++ operator is a 'post-fix' operation. Which means that it runs 'after' the other calculations have been completed. Which means that first time through C = 0x11, then C++ = 0x11 (because the +1 doesn't happen until later) and the C = 0x11. Then after the comparison is over C is incremented and NOW has the value of 0x12, but this doesn't impact the comparison.

      For those who don't know 'why' this fails (and if this isn't the reason then it is some archaic C++ issue that I'm not aware of off the top of my head due to not having touched C++ in years, and is a good example of why C++ has so many 'pitfalls' )

      ~RighteousCoder

    8. Re:Indeed by religionofpeas · · Score: 1

      What if you use Ada to write something as complex as a C interpreter ?

    9. Re: Indeed by Anonymous Coward · · Score: 5, Funny

      Trick question. There is only one ada programmer.

    10. Re:Indeed by Z00L00K · · Score: 1

      Interesting, but as I see it C++ has the bad features from both C and Ada and only have the positive side of allowing object orienting.

      However some stuff in C++ is quite confusing and does not make it very readable.

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    11. Re:Indeed by Immerman · · Score: 1

      false, it is in fact undefined - see my explanation a few posts below

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    12. Re:Indeed by Anonymous Coward · · Score: 0

      Nope. The expression "C++ > C" will always be false. The "C++" on the left evaluates to 16 and has a side-effect of incrementing the variable C. The "c" on the right will evaluate to 17. The expression "16 > 17" is false.

    13. Re:Indeed by TsuruchiBrian · · Score: 4, Informative

      It also has good features, many of which provide you with an alternative to the bad features of C.

      Constructors/destructors (RAII) > manual initialization/deinitialization.
      Smart Pointers (made possible by RAII) > raw pointers
      Polymorphism > function pointers
      Templates > macros

      If you are subscribing to a streaming movie service and you have the choice between netflix and a site that only allows you to watch "Armageddon (1998)", does it make sense to choose the latter because netflix has more bad movies? No of course not, because you don't have to watch the bad movies on netflix, and you can even choose only to watch movies better than Armageddon.

      C++ is netflix. Nobody watches all the movies. Everyone watches the movies that are good from their point of view (even though many of those people are just wrong).

    14. Re: Indeed by Anonymous Coward · · Score: 0

      The order of evaluation is unspecified by the standard. The operator > is not a sequencing point.

    15. Re: Indeed by Hognoxious · · Score: 1

      Evaluation? They look like literals to me.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    16. Re:Indeed by Anonymous Coward · · Score: 0

      try doing this
      -----
      #include
      int main(int argc, char **argv) {
              int C=0x11;
              if (C C++) {
                      printf("C is lesser than C++\n");
              } else {
                      printf("C is not lesser than C++\n");
              }
      }

      $ ./a.out
      C is lesser than C++

    17. Re:Indeed by hcs_$reboot · · Score: 1

      UB

      --
      Slashdot, fix the reply notifications... You won't get away with it...
    18. Re:Indeed by Demena · · Score: 2, Interesting

      You are quite correct. Everyone uses different subsets of C++. The consequence of this should be obvious. Do not use C++ in any circumstances where code has to be maintained. The next maintainer maybe totally unable to deal with it being an expert (and using) a different subset of C++.

    19. Re: Indeed by Anonymous Coward · · Score: 0

      Main doesn't return any value, it won't compile

    20. Re:Indeed by Anonymous Coward · · Score: 0

      You had a bug in your program. I fixed it for you:

      #include <stdio.h>
      #include <limits.h>
      int main(int argc, char **argv) {
              int C=INT_MAX; // <-- bug was here
              if(C++ > C) {
                      printf("C++ is greater than C\n");
              } else {
                      printf("C++ is not greater than C\n");
              }
      }

      $ ./a.out
      C++ is greater than C

    21. Re:Indeed by angel'o'sphere · · Score: 0

      There are no pointers involved, nor objects.

      The whole thing is for some strange reason "undefined".

      But actually it is pretty clear, why the C community made it "undefined" is beyond me, well: they did not want to impose a rule. But that is mere stupid.


          int s = 1;
          int b = 2; // s means small, b means big

          s C; // is only undefined because some guy thought, using the same variable in an expression involving ++/-- more than once is problematic. // actually they should simple have defined the behaviour. E.g. evaluate from left to right and be done with it

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    22. Re:Indeed by angel'o'sphere · · Score: 3, Interesting

      WTF, I have to escape less and greater inside of a code tag?

      There are no pointers involved, nor objects.

      The whole thing is for some strange reason "undefined".

      But actually it is pretty clear, why the C community made it "undefined" is beyond me, well: they did not want to impose a rule. But that is mere stupid.


          int s = 1;
          int b = 2; // s means small, b means big

          s < b; // true
          s++ < b++ // true ... usually, because here it starts, it is actually undefined, facepalm

          s++ < s++; // ok, here we have a point, obviously "it should be false" but it is undefined, and somehow makes sense to be undefined -- for me it makes no sense, in Java this is false

          s++ < s; // undefined in C, false in Java. // the original question
          C++ > C; // is only undefined because some guy thought, using the same variable in an expression involving ++/-- more than once is problematic. // actually they should simple have defined the behaviour. E.g. evaluate from left to right and be done with it

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    23. Re:Indeed by Anonymous Coward · · Score: 0

      the int C variable never goes to 16, on first evaluation it is "17> 17" which is false because it is equal not greater, and on next iteration "18 > 18" would be false again. But you are correct, it won't evaluate to TRUE because it would always be equal.

    24. Re:Indeed by Anonymous Coward · · Score: 0

      assuming we put it inside a for loop, it won't be evaluated as TRUE

    25. Re:Indeed by Kremmy · · Score: 1

      Ignorance of the definition does not negate it.
      The C statement "C++ > C" is not true because post-increment occurs after the statement has been evaluated.

    26. Re:Indeed by Anonymous Coward · · Score: 0

      IMHO it is clearly defined in C as well as C++, because logical operators like == >= etc have higher precedence than post increment operators. Unless if the above code snippet was coded in C++ and the operators were overloaded.

        "s++ > b++" // true ... usually, because here it starts, it is actually undefined, facepalm

      The above is also defined, this will always evaluate as TRUE.

      The only undefined code above, IF INCLUDED IN A LOOP is "s++ > s++ ", but if not in a loop this is also defined. On first iteration it is similar to "s > s" but on second iteration (assuming it is within a loop) then it is UNDEFINED depending on how the compiler was implemented because the compiler could interpret it as "2 > 3" or "3 > 2".

    27. Re:Indeed by Anonymous Coward · · Score: 0

      correction:
      s++ > s++ is also defined, lets say int s = 1; then

      s++ > s++ //this is first iteration: 1 > 1 which evaluates as false
      s++ > s++ //this is second iteration: 3 > 3 which evaluates to false
      s++ > s++ //this is third iteration: 5 > 5 which is false again.
      s++ > s++ //this is fourth iteration 7 > 7 which is false again

    28. Re: Indeed by Anonymous Coward · · Score: 0

      Eh, literals? The operands in the statement can be evaluated in any order before deciding greater than.

    29. Re: Indeed by Anonymous Coward · · Score: 0

      It compiles and runs just fine under GCC.

      The C standard specifies that "reaching the } that terminates the main function returns a value of 0."
      (5.1.2.2.3 Program termination)

      "If you leave out the return statement for main(), the program will return 0 when it reaches the closing }. So you can omit the return statement at the end of main()."
        – Stephen Prata's C++ Primer Plus, 6th Edition, p. 40

    30. Re: Indeed by Anonymous Coward · · Score: 0

      Except that he was comparing strings.

    31. Re: Indeed by Anonymous Coward · · Score: 0

      It's called a sequence point. Your compiler is free to compile "c++ c" to evaluate "c" before "c++". That being said with the choice of operator I don't think it could give different results.

    32. Re: Indeed by hackwrench · · Score: 1

      C++ > C is not the same as ""C++"> "C"

    33. Re:Indeed by mlyle · · Score: 1

      Always actually evaluating left to right is extraordinarily costly --- a lot of the trickery that compilers do to make things fast (CSE, interleaving loads & math, etc) don't work with it.

      And always actually having the same behavior as left to right, when not evaluating left to right in actuality, is hard to do and pick up any performance. Not for trivial cases like this, but because you might reach the same actual location in memory multiple ways (e.g. aliasing from pointer traversal).

    34. Re:Indeed by ooloorie · · Score: 1

      "C++" > "C" (as long as > has not been overloaded..)

      Actually, it's undefined behavior.

      On most implementations, it is not true that "C++" > "C", but it is true that "C" < "C++".

    35. Re: Indeed by Anonymous Coward · · Score: 0

      ++C on the other hand is gt C

    36. Re:Indeed by johannesg · · Score: 1

      Yet somehow, the use of ADA did not stop Ariane 501 from exploding half a minute after lift-off.

    37. Re:Indeed by ls671 · · Score: 1

      Thanks for that! I never would have guessed...

      --
      Everything I write is lies, read between the lines.
    38. Re:Indeed by johannesg · · Score: 1

      Well, at least one person noticed that the original poster was comparing two literal strings...

    39. Re:Indeed by Wootery · · Score: 1

      Then you get a valid C interpreter... obviously.

    40. Re:Indeed by goose-incarnated · · Score: 1

      Thanks for that! I never would have guessed...

      Actually, you didn't. The expression is undefined because the greater than operator is not a sequence point.

      --
      I'm a minority race. Save your vitriol for white people.
    41. Re:Indeed by goose-incarnated · · Score: 1

      s < b; // true
      s++ < b++ // true ... usually, because here it starts, it is actually undefined, facepalm

      That's well-defined. For someone arguing over the technicalities of C you sure don't seem to know the very basic rules.

      --
      I'm a minority race. Save your vitriol for white people.
    42. Re:Indeed by Anonymous Coward · · Score: 0

      If you only worry about out of bounds errors and null pointers, sure.
      There is another type of bugs: The "solution" didn't actually solve the problem.
      The way to avoid those problems is to have as few abstractions as possible and avoid external libraries with too large functions or incomplete/outdated documentation.
      Many modern languages sucks when it comes to solving those issues. In the same regard C++ has a tendency to lead to code that hides operations behind abstractions.

      I'm not sure I agree with TFA regarding the specifics, but the general idea to reduce C++ to a smaller set is probably a good idea.
      The thing is that this isn't a new concept and many compilers have support for limiting the language to MISRA-C and MISRA-C++
      A lot of the criticism I see for C and C++ is from people who clearly haven't dealt with the languages enough to use those subsets/guidelines.
      If you code that way even for applications that aren't safety critical the criticism tends to fall flat.
      At most you end up with "C/C++ is worse than Python because you have to free resources manually (Instead of having them locked up for an undefined time.) and you can't pass any object to any function. (And experience run time type errors at the customer instead of compile time type errors at the developer.)

    43. Re:Indeed by gordo3000 · · Score: 1

      there are no movies better than Armageddon.

    44. Re:Indeed by Anonymous Coward · · Score: 0

      You don't have to guess, unlike some languages C has a document that specifies what the function is supposed to be and it is actually possible to point out if a functionality is a programmer error or a compiler bug.

      From ISO/IEC 9899:1999: (Bold lines added by me.)

      6.5.2.4 Postfix increment and decrement operators
      The result of the postfix ++ operator is the value of the operand. After the result is
      obtained, the value of the operand is incremented. (That is, the value 1 of the appropriate
      type is added to it.) See the discussions of additive operators and compound assignment
      for information on constraints, types, and conversions and the effects of operations on
      pointers. The side effect of updating the stored value of the operand shall occur between
      the previous and the next sequence point.

      and Annex C of the same document:

      The following are the sequence points described in 5.1.2.3:
      — The call to a function, after the arguments have been evaluated (6.5.2.2).
      The end of the first operand of the following operators: logical AND && (6.5.13);
      logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17).

      — The end of a full declarator: declarators (6.7.5);
      — The end of a full expression: an initializer (6.7.8); the expression in an expression
      statement (6.8.3); the controlling expression of a selection statement (if or switch)
      (6.8.4); the controlling expression of a while or do statement (6.8.5); each of the
      expressions of a for statement (6.8.5.3); the expression in a return statement
      (6.8.6.4).
      — Immediately before a library function returns (7.1.4).
      — After the actions associated with each formatted input/output function conversion
      specifier (7.19.6, 7.24.2).
      — Immediately before and immediately after each call to a comparison function, and
      also between any call to a comparison function and any movement of the objects
      passed as arguments to that call (7.20.5).

      As you can see ">" doesn't lead to a new sequence point and the increment will be done after the comparison.

      A language that lacks documentation like that is always non-portable since the functionality is compiler defined rather than language defined.
      Java is for example pretty notorious for having minor differences between different platforms leading to the "Write Once, Debug Everywhere" joke.

      Same goes for many "modern" languages.
      Some boast that they are more stable and generates better code but no-one is willing to guarantee that the functionality will be preserved to the next version of the compiler.

      When old farts sticks to C and refuses to go to newer languages it isn't always because they are unwilling to learn new languages.
      Sometimes it is because the the "new language" isn't a language at all but rather just a toy compiler or interpreter without a properly defined language behind it.

    45. Re:Indeed by Anonymous Coward · · Score: 0

      I don't know C++ well enough to contest if it is defined there or not.
      In C99 (ISO/IEC 9899:1999) "C++ > C" is however properly defined and evaluates to false.
      I quoted the relevant sections in my response to ls671 above.
      As for "++C > C" I didn't see anything about it being undefined and the order the expressions are evaluated in is defined.
      Think of an expression "function_call() > function_call()"
      The compiler may not change order since the function may update values and return different results.
      Same goes for "++C > C". It has to do the increment first and the expression will evaluate as false.

      Then again, C++ may be different, perhaps it is undefined there.

    46. Re: Indeed by Anonymous Coward · · Score: 0

      A specification doesn't help with the majority of people (obviously including you) not being able to read it. The part you quoted by itself already says that the increment happens between the previous and the next sequence point. What that means is that you cannot know whether C was or was not incremented when the right side of that comparison is evaluated.
      Though there might be additional language that moves this completely into undefined behaviour, which has worse effects than just being off by one...

    47. Re: Indeed by Anonymous Coward · · Score: 0

      No, you just don't know C and can't read specs. None on this is will defined, not in ANSI C, not in C99, not in C11, nor in any C++ variant.

    48. Re:Indeed by hcs_$reboot · · Score: 1

      Depends how you declare the arrays (and the implementation..)...
      char *cpp = "C++";
      char *c = "C";
      printf("C++ > C => %s\n", (cpp > c ?"yes":"no"));
      :-)

      --
      Slashdot, fix the reply notifications... You won't get away with it...
    49. Re: Indeed by Hognoxious · · Score: 1

      https://slashdot.org/comments....

      Can you not see the quotes?

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    50. Re:Indeed by Anonymous Coward · · Score: 0

      Actually, C++ > C should always return false, since C++ means "return value of C and then increase the value with one", it will compare C > C.

      ++C > C should, conversely, always return true (since ++C means "increase C with one and return the value"), the comparison becomes ((C+1) > C).

      Strangely enough, this is not the case when I try it in GCC, so either I discovered a bug in GCC or it really is undefined. :)

    51. Re: Indeed by TheRaven64 · · Score: 1

      Are you sure it's not defined in C++? I thought that C++11 removed the requirement of sequence points, on the basis that existing compilers did the right thing and programmers didn't understand them.

      --
      I am TheRaven on Soylent News
    52. Re:Indeed by angel'o'sphere · · Score: 1

      It is not defined in which order the left and the right side of the less sign is evaluated.
      You should consult the manual of C/C++ - which ever you use - again.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    53. Re:Indeed by goose-incarnated · · Score: 1

      It is not defined in which order the left and the right side of the less sign is evaluated. You should consult the manual of C/C++ - which ever you use - again.

      The order in this case does not matter, which is why it is well defined. The standard calls. It well defined, it is predictable what the outcome will be every time hence it is well defined. The expression 'C++ > C' is not well defined because the outcome cannot be predicted every time.

      --
      I'm a minority race. Save your vitriol for white people.
    54. Re:Indeed by Anonymous Coward · · Score: 0

      $ gcc a.c
      a.c:1:9: error: expected "FILENAME" or
      #include
                      ^
      a.c:4:15: error: expected ')'
                      if (C C++) {
                                  ^
      a.c:4:12: note: to match this '('
                      if (C C++) {
                            ^
      a.c:5:17: warning: implicitly declaring library function 'printf' with type
                  'int (const char *, ...)' [-Wimplicit-function-declaration]
                                      printf("C is lesser than C++\n");
                                      ^
      a.c:5:17: note: include the header or explicitly provide a declaration
                  for 'printf'
      1 warning and 2 errors generated.

    55. Re:Indeed by angel'o'sphere · · Score: 1

      Well,
      perhaps you are right. I learned to avoid "decisions" based on code like this.
      Perhaps the "defined" or "undefined" state changed recent years or decades.

      The expression 'C++ > C' is not well defined because the outcome cannot be predicted every time.
      That is nonsense. You could simply define: evaluate from left to right. Then it would always be false because the left side would be less than the right side. There is nothing special in that expression. Except: it is undefined. Pretty odd that a modern day programming language leaves behaviour like this "undefined".

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    56. Re:Indeed by Anonymous Coward · · Score: 0

      The result is "D"

    57. Re:Indeed by goose-incarnated · · Score: 1

      Well,
      perhaps you are right. I learned to avoid "decisions" based on code like this.
      Perhaps the "defined" or "undefined" state changed recent years or decades.

      The expression 'C++ > C' is not well defined because the outcome cannot be predicted every time.
      That is nonsense. You could simply define: evaluate from left to right. Then it would always be false because the left side would be less than the right side. There is nothing special in that expression. Except: it is undefined. Pretty odd that a modern day programming language leaves behaviour like this "undefined".

      Once again I have to ask that you read the actual C standards; start with n869.txt. The statement is not undefined because evaluation order cannot be guaranteed, it is undefined because there is more than one reference to a variable without a sequence point in between.

      You appear to believe that the language designers looked at this special case and said "lets leave this undefined". That is not what happened. They said "reading a variable while writing it or writing a variable while reading it is undefined."

      A side-effect is that expressions like "i = i++ + i++;" and "i++ > i" are undefined.

      --
      I'm a minority race. Save your vitriol for white people.
    58. Re:Indeed by ooloorie · · Score: 1

      Hence "undefined behavior".

    59. Re:Indeed by david.emery · · Score: 1

      True. It's because they turned off the checking provided by the language.

    60. Re:Indeed by Anonymous Coward · · Score: 0

      It helps if you fill in the missing angle brackets (and stdio.h) removed by Slashdot's brain-dead comment parser.

    61. Re:Indeed by angel'o'sphere · · Score: 1

      In original C, K&R the idea of a "sequence point" did not even exist.

      You appear to believe that the language designers looked at this special case and said "lets leave this undefined".
      No, I don't believe that. I know it. Facepalm.

      They said "reading a variable while writing it or writing a variable while reading it is undefined."
      Yes. And? It actually is not undefined.
      If you brain dead code it down to assembly it basically defined in every assembly I know to "work as expected".
      And you could simply have made the definition that it works as expected. Every language except C/C++ does that. E.g. Pascal/Ada/Java.

      They said "reading a variable while writing it or writing a variable while reading it is undefined."
      This is not happening in this case.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    62. Re:Indeed by 14erCleaner · · Score: 1
      I found the bug in your program. Line 4 should be

      if (C = C++) {

      Change that and it works fine.

      --
      Have you read my blog lately?
    63. Re:Indeed by Anonymous Coward · · Score: 0

      ((C+1) > C). would return true?
      Not correct, remember the right side C would also be updated, because remember you're comparing it to itself.
      It would still be the same as C > C except the value of C is incremented first. Hence that statement wouldl always return FALSE or zero.

    64. Re:Indeed by Wuhao · · Score: 1

      Huh? I think if you read that program and don't know that `C++ > C` == false, you don't know how the post-increment operator works and you're not much of a C programmer.

    65. Re:Indeed by Anonymous Coward · · Score: 0

      Because if it does compile, they both know (and agree on) exactly what the legal program will do.

      I think you're confused. There is no undefined behavior in that code snippet. It doesn't matter if the right hand 'C' is evaluated before or after the left hand post-increment -- either way it's not possible to make it smaller than itself ;-)

      Are you mythical Ada programmers supposed to be competent, right? If you don't make accommodations for ignorant dabblers in Ada, why it's C code supposed to be readily obvious for someone who couldn't be bother to spend two minutes to think it through?

    66. Re: Indeed by tender-matser · · Score: 1

      In C99, the main() function doesn't need any return statement. See 5.1.2.3:

      reaching the } that terminates the main function returns a value of 0.

    67. Re:Indeed by johannesg · · Score: 3, Informative

      Just the other way around: it happened because it was checking, and the additional acceleration of Ariane 5 caused an overflow. Without checking everything would have been fine.

    68. Re:Indeed by epine · · Score: 2

      Huh? I think if you read that program and don't know that `C++ > C` == false, you don't know how the post-increment operator works and you're not much of a C programmer.

      This is the reason this entire thread is pointless.

      Going all the way back to the seventies, it was a core design decision in the C language not to over-specify the semantics of expression evaluation to the degree that tricky, efficient implementations became impossible on realistic architectures.

      So the decision was: we're not going to nail your nuts to the floor on side-effects until you reach a sequence point in the expression.

      The C language has a fairly low cognitive burden, and likewise, the world back in the 1970s had a fairly low cognitive burden. One could afford an entire day to actually read K&R.

      Then along comes C++, which follows mostly the same instincts and intuitions, with a desire to maintain a fairly hard standard of compatibility, and now we have a language with a high cognitive burden (in a world with a high cognitive burden) painstakingly built on a foundation that was already trickier than your average ninnie-poo can be bothered to properly master.

      C++ is a fine programming language IF AND ONLY IF you're willing to take on the cognitive burden in the broad spirit of no compromise.

      Before the first Zortech C++, I had already taken this step with the supposedly simple and trivial C language. And I just kept on going in the same spirit when C++ came along. Most of its quirks are there for a reason. It's a big commitment to know all the reasons.

      And here we are in a world where the burden of mastering a tiny handful of C-language quirks lies beyond 90% of the programming population.

      For you people, there's Java. Java even tried to make floating point deterministic across all architectures, present and future, so that ninny-poo legion would never have to learn the first thing about the artful compromise of sequence points and guard digits.

      Java is such a nice cradle to grave language—coffin lid included.

      Personally, I always wanted to be buried in a big boy box, so I put in the effort to know better. The world is so complex now, I would almost classify knowing better as a form of leprosy.

      Emphasis on almost.

    69. Re: Indeed by Anonymous Coward · · Score: 0

      It seems the name was changed to "sequencing" and some cases might have changed from undefined to "arbitrary order", though I mostly base this on Wikipedia. I don't think the underlying problem and the need to avoid constraining compiler optimizations too much has changed.

    70. Re: Indeed by gwjgwj · · Score: 1

      This software has been written in Ada: http://www-users.math.umn.edu/...

    71. Re:Indeed by sconeu · · Score: 1

      Undefined behavior.

      --
      General Relativity: Space-time tells matter where to go; Matter tells space-time what shape to be.
    72. Re:Indeed by Anonymous Coward · · Score: 0

      It's working fine here.

    73. Re: Indeed by Anonymous Coward · · Score: 0

      The second highlighted passage describes which operators cause a new sequence point, and greater than is not one of them... He read the standard just fine.

    74. Re: Indeed by Anonymous Coward · · Score: 0

      It is defined. Read up on sequence points.

    75. Re: Indeed by Anonymous Coward · · Score: 0

      No, in both cases the values in the expression are all are retrieved before the expression is evaluated. With prefix the value is incremented before retrieval, and with postfix the value is incremented after retrieval. In either case it's always false... 17 >17 or 18>18.

    76. Re:Indeed by TsuruchiBrian · · Score: 2

      I don't think you can call yourself a C++ expert and be "totally unable to deal with" a C++ codebase that uses a different subset of C++ than what you would have used.

      You can certainly be a C++ expert and be totally unable to deal with a very poorly designed codebase, but that is true for every language (even C).

      Maybe there are more experts in the C language, because it is a simpler language and therefore an easier language to become an expert at. I would be totally in favor of using a simpler language for a project if there were no benefit to any of the more advanced features provided in C++, but that is rarely the case.

      The 4 things I listed are insanely powerful tools for making safer and more maintainable code, and these things come with little to no performance overhead.

    77. Re:Indeed by Demena · · Score: 1

      I don't think you can call yourself a C++ expert and be "totally unable to deal with" a C++ codebase that uses a different subset of C++ than what you would have used.

      I totally agree. However that just tends to suggest that there are no expert C++ users. Just experts with a particular codebase. Which makes interviewing problematic.

      Maybe there are more experts in the C language, because it is a simpler language and therefore an easier language to become an expert at. I would be totally in favor of using a simpler language for a project if there were no benefit to any of the more advanced features provided in C++, but that is rarely the case.

      You toss that off lightly but I ponder its truth. It is problems and solutions that determine complexity. The question is not whether a language is simple or complex it is whether the language is appropriate to the solution. If it is then it will be simple. If it is not then the result will be complex. Complexity is seldom needed and never when simplicity will do. Human brains do not handle complexity well and the few that do do not handle it constantly or continuously. There is a lot to be said for keeping things simple.

    78. Re:Indeed by Wootery · · Score: 1

      If you only worry about out of bounds errors and null pointers, sure.

      Well, you get a valid C interpreter. That was the question.

      There is another type of bugs: The "solution" didn't actually solve the problem.

      Well of course it's not a useful thing to do in practice. If you want assurances that your C code isn't going to behave differently on different (but compliant) C platforms, you'd go with something like MISRA C, as you say.

      I broadly agree with your other points.

      I'm not sure I'd say C++ memory-management is 'manual' though. Reference-counting has its drawbacks, but it's hardly fair to say it's 'manual'. (And if you're using C++ and not using smart pointers, you're doing it wrong.)

      Agree that the absence of dynamic typing is not a flaw, but a valid design decision.

    79. Re:Indeed by Anonymous Coward · · Score: 0

      I believe tool complexity and product complexity is a zero-sum game. The more complex the tool, the less complex are the usable products made with it. Because if brain capacity remains constant it has only so much room for total complexity.

    80. Re: Indeed by Anonymous Coward · · Score: 0

      Please give one specific example of behavior that is different depending on the platform. Java is quite well-specified.

    81. Re: Indeed by david_thornley · · Score: 1

      In C++ > C, the increment happens between the previous and the next sequence points. It's exactly because > does not cause a new sequence point that there is no sequence point between C++ and C, and so by 6.5.2.4, the increment takes place at roughly the same time as the comparison, possibly before and possibly after.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    82. Re:Indeed by david_thornley · · Score: 1

      I don't know C99 as precisely as C90, but at least in C90 the statement is undefined, and causes the whole program to be undefined. The result of the comparison can be true, false, or Tuesday, all according to the standard.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    83. Re:Indeed by david_thornley · · Score: 1

      Doubtless it's undefined because different machines in common use would have done it differently, and so specifying behavior would have slowed computation down. One design goal of C was to prioritize execution speed of its output. Similarly, signed arithmetic overflow is undefined, because some processors threw some sort of exception or signal and some just went with the overflow. If the Standard specified what happened, one of those groups was going to be unable to do signed arithmetic without checking things. Personally, I think they should have defined possible behaviors and left them to be unspecified or implementation-defined (implementation-defined means the behavior has to be documented, while unspecified means it has to do something reasonable but the programmer can't count on any particular behavior).

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    84. Re:Indeed by david_thornley · · Score: 1

      No. You're confusing order of evaluation with order of side effects. The two are not connected. When the comparison takes place is unrelated to when the increment takes place. The value of s++ is evaluated before the comparison, but all we know about the increments is that they have to take place sometime before the next sequence point. You also mean lower precedence, not higher precedence.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    85. Re:Indeed by david_thornley · · Score: 1

      In K&R C, there was no clear way to tell what would happen with some constructs, but didn't have undefined behavior in the sense of a C Standard.

      The first C Standard was in 1989. It was an ANSI standard, and became an ISO standard in 1990. According to the Standard, the behavior of "C++ &gt/; C" is undefined. More practically, there are several operations there (two fetch Cs, one evaluation, one increment, and one comparison) and only a partial order. It will indeed be translated into assembly or machine code that will do something predictable from the assembly or machine code (or maybe not (there are exceptions here), but the Standard does not define what assembly or machine code should be written, or what it should do.

      And what is expected behavior? Side effects in the order of evaluation, or side effects at the end? I can easily justify either.

      In this case, a variable is being read (both C and C++) and written (the result of C++) between sequence points, which is C's idea of "while".

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    86. Re: Indeed by david_thornley · · Score: 1

      No, in both cases the values in the expression are all are retrieved before the expression is evaluated.

      There is nothing in any of the Standards mentioned that supports your statement. Other languages may well do it this way, but not C or C++.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    87. Re:Indeed by david_thornley · · Score: 1

      As TsuruchBrian said, it is possible to have existing code so badly written that nobody's going to figure it out, and that's possible in any general-purpose computer language. However, given a reasonably well-written C++ codebase, someone who is good at C++ will not have excessive difficult in maintaining it. We know this from experience, We have a large C++ codebase, reasonably well-written considering its history, and when we hire people with C++ experience who have never seen the codebase, the big problem with familiarization is the complexity of the problems it solves.

      Problems can be simple of complex. If they're simple, it doesn't matter much what language the solution is in. When they're complex, you want a language that handles complexity well, typically by creating abstractions to keep the complexity of any given piece manageable. C++ is very good at that. C is not nearly as good at it. Given a complex problem, the C++ solution will normally be considerably shorter and much easier for someone skilled in the language to understand, partially or in toto, than a C solution.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    88. Re: Indeed by david_thornley · · Score: 1

      In which case, it's still undefined, since "C" and "C++" will be in two distinct places in memory that have no connection, and comparisons are undefined. (There have been weird memory access systems that justify this, I believe.) In practice on modern computers, there will be two numeric memory addresses, and no way to determine beforehand which is higher.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    89. Re:Indeed by david_thornley · · Score: 1

      Do that, and you will find how the specific version of the specific compiler you are using does it in that context. If you do it in gcc, you don't know what clang will do. That's why we have standards: so we can write code that will work in different compilers and have it do what we want.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    90. Re:Indeed by TsuruchiBrian · · Score: 1

      There are different types of simplicity. There is simplicity involved in creating something and the simplicity of using it, and these 2 things are often opposed to each other. Raw pointers are simpler to create than smart pointers (the language feature, not an instance). They are easier to understand than smart pointers. They are harder to use correctly than smart pointers. How many bugs are a result of improper pointer use?

      And if you look at code that uses raw pointers and the same code that has been modified to use smart pointers, the code that uses smart pointers will look simpler. It will look the same minus all the delete/free calls, and minus some NULL checks.

      So yes, smart pointers are more complex in some sense. But if you consider the problem of enforcing the proper use of pointers, rather than just deferring that problem to the next programmer, smart pointers are a very simple solution to this problem (e.g. as opposed to something like garbage collection).

      Not solving problems is simpler than solving them. I am all for not solving problems that don't need to be solved. But preventing pointer misuse seems like a problem worth solving, and it is solved elegantly with smart pointers.

      This is just one example of something you can do with a more complex language like C++ that you can't do in C.

    91. Re:Indeed by sconeu · · Score: 1

      Undefined behavior can do anything.

      "Anything" can include

      1. Appearing to work "correctly"
      2. Crashing with a core dump
      3. Uploading your data to Alpha centauri
      4. Formatting your hard drive
      5. Asking if you want to play a game of Global Thermonuclear War

      --
      General Relativity: Space-time tells matter where to go; Matter tells space-time what shape to be.
    92. Re:Indeed by zwarte+piet · · Score: 1

      Line 4 should be: if (++C > C) {

    93. Re:Indeed by allo · · Score: 1

      The question was is C++ greather than C. I do not know a language called ++C.

    94. Re:Indeed by zwarte+piet · · Score: 1

      I C what you did there.

    95. Re:Indeed by Tablizer · · Score: 1

      There's a trade-off. More casual or what may be called "scripting" languages in general are designed to limp rather than halt or die, while type-heavy languages (usually compiled) tend to die (halt execution) rather than limp.

      Which is "better" depends. Maybe the rocket would still have done it's job without the bounds checking, but perhaps it might also have careened into a city rather than self-destruct or stop and fall into the ocean.

      When dealing with life, money, and laws; a halt is usually preferred over letting the system force some default "guess" and try to continue on, which may cause more problems than outright stopping. If a paycheck printing system encounters something like a numeric overflow or null pointer, you probably want it to stop rather than issue paychecks that may be flat out wrong, such as paying the janitor 2 million dollars.

    96. Re:Indeed by herbierobinson · · Score: 1

      Ummm... I think the original intent of this thread was humor. Or perhaps trolling. It certainly has nothing to do with C vs C++, because both have the same issues with that piece of code.

      --
      An engineer who ran for Congress. http://herbrobinson.us
  2. Kids these days... by zm · · Score: 2

    Code in assembly, then you can come back to my lawn..

    --
    Sig ?
    1. Re:Kids these days... by Anonymous Coward · · Score: 1

      You joke, but once RISC-V becomes dominant and Moore's law ends, I can see the programming world moving from bloated languages back to good old (RISC-V) assembly in order to squeeze every last drop out of our no-longer-improving processors.
      Those who cannot adapt to the new assembly world order will be dissolved, their precious proteins and fatty acids harvested to feed superior programmers like myself.

    2. Re: Kids these days... by Anonymous Coward · · Score: 0

      Kids these days. All I had to program with was a magnetized needle.

    3. Re:Kids these days... by phantomfive · · Score: 1

      With a halfway decent macro library, assembly's not too bad.

      --
      "First they came for the slanderers and i said nothing."
    4. Re:Kids these days... by __aaclcg7560 · · Score: 1

      I wanted to take assembly in college. Alas, I went back to community college after the dot com bust. I couldn't get classes in the beginning because they were too many students. I couldn't get classes towards the end because they weren't enough students. When I showed up for the assembly class, I was the only student to show up and the class needed 20+ students to qualify for state funding. Since assembly wasn't a required course, I couldn't take it as an independent study class.

    5. Re:Kids these days... by religionofpeas · · Score: 1

      So, learn assembly in your free time.

    6. Re:Kids these days... by __aaclcg7560 · · Score: 1

      So, learn assembly in your free time.

      It's on my to-do list. I'm currently going through an old compiler book to translate Borland C into modern C and learn Pascal to use the resulting Pascal compiler.

    7. Re:Kids these days... by Immerman · · Score: 2

      Moore's law is unlikely to end any time soon - while it's frequently mis-quoted as having something to do with transistor density or speed, the original claim is only that the number of transistors in a dense integrated circuit would double every year (later revised to every two years, and often claimed as 18 months due to being conflated with a prediction out of Intel at about the same time that processing speeds would double that often)

      While transistor silicon speeds are indeed plateauing, transistor counts keep growing as parallel processing technologies improve, and eventually an alternative computation technology will become cost effective, and the cycle will continue. It seems unlikely that RISC-V will still be relevant when Moore's Law finally does end.

      Moreover - if you've hit the limit of your transistor technology, why on earth would you want to switch to a RISC processor? RISC = a smaller set of simpler computations per tick - it's advantage (other than cost) was that you could build a smaller, faster processor so that even if it took several ticks to do what a more complex processor could do in one tick, it could make up for it by having more ticks per second. But if you've hit the limit of your transistor technology, then everybody is running the same number of ticks per second, and overall speed will be determined entirely by how much work you can get done per tick.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    8. Re:Kids these days... by CAOgdin · · Score: 1

      Probably not in our lifetimes, if present trends endure. Consider one quark-per-bit???

    9. Re:Kids these days... by Immerman · · Score: 1

      Me, I'd need a specific goal for that. I always found I could learn a *lot* faster within the structured classroom environment, and with the benefit of face-to-face conversations with people who understand the topic considerably better than I. And taking classes when you have a full time job - well, good luck with scheduling.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    10. Re:Kids these days... by Anonymous Coward · · Score: 0

      Screw assembly! Occam forever!!

    11. Re:Kids these days... by JustNiz · · Score: 1

      >> I'm currently going through an old compiler book to translate Borland C into modern C

      err... why?

    12. Re:Kids these days... by __aaclcg7560 · · Score: 1

      >> I'm currently going through an old compiler book to translate Borland C into modern C

      err... why?

      To learn C better. Also to learn how to write compilers. The used — and very obsolete — edition of the book was cheaper than the current edition ($5 vs. $70), and modern C compiler books are very expensive. Once I understand how to write compilers, I'll write a BASIC compiler in Python. I've been translating old BASIC games into Python, which I've never gotten to work on my Commodore 64 as a teenager. Of course, Python extensions are written in C (or Cython).

      Keep in mind that I got an A.S. degree in computer programming and work in IT support. My education was practical, not theoretical or theological.

    13. Re:Kids these days... by __aaclcg7560 · · Score: 1

      And taking classes when you have a full time job - well, good luck with scheduling.

      Depends on how motivated you are. I worked 60+ hours per week as a video game tester, taught Sunday school and took two classes per semester for five years. I even made the college president's list for maintaining a 4.0 GPA in my major. That was made possible by a $3,000 tax credit that George W. signed into law after 9/11 to help people transition into new careers. While I don't work as a programmer, understanding programming help me troubleshoot difficult problems in IT support.

    14. Re: Kids these days... by Anonymous Coward · · Score: 0

      RISC processors have up.to 14 stages, with out-of-order execution, register scoreboarding, lookahead stages multiple logic unit pipelining. Just about every CISC processor is actually a RISC processor internally.

      The advances now are intelligent memory which could do common operations like clear, boolean and arithmetic operations.

    15. Re:Kids these days... by Hognoxious · · Score: 1

      I couldn't get classes in the beginning because they were too many students. I couldn't get classes towards the end because they weren't enough students.

      Did you do any classes on algorithms? If so, was binary search covered?

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    16. Re:Kids these days... by __aaclcg7560 · · Score: 1

      Did you do any classes on algorithms?

      That was probably under the "Data Structures" course.

      If so, was binary search covered?

      Binary search for the tree data structure.

    17. Re:Kids these days... by Hognoxious · · Score: 1

      Oh. Did you take any Gen Ed classes, like perhaps legendary literature or folkloric fantasy?

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    18. Re:Kids these days... by __aaclcg7560 · · Score: 1

      Oh. Did you take any Gen Ed classes, like perhaps legendary literature or folkloric fantasy?

      During my first tour through college, I took a half dozen lit classes (English Lit 1 & 2, American Lit 1 & 2, Women Lit and World Lit) and graduated with A.A. degree in General Education (1994). The only reason I graduated with G.E. instead of English is that the G.E. requirements didn't require a biology lab to dissect a frog. Because I completed an A.A. degree, I was only required to complete the major classes for an A.S. degree and graduated in Computer Programming (2007).

    19. Re:Kids these days... by bzipitidoo · · Score: 1

      You know you can load a binary into a debugger and view the assembly code?

      There's really not much to basic assembler. You have main memory, registers, and flags. You can move bytes (1, 2, 4, or 8 at a time, usually) between memory and registers. You can do basic arithmetic and bit operations in the registers, and those set the flags. You can make jumps (gotos) based on whether the the flags are set or not. That's pretty much it. The hard part is putting such basic instructions together to accomplish things. It takes a lot of assembler to do even the simplest things.

      Be warned that the x86 instruction set is loaded with all kinds of obsolete crap and dumb ideas. Like, it has instructions for doing basic arithmetic on packed decimal representations of numbers, as well as straight binary representations. Nothing uses packed decimal these days, it's all done in binary. Then there's the stack stuff, PUSH, POP, CALL, RET, and a few others. They're excellent examples of instructions that are less useful and general than they could be, because they do a little too much.

      --
      Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
    20. Re:Kids these days... by JustNiz · · Score: 1

      No, just reverse engineering existing code wont tell you what you really need to know, which is the theory behind what the programmer was thinking.

      Besides, the preprocessor may have been auto-generated with something like lexx/yacc which makes a giant state machine and will just give you a giant headache trying to figure it out from the code.
      You need to read up on tokens, lexemes, parse trees and other internal representations, once you understand those, you'll understand the meat and potatoes of a compiler.

      Also you're probably far better off looking at something like GCC than some old Borland crap.

    21. Re:Kids these days... by angel'o'sphere · · Score: 1

      Coding in assembly is much easier than coding in a high level language and "doing it right".

      No idea where this Myth "if you can not do it in assembly you are not a real programmer" comes from.

      On the other hand, I pitty those who need to do assembly in 86k and its derivations.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    22. Re:Kids these days... by angel'o'sphere · · Score: 0

      It is not worth learning assembly.

      Chances you will ever use it is basically zero. And: there is nothing to learn from it that translates into your high level usage of languages. The idea that only C or assembly programmers know "what he machine is doing" is a myth.

      As a hobbyist, or a professional, who is interested in it, I would simply read about SWEET16 and try to implement it in a language of choice. More fun ... in all regards.

      I used a Groovy DSL to have a SWEET16 interpreter ... taught me much about Groovy and DSL's ;D (SWEET16, I literally leaned when I was ... well, 17)

      SWEET16 is a virtual machine/assembly language invented by Steve Wonziak to implement parts of Apple ][ integer basic. A virtual machine with 16 16bit registers and something like 15 or 16 op codes.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    23. Re:Kids these days... by __aaclcg7560 · · Score: 1

      Besides, the preprocessor may have been auto-generated with something like lexx/yacc which makes a giant state machine and will just give you a giant headache trying to figure it out from the code.

      I got the O'Reilly lexx/yacc book.

      You need to read up on tokens, lexemes, parse trees and other internal representations, once you understand those, you'll understand the meat and potatoes of a compiler.

      Those subjects are covered in the compiler book, which was previously used as a textbook in the early 1990's.

      Also you're probably far better off looking at something like GCC than some old Borland crap.

      The code in the compiler book was compiled with Borland C in the late 1980's. I have to modify the code to be ANSI C compliant for GCC to compile without error.

    24. Re:Kids these days... by __aaclcg7560 · · Score: 1

      You know you can load a binary into a debugger and view the assembly code?

      Been there, done that. Commodore 64 in the 1980's and DOS debug in the 1990's.

    25. Re:Kids these days... by __aaclcg7560 · · Score: 1

      Chances you will ever use it is basically zero.

      Depends on what microcontroller I used on the hardware side. The newer ones have built-in boot loaders and accept C code over USB. The older ones require assembly language to take up less space than BASIC or C.

    26. Re:Kids these days... by slashdot_commentator · · Score: 2

      It is not worth learning assembly.

      You are dead wrong. I wish I had the points to downvote your post.

      You are correct that its not worth learning assembly, in order to learn "modern" software development.

      What makes learning assembly valuable is that it is the most barebone, lowest level set of instructions that a human can cobble together for a CPU to execute. Every other language involves cobbling together hundreds of CPU instructions which would be magnitudes more inefficient than expressing it in assembler. Because higher level languages are designed for humans to understand what they are instructing the CPU to do, in the desire to increase the output of human programmers, at the expense of actual execution efficiency.

      By writing programs in assembler, particularly I/O routines, the human programmer learns how the CPU "thinks". And indirectly, learns to comprehend that all current computers are constructed to the same design specified by Turing back in the beginning. You come to realize that all CPUs work the same way, even though they have different sets of CPU instructions. They're all moving data from storage to memory, memory to register, simple ALU operations in the register, and moving it back to memory and eventually storage.

      Most people cannot read a book, and magically implement code or concepts from scratch. They need to write programs, have those programs fail, and learn to figure out why they failed. That way, those programmers learn how to express what they want done to the machine. Learning assembler is learning how the CPU thinks, and how assembler instructions are building blocks to abstractions. Assembler programmers (and to a lesser extent C programmers) really do understand "what the machine is doing".

      Yes, once you can master assembler for one CPU platform, you'll probably never need to learn to do it for a different CPU, and probably never need to write assembler again. You learn to code assembler to truly grasp how a set of chips operate to produce the simulacrum that is the personal computer.

      --
      There is no America. There is no democracy. There is only IBM and AT&T and DuPont, Dow, General Electric, and Exxon
    27. Re:Kids these days... by jiriw · · Score: 1

      Almost agree to you... but the basis of modern computer architecture is not Turing but von Neumann. However, von Neumann was well aware of Turings work and the fact it described computers on an even more fundamental level.

      For a machine to be a computer, it needs to be Turing Complete*. The machine can simulate any single-taped Turing machine. But it doesn't have to adhere that architecture. As long as it can simulate it, it's fine. *: Caveat: limited memory.

      The von Neumann architecture tells of a CPU with a control unit, an ALU for calculations and a memory unit that stores both program and data. Connected to it are in/output devices. Exactly what it does nowadays still, in a PC, and exactly what they did from the moment von Neumann began working on such computers, at least since his draft report on the EDVAC.

    28. Re:Kids these days... by religionofpeas · · Score: 1

      Then there's the stack stuff, PUSH, POP, CALL, RET, and a few others

      How are these obsolete or dumb ? All four are in the top 20 of most used x86 instructions.

    29. Re:Kids these days... by religionofpeas · · Score: 1

      I find often find myself looking at the disassembly listing to solve tricky issues. For instance, if I want to find out why a certain library call was included, or if I want to see if the interrupt handler was optimized well enough by the compiler. In some cases, writing a little bit of assembly is useful for task switching, or accessing special features in the CPU.

    30. Re:Kids these days... by slashdot_commentator · · Score: 1

      No, you're absolutely right. Brainfart on my part.

      --
      There is no America. There is no democracy. There is only IBM and AT&T and DuPont, Dow, General Electric, and Exxon
    31. Re:Kids these days... by slashdot_commentator · · Score: 1

      On the Internet, every dog is a world class assembly programmer.

      --
      There is no America. There is no democracy. There is only IBM and AT&T and DuPont, Dow, General Electric, and Exxon
    32. Re:Kids these days... by angel'o'sphere · · Score: 1

      No idea what you want to point out.

      All majour computing platforms in our days are RISC.

      86k is on the fly translating old 86k code into VLIW/RISC instructions.

      The core of an i5 or i7 is RISC. Basically all other processors are RISC from bottom up. ARM as the prime example.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    33. Re:Kids these days... by angel'o'sphere · · Score: 0

      There are not many people doing assembly programming.

      So being world class is actually very easy.

      I did not meet anyone below age of about 45 who ever did assembly. Basically only old guys who remember pre C times, or had an Apple ][ or Commodore 64 etc. or are really old and worked on General Data, PDP/11 etc. or on Mainframes when assembly still was en vogue, know about it.

      This /. talks about assembly and "knowing how the machine real works" are completely bollocks.

      A CPU has a status register, depending on architecture an accumulator, but usually in our times lots of general purpose registers. Older ones had data registers and address registers ...

      In other words: programming in assembly is probably the most simple and easiest way to program. Bottom line you don't need to know anything except the opcodes.

      Programming in LISP, PERL, SQL, Prolog are a complete different thing. That is challenging.

      If one in my company would claim assembly is more "complicated" than a complex SQL query I would be tempted to fire him.

      I programmed 6502, 68k, ARM, SPARK, PowerPC and MIPS in assembly. I started with the first one around 1985. Except for 68k (the first sane high level processor) and ARM (the first intelligent OP code design) the others were a waste of time. The compiler, regardless of Pascal or C, produced better code than you could do by hand ... and that was 20 years ago!

      If you want to learn assembly because you like intellectual masturbation, then learn ARM. In real live you will never need it. I doubt if you google you will find a job offer for an assembly programmer.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    34. Re:Kids these days... by bzipitidoo · · Score: 1

      For one example, consider tail-end recursion. CALL stores a return address on the stack, which is not needed in tail-end recursion. So if you use CALL and RET, you will either have to waste lots of stack space, which will make the program more likely to run out of memory and crash, and which will be slower, or do some extra work like POPing the unneeded address to stop the stack from growing, then when it is time to RET, putting it back on just to give RET something to pop. It's just better to use jumps.

      For another example, many subroutines are very short, do not use all the registers, and are not recursive. Better to copy the instruction pointer into another register of the programmer's choice, then jump. When the subroutine is done, just do an indirect jump to the address contained in that register. Further, to save the contents of the registers it does use, either you have to do a PUSHA and save them all, even the ones it wasn't using, which wastes space and time, or you have to do individual PUSHes of the several registers it does use, which is very bad. Each PUSH instruction updates the stack pointer. It stalls the execution pipeline to update the same register repeatedly. Why not just update the stack pointer once? PUSHing 6 registers is the equivalent of writing MOV and ADD SP,4 6 times. Better to do 6 MOVs and one ADD SP,24, unless size of the code is more important than speed, as PUSH is a shorter instruction than MOV.

      As for using the stack to pass parameters, yuck. Same problem, you're updating SP multiple times instead of once, or not at all, as all that will happen is the routine will just POP the parameters right back off the stack. Whenever possible, use registers to pass parameters.

      Additionally, if you don't use the stack instructions at all, then you free up the SP register (and the SS register) for whatever you want. A longstanding criticism of the x86 architecture was the small number of general purpose registers. Intel has done a lot to address that, and these inherent inefficiencies, so those problems are not as bad on a modern x86 CPU as on a 386 or 486.

      --
      Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
    35. Re:Kids these days... by JustNiz · · Score: 1

      >> Those subjects are covered in the compiler book, which was previously used as a textbook in the early 1990's.

      Great, Thats all you need.

    36. Re:Kids these days... by Anonymous Coward · · Score: 0

      You are right, in that you shouldn't downvote for disagreement. You should respond with a counterpoint.

      You're terribly wrong in your opinion of assembly. I don't think that any programmer that doesn't understand assembly really understands programming. Assembly is what programming is, and high-level languages are tools to assist writing in it. If you don't know assembly, than a core part of understanding your program is reduced to trusting a mysterious black-box process. '...And then something happens which I don't know for exact reason for, but it usually seems to work this way".

      It's like being a writer but eschewing details of grammar and spelling, or being an electrician without knowing ohm's law.

    37. Re:Kids these days... by Anonymous Coward · · Score: 0

      I learnt x86 assembly as my first programming language in 1990s...

    38. Re:Kids these days... by Anonymous Coward · · Score: 0

      I wish I had mod points for you... kids these days think they know how computers work when all they do is drag and drop and call that programming!

      just for fun: empty the bit bucket into a coworker's gloves... the guys that worked for me did that one night and I was picking bits out of the rabbit fur lining for weeks afterwards. That's a practical joke that only a real computer geek can pull off!
      --
      Steve (AC because I've never bothered to sign up after all these years)

    39. Re: Kids these days... by gwjgwj · · Score: 1

      So you mean all the compiler writers are above 45?

    40. Re:Kids these days... by JustNiz · · Score: 1

      >> CALL stores a return address on the stack, which is not needed in tail-end recursion.

      Err whut? Sure it is. Just like with any function call, the CPU needs to know the return address. There's nothing magical about tail-end recursion, its still just a bunch of function calls (that need to return).

      >> It's just better to use jumps.
      But that doesn't give you relocatable code.

      >> Better to copy the instruction pointer into another register of the programmer's choice, then jump. ...As long as that function is guaran-freaking-teed to not recurse, use that register, or make any other function calls that behave the same way, yes you could indeed save a truly minscule amount of time. The cost of that is much inflexibility and horrible side-effects if the implementation ever gets changed by someone/something who doesn't know to not do any of the above.

    41. Re: Kids these days... by angel'o'sphere · · Score: 1

      There are not many compiler writers.

      And they write the compilers in C++ or Java. Usually using tools like ANTRL.

      Get a clue instead of nitpicking ...

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    42. Re: Kids these days... by gwjgwj · · Score: 1

      There are not many compiler writers.

      How well are they paid?

      And they write the compilers in C++ or Java. Usually using tools like ANTRL..

      You realize that there is more to a compiler than just a parser? Good luck writing a compiler without knowing the details of your target architecture and language.

    43. Re:Kids these days... by Anonymous Coward · · Score: 0

      I'm probably showing my ignorance of x86 assembly, but I think he thinks they're dumb because, if I remember my x86, CALL and RET do a lot of state saving and restoration automatically, and he's probably a pure RISC guy who would rather do the state saving manually. As for PUSH and POP, I've no idea his problems with those.

    44. Re: Kids these days... by david_thornley · · Score: 1

      You had a needle.

      I had to raise my own butterflies.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    45. Re:Kids these days... by david_thornley · · Score: 1

      "tail recursion" is a technique of making it easy to convert recursion into iteration. If the last statement in function f(x) is "return f(--x);", you're just running the function again with a different parameter, and that can trivially become a loop.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    46. Re:Kids these days... by david_thornley · · Score: 1

      There is not one language called "assembly". There is at least one* assembly language for each different processor. I've done stuff in about half a dozen. If you're doing standard software development, it's almost certain that you won't miss it. If you're doing embedded software development, odds are much better that you'll find it useful. If you're writing a compiler back end, odds are that you will want to be an expert in the target assembly language. If you're interested, you may as well learn one to get the feel. You don't have to learn to use it well.

      Also, I'm going to ask some of you to get off my lawn. When I was young, I had a TRS-80 with a Z80 processor, and I could do almost anything in Z80 assembler. I knew what the Z80 was going to do at any given time. I could figure out how long any individual operation was likely to take. More modern processors do things in a much more complicated manner, with memory speed depending on the caches and even the order of execution depending on what's going on inside the CPU. (My first experience in this was assembly for the CDC 6600.) The fundamental simplicity and ability to comprehend what the CPU is doing no longer exists for modern CPUs.

      *In some cases, I ran into different assemblers using different names for the instructions. Translating between the two was mechanical, but you couldn't use a program for one for another. Also, some assemblers had more complicated operations, which might specify where the assembled output was put, or even have macros, and those differed. In this sense, there might be several assembly languages for one CPU.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    47. Re:Kids these days... by david_thornley · · Score: 1

      Except that the i5 in my laptop is a black box, even given the assembly code. What I know is that it will be translated into some sort of RISC code inside the processor, and there will be complicated things going on with those. The results of x64 assembly still trust a mysterious black box.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    48. Re:Kids these days... by david_thornley · · Score: 1

      You can do binary search on an ordered sequence in memory, not just in a tree. It's tricky, and I've got lots of references to people not doing it right on the first try. (Knuth said it was published six years before a correct version was published.)

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    49. Re:Kids these days... by __aaclcg7560 · · Score: 1

      You can do binary search on an ordered sequence in memory, not just in a tree.

      That's the context I remembered learning binary search over a decade ago. May very well have done it on an ordered sequence. Search and sort algorithms aren't something I'll do from scratch these days. The closest I came to that recently is sorting a list of text files in numerical order, where the OS returned an ASCII sort and I needed a natural sort. The solution in Python was to copy the numerical names without the extension into a list, use sort(key=int) to sort the list, and than combine numerical names with extension to get a sorted file list.

    50. Re:Kids these days... by JustNiz · · Score: 1

      Then that isn't tail recursion. At least on my CS degree we were taught:

      Head recursion:
      f(p) { // do work here
      f(p'); }

      Tail recursion:
      f(p) { // calculate p'
      f(p'); // do work here
      }

    51. Re:Kids these days... by JustNiz · · Score: 1

      sorry slashdot annoyingly reformatted my post. Imagine the comments on their own lines, and indicating implementation to be added.

    52. Re:Kids these days... by david_thornley · · Score: 1

      Yup. In C++, the preferred technique is to write your own comparison function, which is a more general but often somewhat clunky solution.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    53. Re:Kids these days... by david_thornley · · Score: 1

      It's the tail recursion I learned about, primarily as applied to Lisp and dialects.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    54. Re: Kids these days... by angel'o'sphere · · Score: 1

      We don't need to argue about obvious stuff.

      My point was that the GP is grossly overrating how useful it is to learn an assembly language.

      For "ordinary" programming it is completely pointless.

      It would e.g. make more sense to learn JavaScript to remote control the Eclipse (Code Composer Studio) to use the debugger to download code via an Lauerbach "Emulator" on a target device and run it and then pick up specific memory locations to run "tests".

      Or to learn LISP to automate tasks in Emacs etc. p.p.

      As an intellectual exercise learning assembly might be "fun". But assembly is a quite simple concept.

      To be a compiler writer, simply learning assembly is not enough. Hence again: it is quite pointless to "just learn assembly for fun". to be a compiler writer you need to be an _EXPERT_

      Of course it is not pointless to "do something for fun", but claiming it has any particular value above "fun" is simply wrong, unless you dig deep enough into it to become an expert.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  3. Actually what the guy wrote was by Anonymous Coward · · Score: 1

    C++11 and C++14 added some nifty utility features which make the language worth considering as a replacement for C, even if you have no use for writing your own classes or complex templates (the latter being the usual reason why people would use C++).

    1. Re:Actually what the guy wrote was by Dutch+Gun · · Score: 5, Insightful

      People who know and like C will continue to use it. Giant legacy projects written in C (like the Linux kernel) will continue to use C, of course. C++ 11, IMO, is not going to convince C programmers to switch. Rather, it's a love letter to existing C++ programmers due to the radical way it transformed the language.

      It's still ugly as hell, and has sharp corners that will slice your fingers and toes off if you're not careful (we ARE talking C++ here). Even so, for the first time, using just the core language and libraries (Boost doesn't count), I can completely avoid manual memory management in 99% of the cases, almost like using a garbage collector, but with the advantages of destructors for non-memory resources. Raw pointers are almost a thing of the past, except for some very rare exceptions, and move semantics means your APIs can look like you always wanted them to while still remaining efficient. It's hard to describe how different the language feels pre and post 11.

      In my opinion, C++ 11 simply makes C++ far better at creating large, high-performance libraries and applications (in my case, videogames) because of the confidence that robust ref-counted resource management gives you.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    2. Re:Actually what the guy wrote was by Anonymous Coward · · Score: 0

      Linux, a legacy project?
      I don't think that word means what you think it means. Linux is not a legacy system, and the use of C in it is not really a legacy feature either, since Linus and the current developers actually prefer C and have no wish to change to $LANGUAGE_DE_JOUR.

      That includes C++, because they simply consider C superior. That, "of course", is why they stay with it. Not necessarily because they started with it.

    3. Re:Actually what the guy wrote was by Anonymous Coward · · Score: 1

      And the C++17 and hopefully 20 bring even more goodies which make even exception avoiding code easier to write and read. One more reason to adopt C++ in the formerly C-dominated scenarios.

    4. Re:Actually what the guy wrote was by goose-incarnated · · Score: 3, Insightful

      C++11 and C++14 added some nifty utility features which make the language worth considering as a replacement for C, even if you have no use for writing your own classes or complex templates (the latter being the usual reason why people would use C++).

      I've been seeing this C++ vs C comparison for quite a while now, especially on Slashdot. The usual argument is "C++ can do everything that C can, and more, hence it is better than C".

      It's a damn stupid argument to make, and the makers should rightfully feel stupid for making it. Say "C++ can do everything C can, and more" is just a different way of saying "C++ has all the gotchas of C, AND MORE".

      We write the code to be read by humans, hence anything that adds to the errors made while reading is a *bad* thing, not a good thing. It's fine you add new cognitive traps as long as you are removing existing ones!

      When I need a language that is higher level than C, I do not reach for C++ - the alternatives are better. When I don't need anything better than C I use C.

      Frankly, I cannot think of a situation in which the lack of features in C cause me to reach for C++. When I want those features I'd reach for Java instead and code the performance critical stuff in C anyway.

      The repeated comparisons showing C++ to be a better C is stupid because C++ has all the traps that C has, and adds a whole lot more. When I need the features offered by C++ I can use Java[1] and avoid the pitfalls of C *and* C++.

      [1] Depending on circumstances, I'd use Java for large-team dev, Lisp when I'm solving problems solo (hobbying), Tcl+Tk or Python+Tk when I'm doing a once-off make-my-life-simpler GUI script. Mostly I use bash. For daily dev as an embedded guy in safety-critical environments I use C.

      I probably won't change to C++ for this case, as having the ability to look at a code snippet in isolation and know exactly what assembly will be generated is an advantage.

      --
      I'm a minority race. Save your vitriol for white people.
    5. Re:Actually what the guy wrote was by Hognoxious · · Score: 1

      I agree. Windows 7 is vastly superior.

      It's a throwback to the early 2000s without support for modern hardware support.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    6. Re:Actually what the guy wrote was by Anonymous Coward · · Score: 0

      Oh yeah, I knew I made the right move to 'friend' you. What a great comment.

    7. Re:Actually what the guy wrote was by ChunderDownunder · · Score: 1

      Linux, a legacy project?

      Sure it is.
      Ubuntu has migrated to an NT kernel, while the commonest Linux distro, Android, is moving to Magenta.

    8. Re: Actually what the guy wrote was by Jeremi · · Score: 1

      Pretty much every listed criticism of c++ is valid, but I still prefer c++ over c for one reason: c++ has constructors and destructors, which means you can automate deallocation of resources using RIAA and smart pointers. In C you must remember to deallocate manually, and sooner or later you *will* mess it up, leaving you with a nasty memory leak or dangling-freed-pointer problem which you will spend much time tracking down and fixing.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    9. Re:Actually what the guy wrote was by Bent+Spoke · · Score: 1

      In exchange for manual memory allocation, C++ gives you automatic memory allocation: lots of it.

      When resources are scarce (eg. IOT devices) this overhead can be a show stopper.

      Something that C++ advocates seem to ignore:t there is no free lunch.

    10. Re:Actually what the guy wrote was by CSMoran · · Score: 1

      because C++ has all the traps that C has, and adds a whole lot more.

      Right, like manual memory management and ubiquitous printfs.

      --
      Every end has half a stick.
    11. Re:Actually what the guy wrote was by swillden · · Score: 4, Informative

      In exchange for manual memory allocation, C++ gives you automatic memory allocation: lots of it.

      Nonsense. You don't get memory allocation unless you ask for it.

      When resources are scarce (eg. IOT devices) this overhead can be a show stopper.

      You're misinformed. With C++11 move semantics, you can have both safe, automatic ownership management, and no unnecessary dynamic allocation. Most of my work is done in a very constrained environment, where I have only a handful of pages of heap... or in some cases none at all. C++ is awesome for such environments.

      Something that C++ advocates seem to ignore there is no free lunch.

      No one is claiming that there is. What there is, is the opportunity to delegate tedious and error-prone due diligence that C programmers have to do themselves to the compiler. For example, you know all those functions that have comments describing whether the returned data structure's contents are owned by the caller or the library? In C++ you can write the function so that it's impossible for the caller to avoid taking ownership when that's what you want, or so that it's impossible for the caller to believe it has ownership when the library is retaining it. If the caller gets it wrong, the compiler will flag the error. That's one example, there are many, many more. C++ enables you to have buffers and strings that do automatic bounds checking... or even to write code such that potential bounds violations are flagged by the compiler, making run-times bounds checks provably unnecessary.

      There's no magic here, just language constructs that allow you to accurately specify the semantics you want, which the compiler can enforce.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    12. Re:Actually what the guy wrote was by csmithers · · Score: 0

      Ah, no. Case in point. The Windows file system vs the Linux file system. The Windows file system normally requires de-fragmentation, whereas the Linux file system normally does not. Why ? Because the Windows engineers placed new files directly after older ones. When the older files grew, they got extra space by fragmenting. The Linux engineers (actually Unix engineers) placed files scattered all over the disk. When they grew, there was space for growth.

    13. Re:Actually what the guy wrote was by csmithers · · Score: 1

      Also, did you know that Linux in some form powers 99.99 % of the super computers in the world. Plus Android. Plus most of the web servers in the world. What does Windows power ? Desktops and a few web servers. I agree that Windows is a nice looking front end. But anything mission critical I'd use Unix or Linux (maybe BSD too). Not Windows.

    14. Re: Actually what the guy wrote was by Tough+Love · · Score: 2

      C++ meets or beats C in all but a very few respects. Designated initializers is a really painful and stupidly short sighted omission. C++ has a wealth, even a surplus (see "most vexing parse") of initialization mechanisms, but none of them can do what design initializers do. Unfortunately, when converting C code to C++, this frequently results in maintainability regresses as code has to be converted to rely more on positional parameters... which you hope you have correct, but you don't always, and you hope the order of members never change, but it does.

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    15. Re:Actually what the guy wrote was by Anonymous Coward · · Score: 0

      > What does Windows power ? Desktops and a few web servers.

      Also Navy ships.

    16. Re:Actually what the guy wrote was by angel'o'sphere · · Score: 1

      The repeated comparisons showing C++ to be a better C is stupid because C++ has all the traps that C has, and adds a whole lot more.
      If that is your opinion, you don't know much about C++ and should consider to use it more, e.g. instead of Java.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    17. Re:Actually what the guy wrote was by goose-incarnated · · Score: 1

      The repeated comparisons showing C++ to be a better C is stupid because C++ has all the traps that C has, and adds a whole lot more.
      If that is your opinion, you don't know much about C++ and should consider to use it more, e.g. instead of Java.

      C++ includes all the traps that C has, and adds a whole lot more. That is not my opinion, it is a measurable and countable fact.

      --
      I'm a minority race. Save your vitriol for white people.
    18. Re:Actually what the guy wrote was by angel'o'sphere · · Score: 1

      C++ includes all the traps that C has, and adds a whole lot more. That is not my opinion, it is a measurable and countable fact.
      If that is so, then you are writing C and using a C++ compiler to compile it.

      Learn to use your tool properly and do C++ instead.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    19. Re:Actually what the guy wrote was by Pseudonym · · Score: 1

      And the C++17 and hopefully 20 bring even more goodies which make even exception avoiding code easier to write and read.

      This is a nice way of saying that the main job of each new C++ standard is to fix the glaring usability problems introduced in the previous standard.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    20. Re:Actually what the guy wrote was by Anonymous Coward · · Score: 0

      "Legacy" doesn't mean a system is not used, nor maintained, nor even actively developed. It simply means it builds on top of technology which is now considered obsolete, such as the C programming language (and especially the non-standard GNU dialect of the C programming language - Linux uses a *lot* of non-standard GNU extensions - and gcc most definitely is legacy now, so clang has to emulate them: you know you've got an important legacy system on your hands when modern systems need to emulate their weird non-standard behaviours).

      Linux isn't the only current OS to be written in C, nor did it invent the "we will stick with C thanks" mantra. Arguably most/all operating system kernels are "legacy code". This situation being vastly preferable to the slow non-functional kernels that have been tried in other languages from time to time. "Legacy" is not really a pejorative in that sense.

    21. Re:Actually what the guy wrote was by Anonymous Coward · · Score: 0

      You have clearly read nothing on the subject of the design of the C++ programming language, and very little on its practical usage. One of the overriding design principles in the language is that if it isn't free you don't have to use it.

      Ignorance of C++ is not a good reason to stick with the insecure clusterfuck that is C, and that goes treble if you're working in IoT. Unless you're that developer I keep hearing about that never puts accidental bugs in code, of course. Otherwise I guess your marketing material can be like "It's insecure as fuck but at least it runs fast".

    22. Re:Actually what the guy wrote was by david_thornley · · Score: 1

      Or you could learn C++ and how to use it. Well-written C++ avoids a lot of C gotchas. (By well-written, I'm not saying written by good C++ coders, but rather adhering to a style guide that can easily be checked in code review.)

      C suffers from buffer overflows. Use C++ strings and containers and avoid all that.

      C suffers from memory management problems, and C programs that use dynamic allocation typically lose track of memory or get obscure bugs. Use C++ smart pointers instead.

      Large C functions often need cleanup code that can get out of sync with the main body of the functions. (Large functions are often necessary, or at least clearer than lots of little functions.) C++ destructors can handle a lot of that.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    23. Re:Actually what the guy wrote was by goose-incarnated · · Score: 1

      Or you could learn C++ and how to use it. Well-written C++ avoids a lot of C gotchas. (By well-written, I'm not saying written by good C++ coders, but rather adhering to a style guide that can easily be checked in code review.)

      Code reviews do not remove traps in the language. When we tell people that PHP is crap we giggle when they reply that they only use a subset of PHP that is not crap, and enforce that subset by code-reviews.

      By definition alone, C++ has all the traps and UB of C, and adds a whole lot more.

      --
      I'm a minority race. Save your vitriol for white people.
    24. Re:Actually what the guy wrote was by david_thornley · · Score: 1

      Code review makes sure people are programming according to a certain style, which can be done to avoid traps. If someone tried using a C-style array, or wrote "free" or "delete" in the main code, we'd spot it and not approve it. That removes some of the traps.

      Code reviews won't necessarily catch traps that aren't a matter of style, but they can force a style that will prevent some of them.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  4. Half right by Zero__Kelvin · · Score: 1

    Well C++ IS better than C. Of course C is also better than C++. As always, use the right tool for the right job.

    --
    Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    1. Re:Half right by phantomfive · · Score: 1

      Maybe. This article doesn't make a very good case for it, though. He's claiming the C++ syntax for doing a callback is easier than the C syntax. His example syntax doesn't look much better, though.

      --
      "First they came for the slanderers and i said nothing."
    2. Re:Half right by Dutch+Gun · · Score: 1

      It's typically not about being *easier* in C++. It's more often about being *safer* while not giving up natively compiled performance. Anyone looking for "easy" and is using C++ is missing the boat.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    3. Re:Half right by phantomfive · · Score: 1

      C++ isn't safer than C, it gives you a bazooka to blow your foot off.

      --
      "First they came for the slanderers and i said nothing."
    4. Re:Half right by Brian+Feldman · · Score: 1

      If you avoid static_cast/traditional (C_casts *), and use -Wall -Werror, then C++ is really quite a lot safer.

      --
      Brian Fundakowski Feldman
    5. Re:Half right by phantomfive · · Score: 1

      And if you use exceptions correctly. And make sure not to use dangerous features. And be careful about operator overloading. Nah, C++ isn't safer than C, it has all the dangers of C plus some more. If you use a good string library and a good buffer library, than most of the dangers of C are gone.

      --
      "First they came for the slanderers and i said nothing."
    6. Re:Half right by Anonymous Coward · · Score: 1

      Both languages give you a bazooka, but C++'s bazooka has compiler-enforced safety if you bother to RTFM and follow the best practices. Doing the same tasks in C will not give you compiler-enforced safety, and you will blow yourself to bits.

    7. Re:Half right by phantomfive · · Score: 1

      but C++'s bazooka has compiler-enforced safety if you bother to RTFM and follow the best practices.

      Lies. There's no such thing as C++ best practices. There's a subset of C++ that your team chose to you. And I seriously doubt you've read the manual.

      --
      "First they came for the slanderers and i said nothing."
    8. Re:Half right by Anonymous Coward · · Score: 0

      or, you could just fucking use C++ and code it like it's C until you run into a situation in your code where C++ offers an advantage, and then use C++ (just be prepared to be laughed at when new people join your team and you have to explain that this is how things are done). if you're going to reply that C++ will never offer any advantage over C, then that just tells me you're either incompetent or lazy; in which case, who the fuck is letting you code something in C?? if you're going to reply that your C++ code would be fine, but other devs will write shitty C++ code that's full of bugs, hard to reason about, etc ... you may be right ... but that's what code reviews are for (also, maybe reevaluate your interview process?). sometimes safety just comes from simpler code that's easier to reason about. it might surprise you, but not every bug is because of a buffer overflow. many (not all) things can be written in simpler ways in C++ than C, while still retaining the performance and other benefits of C, along with being supported by many of the same tools (gdb, valgrind/callgrind/etc, static analyzers, etc) -- this is a large reason why people use C++. if it weren't for this fact, many of these people would have moved on to other languages by now, and we wouldn't be having this discussion.

      seriously, when you have a constant stream of people (as has been the case for many years now) saying that there are good reasons to consider using C++ in place of C, especially because of the progress made in C++11/14 specifically, you might want to at least stop and consider what you're not seeing that they are, or maybe what's changed since the last time you used C++ that may make it a reasonable choice now (C++ was god awful 10+ years ago sure, but that's just not the case anymore). it's highly unlikely that they're all wrong and you're completely right. it's likely somewhere in between...

      shit, with the rate that C++ is improving, and the recent'ish development of hipster languages like rust (which comes with some amount of built-in guarantees for being free of certain classes of bugs)... for your own job security you really might want to consider learning something other than C to a degree where you can actually use it in place of C. it's really for your own good. you can argue all you want here, but it's not going to change the general direction of software development.

    9. Re:Half right by phantomfive · · Score: 1

      I know more languages than you have years in your life, mate. I don't care if there are a "constant string of people telling me" anything. At a certain point, you have enough experience to make your own judgements.

      Apparently you haven't made it there yet.

      --
      "First they came for the slanderers and i said nothing."
    10. Re:Half right by TheRaven64 · · Score: 1

      There's no such thing as C++ best practices

      Yes there is. It's called the C++ Core Guidelines and is a proposed part of the upcoming standard. It defines a subset of C++ and an extension library and makes the language more amenable to static checking. Some simple rules of thumb from the standard go a long way: for example, never use new or delete outside of the standard library implementation, always use make_shared or make_unique and always use the returned shared_ptr or unique_ptr instead of a raw pointer. That alone is enough to fix the vast majority of C/C++ memory management bugs.

      --
      I am TheRaven on Soylent News
    11. Re:Half right by david_thornley · · Score: 1

      And, no matter how much you learn, some of your own judgments will be wrong. C++ is safer than C. You can deliberately write C++ to be as unsafe, but when used in a manner that's fairly easy to learn and is easily checked by code reviews it is safer.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    12. Re:Half right by david_thornley · · Score: 1

      Idiocy (to conform with your desire to start a post with an insult). There are C++ best practices. There's lots of books on them that more or less agree, and do agree on certain important points. (Example, use vectors instead of C-style arrays.) Also, if you think the ARM is of anything other than historical interest today, you don't know C++. The ARM was the base document for the 1998 Standard, which improved on it in important ways, and the 2011 and 2014 Standards improved on the 1998 Standard in important ways.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    13. Re:Half right by phantomfive · · Score: 1

      Your comment would have been useful if it had an example, but instead it's just an indication of your own preference. Which is fine. Some HTML/Javascript programmers don't know how to organize their own code, so they prefer React because it helps them. That is fine for them.

      --
      "First they came for the slanderers and i said nothing."
    14. Re:Half right by phantomfive · · Score: 1

      Yes there is. It's called the C++ Core Guidelines and is a proposed part of the upcoming standard.

      That's good to know, thanks

      --
      "First they came for the slanderers and i said nothing."
    15. Re:Half right by phantomfive · · Score: 1

      Also, if you think the ARM is of anything other than historical interest today,

      No one said that. The question was whether you'd read it or not.

      --
      "First they came for the slanderers and i said nothing."
    16. Re:Half right by david_thornley · · Score: 1

      Elsewhere in this thread, I've mentioned memory management (using C++ smart pointers) and buffer overflows (mentioning C++ vectors and strings). If you consistently use these, you will avoid some of the big problems people have with C, and your programs will be safer.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    17. Re:Half right by phantomfive · · Score: 1

      Those are good supporting reasons.
      I disagree, of course, because I think you can use techniques to get the same benefits in C, but you know, we're probably never going to come to full agreement. Exchange of ideas is good enough. :)

      --
      "First they came for the slanderers and i said nothing."
  5. They both suck! by david.emery · · Score: 2

    At some point, the developer community will wake up to just how evil C -syntax- is, and how much it has contributed to bugs and security holes.

    1. Re:They both suck! by david.emery · · Score: 3, Funny

      On the other hand, monkeys prefer C, because the programs they generate by jumping on the keyboard have the best chance to compile.

    2. Re:They both suck! by phantomfive · · Score: 4, Interesting

      What particularly don't you like about C syntax? I've always thought that the main security problem with C are caused by the lack of a decent buffer processing library, and a lousy string processing library. Fix those two things (and any person can do it in their own code!) and you've fixed the vast majority of C security bugs.

      --
      "First they came for the slanderers and i said nothing."
    3. Re:They both suck! by david.emery · · Score: 1

      "=" vs "==", the presence or absence of commas or semicolons that substantially change meaning, the mess that is #include in large systems...

      Just look at any "obfusticated C" contest entry for egregious examples!

      Sure, you can learn and code around them. But at best that's a risk. And we have plenty of examples where those risks have made it to deployed systems. What was the Apple bug on certificates where a semicolon introduced a significant bug in certificate validation that was there for years?

    4. Re:They both suck! by phantomfive · · Score: 1

      "=" vs "==", the presence or absence of commas or semicolons that substantially change meaning, the mess that is #include in large systems...

      Those types of bugs are very rare, and #include was solved long ago with #IFNDEF _HEADER_NAME....

      --
      "First they came for the slanderers and i said nothing."
    5. Re:They both suck! by BarbaraHudson · · Score: 2

      On the other hand, monkeys prefer C, because the programs they generate by jumping on the keyboard have the best chance to compile.

      I think you spelled perl wrong again :-) (hey - it's a feature)

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    6. Re:They both suck! by david.emery · · Score: 1

      But PERL is explicitly built on C syntax. QED!

    7. Re:They both suck! by religionofpeas · · Score: 2

      A good compiler will warn you if you use '=' in a test.

    8. Re:They both suck! by BarbaraHudson · · Score: 1

      Good April Foo;s joke - some n00bs might even believe it :-)

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    9. Re:They both suck! by Anonymous Coward · · Score: 0

      The problem is C semantics, not C syntax.

    10. Re:They both suck! by ShanghaiBill · · Score: 1

      A good compiler will warn you if you use '=' in a test.

      ... and a better compile will allow you to make it a compile-time fatal error.
      Like this:

      gcc -O2 -Wall -Wextra -Werror foo.c

    11. Re:They both suck! by Anonymous Coward · · Score: 0

      glib does a lot of what you are asking.

    12. Re: They both suck! by Anonymous Coward · · Score: 0

      And C++ semantics are NaN% more fucked up.

      This is what all the "new C" designers fail to get.

      C would be fine with minor fixes to the semantics and proper codification of all the low level features that have been strapped on through preprocessor magic. You can even give the language a new name!

      Instead, what they do is they throw the baby away with the bath water and invent a hole new set of fucked-up semantics.

      Some of them are decent taken individually, but they just can't replace C.

      If I need to think about what nightmarish modifications the compiler will make to my code, I don't care if they are "safe" which in C++'s case they are most certainly not.

      Come to think of it, if only C compilers were written by C programmers we wouldn't need a new C at all as reasonable code wouldn't invoke Chthulu in hopes that he changes the outcome of the time(1) command.

    13. Re:They both suck! by csmithers · · Score: 1

      Well, with great power comes great responsibility :)

    14. Re:They both suck! by Tough+Love · · Score: 1

      What particularly don't you like about C syntax?

      Function declaration syntax is demented, just to pull one thing off the top of a huge stack. Ever tried declaring an array of functions?

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    15. Re:They both suck! by Anonymous Coward · · Score: 0

      most software "security holes" is the result of the hole between the designer's/implementer's ears

    16. Re:They both suck! by phantomfive · · Score: 1

      Ever tried declaring an array of functions?

      Yeah but it turned out to not be a good idea, and not because of the syntax.

      --
      "First they came for the slanderers and i said nothing."
    17. Re:They both suck! by djbckr · · Score: 1

      I learned to program using C about 20 years ago. I know about a dozen languages fluently now. C is my least favorite (next to PHP).

    18. Re:They both suck! by Anonymous Coward · · Score: 0

      The compile time problems were not.

    19. Re:They both suck! by Anonymous Coward · · Score: 0

      What about function pointers.. Are they for real? This is not a serious question, I just find the notion to be fairly nonsensical in the first place. Although, maybe I can think of it as similar to the target line number for a "GOSUB".

      Seeing the syntax I thought, wtf, does the C language accidentally support them?, I had the impression someone clever discovered the function pointer while trying to do smart, hackish things with stars and parentheses while writing C code. Eventually, instead of the program doing random things, segmentation faults or failing to compile, he/she found out he had invented a "function pointer" and could create them at will to do vile things with them.

    20. Re:They both suck! by Tough+Love · · Score: 1

      If you don't get the concept of function pointers then sad for you and hopefully this isn't your day job.

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    21. Re:They both suck! by Anonymous Coward · · Score: 0

      #include was solved long ago with #IFNDEF _HEADER_NAME....

      Yes, but that's a good example of what bothers me. That does work, and fixes the problem, but it's just clunky... nearly a hack. When you bolt on changes and fixes to an established language like that, it's not intuitive or elegant. It's PHP territory. The language needs to be redesigned with such feature included from the outset in a way that makes sense.

      C++ is hideously complex not because of its featureset, but because of the way that featureset was pasted on to C (and to previous versions of C++) while trying to keep backwards compatibility.

    22. Re:They both suck! by spongman · · Score: 1

      do yourself a favor and look at the C grammar section that deals with types (including function declarations), consider the constraints that a LALR grammar places on what you can do, then it'll all make perfect sense.

    23. Re:They both suck! by Anonymous Coward · · Score: 0

      That has precisely nothing to do with syntax. Syntax doesn't cause C's pointer and memory models.

    24. Re:They both suck! by Anonymous Coward · · Score: 0

      The whole concept of delegates (or rather, the things you have to do to implement them) in c and c++ is obscene.

    25. Re:They both suck! by david_thornley · · Score: 1

      If you know C, bash, some compiler theory, and various Unix utilities, Perl still looks like the syntax depended on what Larry Wall had for breakfast when he designed that part.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    26. Re:They both suck! by david_thornley · · Score: 1

      Ever tried declaring an array of functions?

      I normally use two lines, one creating a typedef (new name) for the function pointer, and then an array of those. I try to keep the syntax not looking too ugly. (There's no way of making some of this not look ugly.)

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    27. Re:They both suck! by david_thornley · · Score: 1

      Yeah, the syntax kinda sucks independently of the semantic problems.

      C was designed to do anything, including systems software, and it was necessary to allow C-style pointers and memory models. C++ provides safe handles for sharp tools.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    28. Re:They both suck! by Anonymous Coward · · Score: 0

      // string processing library
      #include <string>
      // buffer processing library
      #include <vector>


      Yes. C++ really is better than C.

    29. Re:They both suck! by Tough+Love · · Score: 1

      How they got there makes perfect sense. That K&R chose to double down on such a messed up plan is demented. There are better alternatives grammatically, that are equivalently powerful and work just as well or better with LALR parsers.

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    30. Re:They both suck! by Tough+Love · · Score: 1

      And please don't flatter yourself that you are the only one to have read the C grammar. I hope you also read your dragon book.

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    31. Re:They both suck! by Anonymous Coward · · Score: 0

      Or its lack of memory model. Heck, C++ got its first definition at the C++11!

  6. I use awk by jlowery · · Score: 5, Funny

    enough sed. don't bash me.

    --
    If you post it, they will read.
    1. Re:I use awk by Anonymous Coward · · Score: 1

      You're a uniq head case.

  7. This just in! by skam240 · · Score: 1

    This just in, slashdot diminishes usefulness of site for a day in same tired April Fools joke they do every year!

    One editor was reported saying, "Yes, we've been beating this horse for twenty years now but rumors of the horse's demise many years prior have been grossly exadurated."

    --
    I ignore Anonymous Coward posts. If you want to discuss something, that's awesome. Log in.
    1. Re:This just in! by Areyoukiddingme · · Score: 1

      One editor was reported saying, "Yes, we've been beating this horse for twenty years now but rumors of the horse's demise many years prior have been grossly exadurated."

      Yep, that looks like the spelling of Slashdot editors. Bravo.

  8. Better by Anonymous Coward · · Score: 0

    I agree. Go is Better.

    1. Re:Better by phantomfive · · Score: 1

      Golang.......nice language, but it has some braindead parts. Instead of using make(), they could have just used new like every other datatype. No need for a specialized function. map.New() would have been completely acceptable, and more consistent.

      The keyboard input is braindead. There are a lot of functions, but they combine the archaic-ness of C with the verbosity of Java. fmt.Scanln() doesn't actually read a line, it reads a word (delimited by spaces). Reader.ReadString('\n') is recommended in the documentation, but that is probably useless because it doesn't read the final line if it ends with EOF instead of a newline. I've been trying to think of a situation where that is even useful.

      Concurrency in Go is nice, but go routines are just threads. Message queues are a nice way to solve some of the problems of shared memory, but you have to think about deadlocks every time you use one because they are blocking.

      --
      "First they came for the slanderers and i said nothing."
    2. Re: Better by Anonymous Coward · · Score: 0

      make() works perfectly, in my keyboard is no EOF key i could hit accidentially and go routines are NOT just Threads. Which makes it so perfect

    3. Re: Better by phantomfive · · Score: 1

      in my keyboard is no EOF key i could hit accidentially

      Try using redirect from a file.

      --
      "First they came for the slanderers and i said nothing."
  9. OMG by Anonymous Coward · · Score: 0

    Really ? Wow just wow. You mean to tell me out of 6 billion people one of them thinks C is better than c++? No shit, in other news some people like Java over c++, some people like Microsoft over Apple, and yet others even use Snapchat instead of Facebook.

    1. Re: OMG by Anonymous Coward · · Score: 0

      Hello sir, I'm your calendar, pls look at me *today*.

  10. Rubbish in Cans by prefec2 · · Score: 1

    He favors automatic memory cleanup an trashes C for using marcos for it (which is indeed stupid) and favors destructors . But in that case he could just favor C# or Java. Both do the memory cleanup for you.

    Also his examples look very cluttered. It looks more like a C++ lover who try to bash C.

  11. If you want to fix C, don't use C++... by __aaclcg7560 · · Score: 1

    [...] "adopting a subset of C to smooth out C's rough edges" [...]

    FTFY — A little trick I picked up from John Carmack.

  12. Fucking Awful Headline by Anonymous Coward · · Score: 1

    This is a fucking awful headline, about as credible as "Anonymous Coward Just Said Slashdot Fucking Sucks." Why should I give a shit what someone on Medium has to say? If I tweet that Perl sucks, will you post a story about that, too? The editors are worse than ever.

  13. STL != C++ by JustNiz · · Score: 2

    Seems like his gripe is actually with STL and possibly curl's interface, not C++ per se.

    I like C++ (classes, exceptions etc) but generally avoid using STL except possibly for basic things like cout, strings and vectors. STL code becomes unreadable FAST, and quickly turns a simple problem into a giant pain in the ass, especially when debugging.

    1. Re:STL != C++ by angel'o'sphere · · Score: 1

      STL code becomes unreadable FAST
      Hint: learn about the keyword "typedef".

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    2. Re:STL != C++ by JustNiz · · Score: 1

      I've been programming in C/C++ for over 35 years. I'm fairly sure I already know about typdef.
      And no, just adding yet more layers of abstraction isn't a good solution either.

    3. Re:STL != C++ by angel'o'sphere · · Score: 1

      If you know about typedefs then using the STL should not be "verbose" or any problem at all :D

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    4. Re:STL != C++ by JustNiz · · Score: 1

      Who said anything about verbosity being a problem?
      Using STL fundamentally causes multiple problems. Have you ever tried debugging it for example?

    5. Re:STL != C++ by angel'o'sphere · · Score: 1

      Using STL fundamentally causes multiple problems. Have you ever tried debugging it for example?
      Yes? What is your point? Why you are debugging "the STL" is beyond me anyway. You should debug you own code that is using it.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    6. Re:STL != C++ by JustNiz · · Score: 1

      dont be a dumbass. I'm OBVIOUSLY not talking about debugging the STL itself, I mean if a call to it is wrong somehow, it blows up with an impossible stack trace to follow.

    7. Re:STL != C++ by angel'o'sphere · · Score: 1

      Then learn how to use debugger.

      You put a breakpoint at the line in your stack trace where your code is about to call the STL.

      Pretty simple.

      Bonus points if you are able to read the manual of your debugger/IDE and set a "conditional breakpoint".

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  14. I know it's April fools, but still ... by BarbaraHudson · · Score: 2
    From the article:

    Set the handle to send a pointer to the struct. The handle expects a void *, so there’s an implicit cast from the struct’s pointer type to, effectively, nothing.

    A void pointer is NOT a pointer to nothing. At least it better not be. :-)

    --
    "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
  15. Undefined behavior by Immerman · · Score: 5, Informative

    Not quite, it is in fact undefined.

    C++ is the post-increment operator, it increments the variable, but then returns the original value. Therefore, since C started out as 0x11, C++ will evaluate to 0x11 while modifying C to be 0x12 as a aside effect.

    Therefore, if you were > optimistic you could try to claim that "C++ < C", expecting the operations to be evaluated left-to-right and thus be evaluated as "0x11 < 0x12". However, C++ doesn't specify the evaluation order of operators, which means that "C" might end up being evaluated before "C++", in which case the comparison would be evaluated as "0x11 < 0x11" instead. The only thing you can be sure of is that C++ will NOT be greater than C.

    Basically, as a rule of thumb you should never modify a variable within a line of code if the value of that variable will matter anywhere else within that same line. http://en.cppreference.com/w/c... - discusses undefined behavior halfway down the page.

    --
    --- Most topics have many sides worth arguing, allow me to take one opposite you.
    1. Re:Undefined behavior by csmithers · · Score: 1

      I think you're actually comparing C to itself. If I use a simpler example, with a pre-increment even, you still don't get the first branch : #include int main(int argc, char **argv) { int i = 1; if ( ++i > i ) printf("++i is greater than i\n"); else printf("++i is not greater than i\n"); }

    2. Re:Undefined behavior by csmithers · · Score: 1

      And you could do : #include int main(int argc, char **argv) { int i = 1; if (++i > i) printf("++i is greater than i\n"); else if ( ++i == i ) printf("++i == i\n"); }

    3. Re: Undefined behavior by hackwrench · · Score: 1

      I would have expected the variable increment to take place after the expression is evaluated for a result.

    4. Re: Undefined behavior by csmithers · · Score: 1

      Post increment or pre increment, you're still comparing C to itself.

    5. Re:Undefined behavior by thegarbz · · Score: 1

      So what you're saying is that not only is C++ not greater than C, but it's not even equal to it!

    6. Re:Undefined behavior by Immerman · · Score: 1

      Using preincrement doesn't fundamentally change anything - the outcome is still undefined.

      ++C would evaluate to 0x12, while C would evaluate to either 0x11 or 0x12 depending on whether it was evaluated before or after ++C.

      So ++C *might* be greater than C, depending on how the compiler sequenced it.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    7. Re: Undefined behavior by Immerman · · Score: 1

      Nope, ()++ is essentially just a function with a side effect, there's no crazy "do the actual incrementing at some other point in the code" magic going on. Consider how writing your own version for a custom data type would have to be implemented.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    8. Re: Undefined behavior by Immerman · · Score: 1

      No, you're not. Post-increment returns the *previous* value of C, while preincrement returns the new *current* value. And in either case it's undefined as to whether the increment occurs before or after the value of C has been taken for the other side of the inequality.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    9. Re: Undefined behavior by Anonymous Coward · · Score: 0

      No, it doesn't. The next sequence point is after the greater than expression is evaluated. Otherwise postfix would be the same as prefix.

    10. Re:Undefined behavior by Anonymous Coward · · Score: 0

      Wouldn't that rule of thumb make for-loops illegal?

    11. Re:Undefined behavior by Anonymous Coward · · Score: 0

      I don't get why everybody is claiming this is undefined or difficult. It isn't undefined (at least for C). ++C according to the standard means "increment, then return the value" which means any calculation will use the incremented value. C++ means "return the value, then increment it" which means that any calculation using it will always use the original value. This "which side of the '>' is evaluated first" is completely irrelevant because it will evaluate using the returned value. Which in the case of C++ will always be the original value.

      If C++ doesn't define this, well, just adopt the C standards definition. Granted in my experience, every implementation of C++ uses the C definition. The only ones that are undefined are things like 'if (++C > C++)' which is logical gibberish anyway. But even then, being undefined as to which gets evaluated first, I can tell you with certainty what the boolean outcome will be, just not the exact values being compared. Granted almost all of these cases are logical gibberish to begin with.

    12. Re:Undefined behavior by david_thornley · · Score: 1

      You're saying what might happen in practice. The Standard does not address this, so the program is not conforming C or C++, and the Standard has nothing to say about what happens. Anything is in accordance.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    13. Re:Undefined behavior by Immerman · · Score: 1

      Exactly. Which is why I'm pointing out that the behavior of such code is undefined. It's extremely unlikely that the compiler would simply do something else entirely, even though, yes, technically, it would be in accordance if it launched a word processor while reformatting the moon.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    14. Re:Undefined behavior by Immerman · · Score: 1

      Well, it is a rule of thumb, not an absolute guideline. But basically a for loop contains three lines of code that get run in a well-defined sequence:
      for( i=0;
      i < end;
      ++i)
      {...}
      Generally speaking you can consider a line of code to end at a semicolon, and that a for loop is a locality-improving shorthand for
      i=0;
      while(i < end)
      {...
      ++i;}

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    15. Re:Undefined behavior by Immerman · · Score: 1

      Nope, it's extremely important which side of the > gets evaluated first. Consider, if C starts out as 1, then
      C > ++C can mean
      1 > 2 if ++c is evaluated second, or
      2 > 2 if ++c is evaluated first
      Both are valid according to the standard, therefore the result of the comparison is undefined. And I'm pretty sure C doesn't define a definite sequence of operations either.

      Also, slight correction: C++ is "increment then return the original value, not return the value then increment - once you return a value a function can no longer do anything else.

      It's not just restricted to ++ operators either, if you call a function:
      foo( a(), b(), c() )
      The standard does not specify what order a(), b(), and c() will be called in, only that they all get called before foo(). That allows for a wide range of potential optimizations, but means that if there are side effects that mean sequence does matter, then you need to explicitly call the functions in the right order and then pass their results to foo() separately.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    16. Re: Undefined behavior by hackwrench · · Score: 1

      The thing is when do side effects happen? In order to ensure they do not disturb intended effects it would make sense to make sure they happened after all others.

    17. Re: Undefined behavior by Immerman · · Score: 1

      The side effects must happen while the function is being called. When else could they happen?
      Though I'll admit there may be details specific to the native increment operators that give the compiler additional leeway.
      For any custom type ()++ has to be implemented as:

      MyType++()
      {
      MyType oldValue = *this; //increment MyType here...
      return oldValue;
      }

      Avoiding unintended effects is the responsibility of the programmer - that's why it's called out as undefined behavior. Most of the time the sequence doesn't matter, and there's the potential for optimizations by resequencing.
      Similarly, the standard makes no guarantees as to the sequence in which A(), B() and C() are called if you call:
      foo(A(),B(),C());
      If the sequence matters, then you need to call them separately beforehand and store the returned value to pass into foo().

      Basically, you want only one side-effect per line of code, unless the sequence doesn't matter.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    18. Re: Undefined behavior by Anonymous Coward · · Score: 0

      Well, if you increment a variable, then check to see if it's greater than itself, shouldn't the answer be no ?

    19. Re: Undefined behavior by Immerman · · Score: 1

      Absolutely. But that's not what you're doing. Both in that I++ is categorically NOT equal to I (since it returns the previous value), and that you're not necessarily incrementing beforehand, but could be doing it halfway through the comparison since C++ doesn't define a specific evaluation sequence.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    20. Re: Undefined behavior by Anonymous Coward · · Score: 0

      The issue is whether it's increment-then-check or check-then-increment.

      When the definition says post-increment "adds one to the value after the variable is evaluated," does that mean the evaluation happens before the comparison, or after?

      Logic would seem to dictate that you need to evaluate both sides before you can make the comparison, but in practice you can evaluate the left hand side, increment it (because it's been evaluated) then evaluate the right hand side, then make the comparison, which will give a different result.

      That's where the ambiguity lies (over there, in a box..)

  16. I like a lot of the C++ features by Anonymous Coward · · Score: 0

    Back when I was doing my work in C, before I made the switch to C++, I developed my own set of practices that I later realized were attempts at doing what C++ did natively, including proto-classes that "isolated" variables and called member functions through a jump table (I know, I know...). So I found a lot of C++ to be pretty natural for my way of thinking. That said, C is still good, too, especially for smaller projects.

    1. Re:I like a lot of the C++ features by AaronW · · Score: 2

      I found the same thing when I was handed a large project in C++. In this case it was a very complex kernel-level OS/2 device driver. It took me a while to adjust to C++ but once I did I certainly saw the advantages.

      With C we're always reinventing the wheel and doing things the hard way. I say this as someone who works on bootloaders and has worked on a lot of device drivers and works close to the hardware. C++ requires more support than C to get basic functionality working, but once it's there a lot of code becomes simpler.

      --
      This post is encrypted twice with ROT-13. Documenting or attempting to crack this encryption is illegal.
    2. Re:I like a lot of the C++ features by Anonymous Coward · · Score: 0

      Back in the 90s, my employer sent my dev team to a one week training course in C++ taught by a guy named Arthur Riel. Arthur started the course by explaining that C++ makes it easy to execute the best practices of advanced C programmers, such as jump tables and compatible structure layouts, without a lot of the awkwardness and loss of type safety you'd have in C code.

    3. Re:I like a lot of the C++ features by lucasnate1 · · Score: 1

      C also has libraries, you know, things like glib for example.

    4. Re:I like a lot of the C++ features by TheRaven64 · · Score: 1

      That's a very good way of thinking about it. For a simple example, think about locks. In C, you must explicitly release the lock in every code path. You can make this easier by ensuring that you have a single function return, or use structured flow control and make sure that you release the lock in the same scope that you acquire it, and maybe write a static analyser checker to make sure that you did. In C++, you can simply use `std::lock_guard` and it will ensure that the lock is released even in the presence of exceptions at the correct point. If you're happy to use GNU extensions, then __attribute__((cleanup)) will do the same, but it's horribly verbose and so you must wrap it in macros.

      --
      I am TheRaven on Soylent News
  17. I started off with C by Brian+Feldman · · Score: 2

    It's my most familiar language, back from when I was learning it on the schoolbus by reading K&R. I would still never choose C over a carefully-selected subset of C++ for a new project. There is just no advantage to keeping things more primitive except when it comes to very specific environments, like traditional Unix kernels. I think templates are very useful in limited doses and far superior than macros, inheritance is somewhat useful to almost any kind of CS problem, and the STL itself is a huge boon to software reliability and interoperability.

    Of course, I also have no qualms with Java, so....

    --
    Brian Fundakowski Feldman
    1. Re: I started off with C by Anonymous Coward · · Score: 0

      It depends on what you need, but C++ has serious deficiencies that can break its neck for some uses.
      For example, before constexpr guaranteeing that some table didn't end up initialized at runtime wasn't really an option.
      Lack of designated initialized especially for arrays makes sparse lookup tables a pain and error-prone to implement.
      It also means no safe way to map enums to something else via an array, sometimes resulting in abominations line std::map being used for that.
      Also, the code compiler produce for constructors are an abomination, it contains as many move instructions as you have variables, in many cases even if you only set them all to 0.
      Comparison operators are just as bad.

  18. I worked on a C++ device driver by AaronW · · Score: 5, Interesting

    In the 1990s I worked on a complex device driver for OS/2 for ATM networking (asynchronous transfer mode). The driver was around 100K lines of C++ code however only a subset of C++ was used. Surprisingly the use of C++ worked out quite well. We had an equivalent driver for Windows NT that was written in C that was over 300K lines of code. The C++ codebase was a lot more reliable and easier to work on, despite all the work that was done to make C++ work in kernel mode under OS/2. The C++ driver actually had more functionality than the C driver and it was faster as well with a smaller binary. Also, as I said, it was a subset of C++, especially in the performance critical code. The driver in question included the entire ATM signalling stack and implemented full LAN emulation support with both Ethernet and Tokenring plus it could emulate multiple networks (ELANs, equivalent to VLANs) simultaneously. When I implemented multiple ELAN support I was afraid it was going to be a nightmare, but due to the way it was architected in C++ I ended up only having to change a few lines of code, changing a pointer to the LANE class to an array of pointers.

    For the signalling stack and ILMI C++ worked out especially well due to the event and message based nature of it and the various state machines. For LAN emulation it made it easy to support both Ethernet and Tokenring by having a few virtual functions in the main LANE class.

    There was no exception handling support and none of the more complex C++ features were not used. It used templates but that was also somewhat limited.

    Having destructors was also quite nice, making it easy to clean up resources.

    Despite being C++, debugging wasn't too bad though at the time the OS/2 kernel debugger basically ran at the assembly level.

    If the infrastructure is in place I can certainly see using C++ in the kernel and device drivers.

    --
    This post is encrypted twice with ROT-13. Documenting or attempting to crack this encryption is illegal.
    1. Re:I worked on a C++ device driver by slashdot_commentator · · Score: 1

      If the infrastructure is in place I can certainly see using C++ in the kernel and device drivers.

      Its already been done. At least one of the L4 microkernels (Fiasco?) is implemented in C++. You don't lose code efficiency doing it in C++, if you know what you're doing in C++.

      --
      There is no America. There is no democracy. There is only IBM and AT&T and DuPont, Dow, General Electric, and Exxon
    2. Re:I worked on a C++ device driver by Anonymous Coward · · Score: 0

      That's the main problem with C++. It is incredibly hard to know what is happening behind the scenes (will this object allocate memory or not?), so one has to be very careful in performance-critical parts. And then using a C++ subset you know performs well, or just programming in C is the way to go.

      If you just want a program that runs well and you don't care about the last 30% of performance, you don't need to know as many details of C++, just know what you're doing in general w.r.t. abstract data types. C++ is great at this. Not that great at portability between compilers though, which makes it annoying to use if you want to produce static libraries.

    3. Re:I worked on a C++ device driver by slashdot_commentator · · Score: 2

      That's the main problem with C++. It is incredibly hard to know what is happening behind the scenes (will this object allocate memory or not?), so one has to be very careful in performance-critical parts.

      Its more difficult to know what's happening below the source code level, because C++ is conceptually more abstract than C. But ANSI C is an abstraction as well. Its not like the days of K&R C, where you knew what the parameter passing code looked like in assembler. And C++ being a higher level of code abstraction than C is a good thing. If you know how to code C++, you avoid all the problems with loose pointers, and memory leaks, and human implementation errors prevalent with C.

      (will this object allocate memory or not?)

      That is a horrible example. You always should know when an object allocates memory, because C++ doesn't intrinsically do automatic memory allocation and garbage collection. You have to write that in with constructors and destructors. Yes, the programmer may not do that properly, but it shouldn't be a problem to debug when it occurs.

      And then using a C++ subset you know performs well, or just programming in C is the way to go.

      If you're a mediocre programmer, you will be more likely to produce a working program in C, but it will be also more likely to contain bugs. That does not mean C is a "better" language for real-time system code than C++.

      If you just want a program that runs well and you don't care about the last 30% of performance, you don't need to know as many details of C++,

      Again, that is part of the B.S. about C++ being less efficient than C. I already brought up the example of the L4 microkernel. Many windowing and graphics libraries are written in C++, and they don't suffer from a 30% inefficiency compared to a library written in C. If you don't have a mastery of C++, then you're not going to write efficient code in C++; that is true for any language on that level.

      --
      There is no America. There is no democracy. There is only IBM and AT&T and DuPont, Dow, General Electric, and Exxon
    4. Re:I worked on a C++ device driver by AaronW · · Score: 1

      Actually it is fairly clear what happens behind the scenes if you know what you are doing. As I said, I had to debug at the assembly level so I got to see first hand exactly what the compiler did. It didn't take me long to understand how C++ code compiled. I also did not see a performance hit. The this pointer basically behaves like passing a pointer to a data structure containing all the data the function needs to work with as is common in C.

      There is no inherent reason for C++ code to be any slower than C code.

      If you are inexperienced with C++ I could see your complaint about not knowing what's going on behind the scenes.

      Also, portability has greatly improved with C++. I have regularly updated C++ libraries without the need to recompile applications.

      --
      This post is encrypted twice with ROT-13. Documenting or attempting to crack this encryption is illegal.
    5. Re:I worked on a C++ device driver by TheRaven64 · · Score: 1

      It's a more valid criticism of C++ to say that it is too explicit what is going on behind the scenes. For example, C++ provides virtual functions and templates as completely orthogonal features. One performs run-time specialisation, the other compile-time specialisation. You know that using one will increase dynamic instruction count, using the other will increase i-cache usage. In a language like Lisp, it's trivial to switch between the two (and you can't tell which you're using unless you read the definition of the code). In a language like Smalltalk, Java or C#, the abstract machine only provides run-time specialisation, but the implementation is free to prefer compile-time specialisation if profiling indicates that it would be faster. In C++, you make this decision early and then you pay for it if you made the wrong choice.

      --
      I am TheRaven on Soylent News
  19. Online by meadow · · Score: 1

    Online CS courses at colleges kick ass. They are the wave of the future.

  20. Both have pros and cons by Anonymous Coward · · Score: 0

    I like the transparency of c nothing is hidden or implied it makes debugging simpler. And if your writing singletons All day every day, why use anything else. However if you heavily code data driven apps then why not use c++ too.

  21. re by JohnVanVliet · · Score: 1

    well there is a ++ in the name so.....

    --
    "I don't pitch OpenSUSE Linux to my friends, i let Microsoft do it for me
  22. Problem isn't C++ per-se... by Anonymous Coward · · Score: 1

    The problem is the ABI clusterfuck you get with compiled code, especially when mixing different C++ standards, different compiler versions (often with mangled C++ namespace mangling) and different library versions (which thanks to improper use of inheritance, operator overloading, public/protected/private namespaces, etc) end up leading to a morass of bugs in the application level code, especially if you are trying to build a project which doesn't have the exact versions of all of those used to build it documented (because it was institutional knowledge and nobody thought it was important to include!)

    From a 'developing new code' point of view, C++ is nice. From a maintaining or improving existing code point of view, it is a huge clusterfuck, especially on systems that don't make ensuring slotting or abi versioning a priority (microsoft has gotten good about this since the win9x days, although they still constantly break API/ABI functionality with each new version or service pack, sometimes even in minor number releases, like the Win9x game breakage when DX8.1 came out on Windows 2000/XP...)

    C++ is fine for end user applications, and CAN be fine for application libraries. But system level software and operating system kernels are DECIDEDLY NOT the place for it, unless a *LOT* of features are pared back and warnings increased for documenting how and where API/ABI changes happen between versions of code/compiled libraries and binaries.

    1. Re: Problem isn't C++ per-se... by Anonymous Coward · · Score: 0

      Not to forget the disease of "we don't do stable ABIs, enjoy recompiling every program on your computer for every security patch, and if you don't you'll get random crashes at runtime" exemplarized by projects like boost and llvm. Qt shows you can do better, but few C++ projects do it. Probably because they choose C++ because it's easy, so they just don't do all the things that are hard with it, at the expense of everyone else...

    2. Re:Problem isn't C++ per-se... by TheRaven64 · · Score: 1

      From a maintaining or improving existing code point of view, it is a huge clusterfuck, especially on systems that don't make ensuring slotting or abi versioning a priority (microsoft has gotten good about this since the win9x days, although they still constantly break API/ABI functionality with each new version or service pack, sometimes even in minor number releases, like the Win9x game breakage when DX8.1 came out on Windows 2000/XP...)

      Odd to pick Microsoft there. Microsoft still has a policy of no stable C++ ABI across visual studio revisions, unlike the *NIX world that standardised on the Itanium ABI around 15 years ago. In contrast, Microsoft's policy is to tell you to use C or COM across library boundaries.

      You're also conflating three issues:

      1. Language ABI.
      2. Standard library ABI.
      3. Third-party library ABIs.

      Outside of Windows, the first has been a solved problem for well over a decade. The second was a little bit problematic in the move to C++11 because that change fixed a lot of fundamental problems with the language, but C++14 and C++17 have both been explicitly designed to permit a stable standard library ABI and libc++ supports a single ABI for all versions of the language. Neither C nor C++ is particularly good for third-party ABIs, unless you put a lot of care into the design. C++ at least makes it possible to use namespaces for versioning and so you can add compat functions in the language and have old code fall back to using them while new code uses the newer versions: C requires you to use symbol versioning in the linker to do the same thing.

      But system level software and operating system kernels are DECIDEDLY NOT the place for it, unless a *LOT* of features are pared back and warnings increased for documenting how and where API/ABI changes happen between versions of code/compiled libraries and binaries.

      The microkernel that runs the secure element in an iPhone and the baseband in any phone is written in C++. Windows and macOS device drivers are written in C++. Google's new kernel is written in C++. Symbian (which held 80% of the smartphone market until Nokia mismanaged it into oblivion) was written in C++. About the only operating systems that prefer C to C++ are ones that predate C++.

      --
      I am TheRaven on Soylent News
  23. My thoughts. by Anonymous Coward · · Score: 0

    As a master of C++, I think that C++ offers man yopportunities for misuse. But used properly, there is no really reason to "prefer" C over C++.

    First, using a subset is wrong. There are times when each feature is useful, and times when features are not useful. I would say I almost never use volatile or multiple virtual protected inheritance. But when I do need multiple protected virtual inheritance, in those rare cases that I do, I'm very glad to have it. Volatile is almost never useful, but at times, I want to use it. For example, when I want to make damn sure a crypto key is scrubbed from RAM and not have my overwrite optimized out.

    Let me go over what C has that C++ doesn't:

    Dot-Constructors and an official restrict keyword. That's pretty much it. Restrict is supported by most C++ compilers anyway.

    If I wanted to list the things C++ has but C doesn't, it'd take all day.

    C++ is faster than C in practice because of templates (try std::sort vs qsort, std::sort is significantly faster), the disadvantages of C++ all involve misusing C++ features when they are not needed. They are not inherent flaws of the language.

    That's why C++ is better than C, even though some people do stupid things with it.

    1. Re:My thoughts. by Anonymous Coward · · Score: 0

      > If I wanted to list the things C++ has but C doesn't, it'd take all day.

      I think I found your problem, right here.

    2. Re: My thoughts. by Anonymous Coward · · Score: 0

      I agree that C++ is a much harder language to learn, but once you spend a few years to learn it properly, it is a much better language. It took me around 4-5 years of using C++ to master the language. But now that I have I willl probably use C++ for the rest of my life. It's not going to be replaced unlike many other langauges out there. And I know that I can learn any other language with relative ease.

      So my opinion is this:

      Begginner: Use Python.
      Intermediate: Use C#/Java.
      Expert: Use C++.

    3. Re:My thoughts. by TheRaven64 · · Score: 1

      It is a large language, but you should re-read what he said about subsetting. 90% of programming problems can be solved with 10% of C++. The other 90% of the language is for the remaining 10%. If you learn the core of the language, it doesn't take much longer than learning the core of C, and you can then pick up the other features as you need to - many you never will unless you're implementing something like the standard library.

      --
      I am TheRaven on Soylent News
  24. C vs C++ by woboyle · · Score: 2

    I have been writing C since the early 80's and C++ since the early 90's. For large-scale robust systems, C++ is the way to go. It provides for greater degrees of abstraction, debug-ability, and clarity of intent. I only use C any longer for kernel development.

    --
    Sometimes, real fast is almost as good as real-time.
    1. Re:C vs C++ by Anonymous Coward · · Score: 0

      I thought the entire world did this. The idea that one should use C++ as a "better C" is a common practice that dates back 20 years. Sure, now and again I find a client that heavily drank from the C++ coolaid, and is using Boost for everything, but 95% of my clients are just using C++ as a "better C", with classes, single inheritance, and sparse use of templates only when necessary.

      The headline should really be "Someone on Medium just put a 20-year old industry-wide practice into words, thus annoying a bunch of kids that are either still in college or haven't yet got over once being in college."

  25. Re: different tesults on different platforms by Anonymous Coward · · Score: 0

    I tried a similar problem with ++ in for, if, while.. different flavour of unix(read compilers) gave unpredictable/unexpected results..get rid of doing multiple things in multiple ways

  26. Well, duh - it is by johannesg · · Score: 3, Informative

    C++ is much better than C. It's much greater expressiveness makes it easy to clearly formulate what you are doing, and in far fewer lines of code too. Exceptions free you from all that tedious boilerplate, where every function call basically expands into three lines: error=function();if (error) handle_error (error);. RAII makes resource handling painless. It's massively more powerful standard library provide instant access to lots of useful datastructures and algorithms, and unlike C it's all typesafe too.

    Is it hard to use? Hardly. I find C hard to use - just imagine having to write an application that uses strings, it'll be one giant mass of mallocs, strcats, strcpys, frees (don't forget any!), and will invariably end in buffer overflows and lost memory. Oh, and it will probably have a whole bunch of gotos for what they laughingly call 'resource management', Dijkstra's 1968 paper notwithstanding.

    Do I disagree with all the criticism, then? No - but the horror stories that get posted here do tend to be worst possible cases, which pop up once in a very long while, rather than the daily occurrences some people make them out to be. It's been... I don't know, half a decade or so? since I last saw one of those horrifying template errors - and it's not for lack of templates in my code. It's not really a hard language either - sure, you _can_ write unreadable statements, but you can do that in any language so that doesn't mean much. It also gives you the tools to write much, much clearer code.

    I always roll my eyes when people mention needing a 'cut-down C++'. That's lack of understanding, usually mixed with a liberal dose of unwarranted fear, and better advise would be "use common sense". For example, there is nothing wrong with overloading operators, but common sense indicates one should not change the meaning of those operators. Having your own number-like class is fine (for example, for complex numbers, bignums, money, whatever), and overloading operators for it is an excellent idea. Using operator+ to paint a widget or retrieve data from a database - maybe not so much.

    So, yeah, C++ is an amazing language. Hmm, that makes me wonder if there will be an article on Medium now, revealing that someone on Slashdot just said that. I don't know that website, maybe they are not into clickbait so much...

    1. Re:Well, duh - it is by lucasnate1 · · Score: 1

      gcc added something called "cleanup attribute" which is essentially destructors in C++. That replaces "goto" in the case you described. I really hope they will put it in the standard at some point.

    2. Re:Well, duh - it is by Anonymous Coward · · Score: 0

      None of gcc's non-standard extensions are standardized, and for good reasons, only one of which is the fucked up LISP syntax it uses for them (thank you Richard Stallman!)

      Corollary: Linux isn't actually written in C and people should stop claiming that it is ;)

  27. Software Engineering by Anonymous Coward · · Score: 0

    If you don't know if it's overloaded or not, please don't call what you're doing software engineering.

  28. Memory management by Anonymous Coward · · Score: 0

    You're going on about libraries.

    C++ still supports the Standard C Library and raw pointers.

    Your arguments, like your coding skills are weak.

  29. Generally I only use a subset of C++ by w3woody · · Score: 3, Insightful

    I first started using C++ back in the 1980's.

    I am a huge fan of classes. When C++ was basically a preprocessor for C which introduced the class keyword, I thought it was pretty cool.

    When exceptions were introduced to the language I thought C++ was fairly complete as a language. If from there the designers of C++ had addressed the fragile base class problem, lambdas and some form of introspection, I think C++ would have been a fantastic language.

    Instead, we got templates. I'm not a fan of templates.

    And when we got the standard template library, I thought someone was smoking crack. Using the left shift and right shift operators to mean "input" and "output"? Really? Really?!?

    When I write C++ I try to stick to using a subset of C++ which includes classes and exceptions. I use templates sparingly, only when they are really needed, and I refuse to use the C++ left-shift and right-shift operators. (I really feel like the person who designed that thought "how cool; we can override a shift operator to mean input and output!" But just because you can doesn't mean you should, and now we're stuck with this bit of syntactic bit of bullshit.

    We're finally getting around to lambdas, though too late: Apple has already wedged blocks into a non-standard extension. And I'm not holding my breath on introspection or on fixing the fragile base class problem simply because the run-time implementation recommendation for classes way back in the late 1980's has become a baked in de-facto feature. (Sadly it would have been relatively easy to solve by introducing link-time assignment of the indexes in the virtual table pointer; that way, as the base class is recompiled the index references for the methods in the virtual table could be reassigned at link time. This also solves fragile access to public class fields; simply replace them with a standard getter and setter method which is accessed via the virtual table.)

    1. Re:Generally I only use a subset of C++ by Anonymous Coward · · Score: 0

      > Using the left shift and right shift operators to mean "input" and "output"? Really? Really?!?

      That's not even the worst of it. That's just the tip of the operator overloading iceberg.

      Unnecessary and sometimes fatal ambiguity introduced and for what? A little syntactic sugar?

      Bjarne should compensate all C++ programmers for the thousands of hours they've lost debugging that crap.

    2. Re:Generally I only use a subset of C++ by Anonymous Coward · · Score: 0

      And when we got the standard template library, I thought someone was smoking crack. Using the left shift and right shift operators to mean "input" and "output"? Really? Really?!?

      A quick check shows that the shift operators were already in the language when Stroustrup wrote "A C++ Tutorial" back in September 1984. That's a full decade before STL was added to the draft standard.

    3. Re:Generally I only use a subset of C++ by Anonymous Coward · · Score: 0

      I'm still waiting for hot-swappable delegates which don't take a several-page helper class and a syntax you have to look up every time.

    4. Re:Generally I only use a subset of C++ by Anonymous Coward · · Score: 0

      Using the left shift and right shift operators to mean "input" and "output"? Really? Really?!?

      Iostream and operator overloading became long before templates, particularly the STL. If you like encapsulation provided by classes, you likely like operator overloading as well. Since we live in the age of GUIs, and error logs are written out without buffering, you might not use iostream much anyway (unless you really love to left shift to cerr). C++ standard graphics library will save your day, eventually.

      I refuse to use the C++ left-shift and right-shift operators.

      If you don't have to deal with the low level code, you don't have a reason to. ;)

  30. Which is better? by Anonymous Coward · · Score: 0

    I've programmed in both languages. Knowing C++ made me a better C programmer.

  31. Silly language debates by Qbertino · · Score: 3, Informative

    C++ done right is do vastly different from C that debating which language is better is beyond silly. This goes threefold if you look at C++14 programmed with the GSL - the right way to do C++ these days.

    In a nutshell C is assembler 2.0 and C++ is assembler 3.0. C++ has massive inner api advantages over C that C tries to compensate for with libs such as boost.

      Yet build with C++ without knowing what you are doing and of course you'll produce bad software. With C you simply won't get anywhere.

    Wether you use one or the other these days is often a matter of personal preference more than anything else. C++ has massive ready-made power with the responsibilty that comes with it. Any programmer looking at these PLs will see the difference and adapt his style of coding accordingly.

    --
    We suffer more in our imagination than in reality. - Seneca
  32. it all goes back to assembler by Anonymous Coward · · Score: 0

    This all goes back to the early days and processors (PDP-11) with autopreincrement and autopostincrement flavors of register access. (e.g. a Push was a MOV R0 -(R6) ) Although B had it too, and comes from the PDP-7 days which had only an autoincrement

    If you want "control of the metal", then you want both i++ and ++i.

  33. 60% of the C coders are good 10% of the C++ ones. by Anonymous Coward · · Score: 0

    C++ ain't that bad, it just seem to attract shit coders.

  34. His name is... by Anonymous Coward · · Score: 0

    Trick reply. It's more like half a person, half a machine.
    His name is...