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++?

216 of 315 comments (clear)

  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 Jamu · · Score: 1

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

      --
      Who ordered that?
    4. Re:Indeed by religionofpeas · · Score: 1

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

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

      Trick question. There is only one ada programmer.

    6. 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.
    7. 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.
    8. 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).

    9. 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."
    10. Re:Indeed by hcs_$reboot · · Score: 1

      UB

      --
      Slashdot, fix the reply notifications... You won't get away with it...
    11. 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++.

    12. 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.
    13. 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.

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

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

    15. 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).

    16. 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++".

    17. 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.

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

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

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

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

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

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

    21. 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.
    22. 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.
    23. Re:Indeed by gordo3000 · · Score: 1

      there are no movies better than Armageddon.

    24. 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...
    25. 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."
    26. 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
    27. 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.
    28. 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.
    29. 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.
    30. 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.
    31. Re:Indeed by ooloorie · · Score: 1

      Hence "undefined behavior".

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

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

    33. 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.
    34. 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?
    35. 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.

    36. 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.

    37. 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.

    38. 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.

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

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

    40. 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.
    41. 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.

    42. 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.

    43. 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.

    44. 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
    45. 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
    46. 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
    47. 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
    48. 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
    49. 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
    50. 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
    51. 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
    52. 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
    53. 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.

    54. 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.
    55. Re:Indeed by zwarte+piet · · Score: 1

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

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

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

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

      I C what you did there.

    58. 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.

    59. 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 phantomfive · · Score: 1

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

      --
      "First they came for the slanderers and i said nothing."
    3. 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.

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

      So, learn assembly in your free time.

    5. 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.

    6. 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.
    7. Re:Kids these days... by CAOgdin · · Score: 1

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

    8. 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.
    9. 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?

    10. 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.

    11. 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.

    12. 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."
    13. 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.

    14. 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."
    15. 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).

    16. 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"
    17. 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.

    18. 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.
    19. 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.

    20. 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.

    21. 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.

    22. 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
    23. 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.

    24. 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.

    25. 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.

    26. 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
    27. 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
    28. 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.
    29. 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"
    30. 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.

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

      So you mean all the compiler writers are above 45?

    32. 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.

    33. 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.
    34. 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.

    35. 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
    36. 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
    37. 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
    38. 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
    39. 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
    40. 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.

    41. 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
      }

    42. 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.

    43. 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
    44. 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
    45. 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: 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.

    3. 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.
    4. 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."
    5. 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.

    6. 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.
    7. 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.

    8. 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.
    9. 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.
    10. 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.

    11. 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.
    12. 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.
    13. 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.
    14. 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.
    15. 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});
    16. 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
    17. 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.
    18. 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 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."
    9. 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
    10. 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
    11. 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
    12. 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."
    13. 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."
    14. 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."
    15. 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
    16. 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 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

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

      Well, with great power comes great responsibility :)

    11. 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.
    12. 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."
    13. 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).

    14. 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.
    15. 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.

    16. 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
    17. 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
    18. 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
    19. 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.
    20. 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.
  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. 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.

  9. 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.

  10. 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."
  11. 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.

  12. 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.
  13. 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.
  14. 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 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
    10. 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.
    11. 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.
    12. 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.
    13. 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.

    14. 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.
    15. 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.
  15. 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
  16. 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 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
    3. 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.
    4. 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
  17. Online by meadow · · Score: 1

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

  18. 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.
  19. 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
  20. 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 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
  21. 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.
  22. 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.

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

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

  24. 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.)

  25. 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."
  26. 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
  27. 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
  28. 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