Slashdot Mirror


Was Linus Torvalds Right About C++ Being So Wrong?

Nerval's Lobster writes: Perhaps the most famous rant against C++ came from none other than Linus Torvalds in 2007. "C++ is a horrible language," he wrote, for starters. "It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it." He's not alone: A lot of developers dislike how much C++ can do "behind the scenes" with STL and Boost, leading to potential instability and inefficiency. And yet there's still demand for C++ out there. Over at Dice, Jeff Cogswell argues that C++ doesn't deserve the hatred. "I've witnessed a lot of 'over-engineering' in my life, wherein people would write reusable classes with several layers of inheritance, even though the reusable class wasn't actually used more than once," he wrote. "But I would argue that's the exception, not the norm; when done right, generic programming and other high-level aspects of C++ can provide enormous benefits." Was Linus going overboard?

757 comments

  1. Write-only code. by mellon · · Score: 5, Insightful

    The problem with C++ is that it's way too easy to write write-only code, because the language has so many features that nobody but language experts understand all of them. So we all program in different dialects, and then scratch our heads when we read other peoples' code.

    1. Re:Write-only code. by Anonymous Coward · · Score: 5, Interesting

      Maybe that's what it is. I write a lot of C code, some of it pretty good, but I just can't "get" C++. I appreciate the class stuff. Heck, I pretty much do the same thing using structs in C but past that, the rest of C++ just loses me.

    2. Re:Write-only code. by Anonymous Coward · · Score: 4, Insightful

      This is a potential problem with every single programming language ever. No exceptions. C is somewhere in the middle with that risk, but it is no where near the worst. I'd give that medal to Perl.

    3. Re:Write-only code. by Carewolf · · Score: 5, Insightful

      The problem with C++ is that it's way too easy to write write-only code, because the language has so many features that nobody but language experts understand all of them. So we all program in different dialects, and then scratch our heads when we read other peoples' code.

      Less so than C, especially as used in the kernel. Seriously read some of the Linux kernel and compare it with any good C++ project. The kernel loses BADLY. The manually implemented virtual classes are not pretty and not type safe, and neither are all the ugly macros needed to do things that would safe, automatic and easy to read in C++.

    4. Re:Write-only code. by mellon · · Score: 5, Interesting

      You can find some really elegant C++ code out there. I am quite fond of the Qt libraries, for example. But Qt is its own C++ dialect. The company I work for codes a lot of our software in C++, and it is really nice, clean, maintainable code. But we have a style guide that everybody has to follow, and that's how we pull it off. Essentially, we are not writing in C++. We're just using a C++ compiler to compile NomLang.

    5. Re:Write-only code. by loonycyborg · · Score: 4, Insightful

      I definitely disagree here. All features of C++ have their uses and it's possible and necessary to master them all. This language is focused on getting the job done. Thus some of its design decisions don't look very nice. But it's the most usable language in its niche.

    6. Re:Write-only code. by mellon · · Score: 2

      True, but for example while Scheme is highly extensible, there isn't a lot of really obscure syntax, nor is there a preprocessor. Anything that's Turing complete can develop widely divergent dialects, but C++'s dialects are notoriously obscure.

    7. Re:Write-only code. by rroman · · Score: 1

      Yes. Exactly.

    8. Re:Write-only code. by mellon · · Score: 2

      I don't think you actually mean "virtual classes" here. But yeah, if you have to implement classes in C, maybe you should have used C++. One of C++'s problems is that it builds on C, though, so the fact that you can do some things, particularly classes, better in C++ than in C shouldn't be a surprise: that's the itch they were scratching.

    9. Re:Write-only code. by KermodeBear · · Score: 5, Insightful

      The same applies with Perl. And PHP. And Java. And Go. And Ruby. And Python. And Javascript.

      I've also seen good C/C++, PHP, Java, Python, etc.

      You can write crappy convoluted code that uses odd, unusual frameworks and features in every language. It isn't the fault of the language - it is the fault of the people (ab)using it.

      --
      Love sees no species.
    10. Re:Write-only code. by mellon · · Score: 1

      Of course all C++ features have their uses. Otherwise they wouldn't exist. Every one of them scratches some itch.

    11. Re:Write-only code. by Carewolf · · Score: 1

      I don't think you actually mean "virtual classes" here. But yeah, if you have to implement classes in C, maybe you should have used C++. One of C++'s problems is that it builds on C, though, so the fact that you can do some things, particularly classes, better in C++ than in C shouldn't be a surprise: that's the itch they were scratching.

      I mean virtual tables, which is the implementation side of virtual classes. The kernel uses virtual tables extensively to describe interfaces of modules and especially drivers.

    12. Re:Write-only code. by schitso · · Score: 2

      One of the nice things about Python is the very concrete idea of what is and isn't "Pythonic". I've never had too much difficulty jumping right in to something written in Python and having a good idea of what's going on.

    13. Re:Write-only code. by sjames · · Score: 3, Insightful

      Actually, the kernel code is quite clear and understandable to any decent C programmer. I find it hard to consider it losing BADLY to anything.

      Note that C++ isn't necessarily type safe either. It's not at all difficult to cast an object pointer to the wrong type and crash. It's no harder than it is in C.

    14. Re:Write-only code. by Pieroxy · · Score: 3, Interesting

      Are you comparing the complexity of Java vs C++ (as a language, not as a runtime)? Are you kidding?

      You can write convoluted code in any language, this is true. But C++ code can be made UNREADABLE as well as convoluted. In Java, there is only the one way of writing things. You can architect them differently if you want, but there's usually one way to write them. In C++, you have a hundred. THIS is the problem with C++. And let's not even talk about macros which is one more way to write things. You can actually write your whole program only through macros. Macros are turing-complete. They're just a language inside the language... This is pure madness.

    15. Re:Write-only code. by cant_get_a_good_nick · · Score: 1

      Orange is the new black, C++ is the new Perl.

    16. Re:Write-only code. by OrangeTide · · Score: 1

      I find Linux kernel code very easy to read. And I've not had any problems doing very heavy modifications to the not type-safe, but fairly modular design.
      But I do this as my day job, I have the unfair bias of many years of practice.

      I can't do much with C++ though. I could probably compile a working C++ project without too much help, but I'd struggle if I had to make significant changes to a big C++ project.

      --
      “Common sense is not so common.” — Voltaire
    17. Re:Write-only code. by Dwedit · · Score: 2

      Sounds like that goes back to the "lack of standard ABI" problem. C lets you specify exactly what you want explicitly, but C++ has no consistent ABI, you get different results depending on which compiler you use.

    18. Re:Write-only code. by Anonymous Coward · · Score: 5, Interesting

      You can find some really elegant C++ code out there. I am quite fond of the Qt libraries, for example. But Qt is its own C++ dialect.

      Ditto on Qt. Qt can be a beautiful thing sometimes... but then comes pre-compile, which turns it into an anus-puckering nightmare for those who don't know you're using it ;) .

      The company I work for codes a lot of our software in C++, and it is really nice, clean, maintainable code. But we have a style guide that everybody has to follow, and that's how we pull it off.

      That should be the norm in any competent shop, though.

      Mind you, I've seen shops where styles are horribly mixed-up. That usually happens when Company A buys Company B's codebase and nobody cleans up the stuff from Company B. OTOH, I've seen instances where different teams in the same company decide to become special snowflakes and go their own way, making life into a giant shit sandwich for DevOps, QA, or SCM to eat - especially when they have to point to something and say "...fix that, because it's breaking Jenkins/Tito/unit tests/etc... and WTF man, we have artifacts for a reason!"

      But then, I just came out of a Java shop where they were using Geronimo, Jetty8, Jetty9... Java 1.6 and 1.7... all in the same 'effing overall product (just that the components sit on different servers.)

      Long story short, it takes discipline to keep everyone rowing in the same general direction - enforced styleguides are a part of that. Discipline also keeps things from becoming an unmanageable mess, if the head coder has the spine for it.

    19. Re:Write-only code. by Penguinisto · · Score: 2, Insightful

      This is a potential problem with every single programming language ever. No exceptions. C is somewhere in the middle with that risk, but it is no where near the worst. I'd give that medal to Perl.

      The more powerful the language, the more it's like a loaded gun: You can use it responsibly and do amazing things with it, or you can put a bullet through your foot with it. Choice is yours... and the closer you get to bare metal with the language, the greater the chance of lead meeting foot at high speed.

      --
      Quo usque tandem abutere, Nimbus, patientia nostra?
    20. Re:Write-only code. by johanw · · Score: 4, Interesting

      I usually use C++ as "C with classes". No fancy stuff like STL or Lambda expressions. That works well, and most companies where I've worked use C++ that way.,

    21. Re:Write-only code. by grahamwest · · Score: 1

      I'm not a Linux programmer so I may be out of date on this, but there isn't or wasn't a single C++ ABI on Linux between the various compilers. If the kernel used C++ for those interfaces it would potentially require that the kernal and all kernel modules were compiled with the same toolchain. Rolling their own implementation means the ABI is compatible across all the different compilers and compiler version with a side benefit of being able to write kernel modules in languages other than C/C++.

      --
      Graham
    22. Re:Write-only code. by tibit · · Score: 1

      Frankly said, I think that this is rather overstating things. Modern C++ has plenty of idioms that you should use first, without attempting to come up with your revolutionary redesigns of a common wooden wheel. Effective C++ and Modern Effective C++ are required reading, as well as Strostrup's most recent (at any time) edition of The C++ Programming Language. Also Exceptional C++, and Modern C++ Design. I can't help but mention the interview with Alex Stepanov, where he explains the mathematical basis for STL (You thought that software engineering requires no abstract, higher non-CSy math? Think again!)

      C++ is a big language, and people who know their craft actually do know all of its features, and can probably point to relevant sections in the standard when they talk about things. I'd say: meh, pebkac.

      --
      A successful API design takes a mixture of software design and pedagogy.
    23. Re:Write-only code. by praxis · · Score: 1

      That is not a feature of the language, though. That is a feature of the community.

    24. Re:Write-only code. by grahamwest · · Score: 2

      C++ templates are also Turing-complete at compile time.

      When I tried learning a bit of LISP, the thing that struck me was that its metaprogramming language is also the runtime language, and I like that very much.

      --
      Graham
    25. Re:Write-only code. by StikyPad · · Score: 1

      I haven't found that to be true at all. If someone doesn't understand the fundamental types, operators, objects, iterators, and data structures, they shouldn't be using the language professionally. If they do, then they can read any code.

      I don't know about strict feature counts, but Java and C# have features that C++ lacks, like anonymous classes/types, and they can be just as opaque if you don't know what you're looking at, or if you're trying to divine the functionality by looking at the methods that consume them.

      Are there many ways to skin a cat? Sure, but they're all going to involve cats and skin. If you know what objects a method/function/class is working on, it's usually not a huge leap to figure out what it's doing to them. If the inputs and outputs aren't documented, well, that just sucks, but it's not a function of the language.

    26. Re:Write-only code. by spiralx · · Score: 4, Interesting

      It's both. Type import this from the interpreter, and you'll get this:

      The Zen of Python, by Tim Peters

      Beautiful is better than ugly.
      Explicit is better than implicit.
      Simple is better than complex.
      Complex is better than complicated.
      Flat is better than nested.
      Sparse is better than dense.
      Readability counts.
      Special cases aren't special enough to break the rules.
      Although practicality beats purity.
      Errors should never pass silently.
      Unless explicitly silenced.
      In the face of ambiguity, refuse the temptation to guess.
      There should be one-- and preferably only one --obvious way to do it.
      Although that way may not be obvious at first unless you're Dutch.
      Now is better than never.
      Although never is often better than *right* now.
      If the implementation is hard to explain, it's a bad idea.
      If the implementation is easy to explain, it may be a good idea.
      Namespaces are one honking great idea -- let's do more of those!

      While it doesn't always manage it, if you read the discussions and PEPs relating to the language's design it's clear that the idea of a "Pythonic" way of doing things is one of the top considerations.

    27. Re:Write-only code. by Anonymous Coward · · Score: 0

      Yeah, but most of those features are CONSISTENT and compatible with each other.

      C++? Hardly the same.
      C++ is a glorious mess unlike that which the world has seen before.

      C++ as a "language" is like saying there is such a thing as a standard human in biology. Hilariously wrong.
      There are averages of what is to be expected in a C++ program, but they still vary wildly.

    28. Re:Write-only code. by Cramer · · Score: 1

      list of function pointers. That's how everything works already. In the kernel code, you see it explicitly. Elsewhere, the compiler and dynamic loader logic covers all that up.

      But, yes, the kernel code can be a swirling mess. Many times the non-obvious complexity is due to compiler issues or a specific need to get the CPU/hardware to do something in a very specific manner. If there aren't a bunch of comments around it in the code, others won't know why something so "obviously stupid" was done. (I've had to fix the same issue in the sparc64 code three times because davem won't include my comments, and every few years forgets.)

    29. Re:Write-only code. by Yunzil · · Score: 1

      In Java, there is only the one way of writing things.

      Yeah, and it's ugly and complex.

    30. Re:Write-only code. by Anonymous Coward · · Score: 0

      But usually if you are close to the metal your risks don't include "doing things that are hidden from the programmer that are really slow and unpredictable".

    31. Re:Write-only code. by Anonymous Coward · · Score: 0

      It's certainly harder than in C. In C, you can cast any pointer to and from a void pointer. In C++, you shouldn't, and if you do cast pointers you know you're doing something wrong. Having to write a cast at least shows you must have given it some serious thought.

    32. Re:Write-only code. by wed128 · · Score: 4, Insightful

      Sometimes wounds itch. When you scratch them, they break open and fester. C++ scratches exactly these itches.

    33. Re:Write-only code. by wed128 · · Score: 1

      This. Lisp is a beautiful language. The fact that it's not taught and used is a serious problem in the programming profession. Every programmer has the potential to be better, just by learning Lisp (not even using it!)

    34. Re:Write-only code. by Anonymous Coward · · Score: 2, Interesting

      C is quite stable compared to various other language, even factoring the C99 implementation slowness or difficulty in. Since the C11 change of standardization policy, the language will be even more stable in the future.

    35. Re:Write-only code. by wed128 · · Score: 2

      Ugly and Complex is better than Ugly and Complex and Inconsistent.

    36. Re:Write-only code. by Anonymous Coward · · Score: 0

      Crappy code is the DEVELOPER'S fault and not the languages.

    37. Re:Write-only code. by Anonymous Coward · · Score: 0

      I agree. C++ is mostly crap. For me, and from what I've read for many other programmers as well, the spec and libraries are too big, too ugly, and too hard to learn well and master. While it's great that languages offer various ways to solve problems, C++'s somewhat obscure syntax at times, complex libraries, many gotchas (copy constructor rules are quite maddening), and other rules makes it pale in comparison to the readability (hence maintainability) of most other languages, in my experience (25+years of programming).

      Avoiding the language wars' ridiculous and time-wasting trolling, I simply chose to avoid C++ as much as I can. I've recently been using a lot of C# and it's really very nice. I wish it was more available and up-to-date on more platforms than it currently is. It's not about the spec/memory/GC/bare-metal arguments as much as it is having the headspace to get on solving my problems while not fighting with the language/libraries the whole way.

    38. Re:Write-only code. by sjames · · Score: 1

      So how does that differ at all from C? Shouldn't != can't

    39. Re:Write-only code. by Carewolf · · Score: 3, Informative

      Sounds like that goes back to the "lack of standard ABI" problem. C lets you specify exactly what you want explicitly, but C++ has no consistent ABI, you get different results depending on which compiler you use.

      Not anymore. At least not on Linux. Intel wrote a C++ ABI for IA64 (Itanic), since it was the first of its kind it got adopted to a defacto ABI for all other architectures as well. This is what g++ has been using for over a decade, and what every other compiler is mimicking to stay g++ compatible.

      Even a failed architecture can sow the seeds for good things in the open source world.

    40. Re:Write-only code. by Kjella · · Score: 1

      I definitely disagree here. All features of C++ have their uses and it's possible and necessary to master them all. This language is focused on getting the job done. Thus some of its design decisions don't look very nice. But it's the most usable language in its niche.

      Yes, but they have the defaults all wrong. They hand you a scalpel and tell you 99.99% of the time you'll use this as a kitchen knife, because in the 0.01% corner case nothing short of scalpel will do. For example "int i; printf( "%d", i );" and you have a code with undefined behavior. At runtime it'll print a random number even though you never called rand() to indicate that's what you wanted. By default it should be deterministic, if you need that behavior for some reason make it "uninitialized int i; printf( "%d", i );" then. In a switch statement you very often want to do one thing per case and you must remember to break every one of them. If you have fallthrough that's part of the logic so spelling it out makes much more sense. It's a minefield just daring you to prove your C++ mastery. And I really wish they'd implement int?. Databases, nobody works with those anymore...

      I like the Qt dialect of C++, but I realize it's a huge patchwork to put features on top of C++ that it doesn't have by default, using a ton of generated classes, macros and so on. If you wanted to start over with a new OOP language, I'd take a long look at Java, Swift and C# for design elements, with as few C-isms as possible.

      --
      Live today, because you never know what tomorrow brings
    41. Re:Write-only code. by mrvan · · Score: 1

      There should be one-- and preferably only one --obvious way to do it.

      So, tell me, should I prefer


      borbs = []
      for orn in orns:
          x = compute(orn)
          if x > 12:
              borbs.append(x)

      or


      borbs = [compute(orn) for orn in orns if compute(orn) > 12]

      And please note that this is from someone who is actually Dutch, so it should be obvious to me, right?
      (and it comes from someone loving and professionally using python for >10 year)

    42. Re:Write-only code. by guacamole · · Score: 1

      ... , because the language has so many features that nobody but language experts understand all of them.

      And I think that's fine. C++ is not an every day go-to programming language. Its use should be reserved for writing heavyweight applications (like the desktop environments, productivity apps, etc), servers, and numerical code. Considering the complexity of a typical c++ app codebase as well as the language itself, only the experts should touch it.

    43. Re:Write-only code. by Darinbob · · Score: 5, Informative

      Right now I'm doing just C and assembler (and the occasional scripting in something else). Sometimes it feels a bit archaic compared to a stripped down C++ style I'm more used to, but on the other hand there just aren't as many political fights over style so it's less stressful. The interesting thing about C is that newer standards don't tend to lots of new and experimental features, which is sort of the norm with C++. C tries to be stable.

      Also a big part of my job when doing C++ was decoding the obtuse error messages for coworkers, and that almost never happens with C...

    44. Re:Write-only code. by Anonymous Coward · · Score: 0

      No, you can write a java program in 100 different ways too, but you're right about macros -- they're terrible. I choose not to use them.

    45. Re:Write-only code. by tbttfox · · Score: 1

      "Flat is better than nested", so I would prefer the second one. Unless, of course, compute() is an expensive function, because "practicality beats purity".
      That said, to me the obvious choice is to use two comprehensions:

      mid = [compute(orn) for orn in orns]
      borbs = [i for i in mid if i>12]

    46. Re:Write-only code. by IamTheRealMike · · Score: 1

      Java is ugly. It is not complex by any reasonable definition, unless you're comparing it to BASIC or something. Part of the reason Java is ugly is that it's so simple, in fact - it eschews syntax sugar and various conveniences that'd make the code shorter and prettier.

      I tend to feel that Java is on the wrong side of programming language trends here: there's a lot to be said for simplicity, but some languages are showing that you can add a lot of convenient and helpful features to Java-like languages without exploding the language's complexity budget. C# for instance is widely agreed to be more pleasant to use than Java (at least, widely agreed by most devs with experience in both that I've met).

      On the JVM unfortunately we've been kind of limited until now in the "simple, beautiful yet performant" space. There are languages like Scala that are static enough to be reasonably fast, but there seems to be a growing consensus that Scala is very complicated. I've seen it be called the C++ of the JVM. There are lots of dynamic languages like Ruby, Python, Groovy, Clojure etc that gain simplicity and terseness by abandoning static typing entirely but sacrifice maintainability and performance. There's Frege, a Haskell dialect that I have no experience of, but lazyness-by-default seems a controversial choice at best.

      Lately there's also Ceylon and Kotlin, which seem to be exploring a new space in PL design that can be summed up as Scala but made a lot simpler. The syntaxes are terse and compact, the typing is static, the IDE support is developed alongside the language, and they compile to both the JVM and Javascript. Kotlin is my personal favourite. The feature set eliminates much of the tedious boilerplate in Java without adding much potential for code maintenance disasters or excessive complexity. It also increases safety, like by making nullability a part of the type system.

    47. Re:Write-only code. by phantomfive · · Score: 1

      Note that C++ isn't necessarily type safe either. It's not at all difficult to cast an object pointer to the wrong type and crash. It's no harder than it is in C.

      The main problem is when you pop an item off a stack or queue, usually you have to cast it to the object you want (in C). In Java, with templates, and C++ with templates, it pops off and is automatically converted to the correct type.

      This isn't a problem either way for skilled programmers who know what objects get put in a queue, but some of the (poorly written) Java code I've seen definitely benefited from knowing what type of object was in a queue.

      --
      "First they came for the slanderers and i said nothing."
    48. Re:Write-only code. by Anonymous Coward · · Score: 0

      It's not at all difficult to cast an object pointer to the wrong type and crash. It's no harder than it is in C.

      This is true due to backwards compatibility. But if instead of using the C based casts and instead using C++ based casts (static_cast, reinterpret_cast and that ilk) it does become harder than in C. Not much harder, but there's a little more safety there than there was before.

    49. Re:Write-only code. by phantomfive · · Score: 1

      True point. The people matter much, much more than the language. You can even find beautiful COBOL.

      --
      "First they came for the slanderers and i said nothing."
    50. Re:Write-only code. by Darinbob · · Score: 1

      Which is great because it is portable. If you did this with C++ then you could only link with C++, and only the same C++ compiler because the virtual tables aren't compatible with each other.

    51. Re:Write-only code. by galabar · · Score: 1
    52. Re:Write-only code. by Anonymous Coward · · Score: 0

      ASM is. IT does everything that any and ALL other languease can do, with way fewer built in functions. The code is also tighter and faster then any other language.

      It's usable niche is EVERY WHERE.

    53. Re:Write-only code. by Darinbob · · Score: 1

      However elsewhere there are problems. Ie, G++ and MSVC++ implement things very differently, depending on the versions and such. Ie, the contents of the v-table, location of the v-table in the object, etc. You've got both a function pointer plus a "fixup" offset to account for multiple inheritance, or thunks, whereas most OS kernels prefer to just have a simple array of function pointers which are capable of being easily used from most any language that follows the CPUs ABI (including assembler). It works on Linux because for a very long time g++ was the only offering and the newer options intentionally remain g++ compatible, whereas elsewhere this may not be true at all.

    54. Re:Write-only code. by Darinbob · · Score: 1

      It's also old code. As you go back to earlier and earlier linux releases the code does look a bit nicer.

    55. Re:Write-only code. by sjames · · Score: 1

      That's not necessarily true in C. If you use defines for the pushing and popping (queue/dequeue, link/unlink, etc) and build the chain pointers into the object, it will happily enforce the type based on the type of the head object. Once the pre-processor is done, the compiler will complain if you try to assign struct foo_t *next the address of a struct bar_t

    56. Re:Write-only code. by earthminion · · Score: 1

      Its true the more powerful the language the more of good and bad you can have, depending upon how its used, but there's another side to it. How its used (and expected to be used) is very often driven and controlled like a fashion and just like fashion it has its own over zealous even hostile types who often enjoy denigrating anyone for doing things that don't follow the current fashion. There has been times where questioning current *insert programming language* doctrine is treated almost like heresy.

      Of course all too often these loud denigrating Prophets of the new way, as they want others to believe, ultimately profit from being seen as the leaders in their field and so don't want rational discussion to get in their way.

      Veterans of programming who have been around for a few decades will know what I mean, because they will have seen how what is seen as in fashion changes over time and then we also at times even get reinventions of older ideas under new names and new spins on old ideas.

      Programming more than any other area of human behaviour should be about logic, not fashion, but sadly all too often, that's not how some programmers treat other programmers. I guess for some, manipulative career advancement takes precedence. Of course, they will be the type of people who'll be most likely to deny that's how anyone plays their power games over others.

      But then that's no different from just about every industry and every walk of life.

    57. Re:Write-only code. by Jeremiah+Cornelius · · Score: 1

      Write-only code is easy in ANY syntax.

      --
      "Flyin' in just a sweet place,
      Never been known to fail..."
    58. Re:Write-only code. by Rei · · Score: 5, Interesting

      STL and lambda are my main reasons for using C++. They're bloody awesome.

      Here's my standard challenge for C people - I've given it many times in these sort of threads and not once gotten a real response that meets the specs. Show me the code (emphasis: show me actual code, don't just say "... this is how I'd do it" and a rough description), full code (emphasis: full) for a program launching a detached (emphasis: detached) thread, such that it can happen an arbitrary number of times with no guarantee that other threads will be done (emphasis, there can be more than one thread at a time), to run the function do_something(Foo a, Bar b) (emphasis: two arguments, arbitrary size) - where the values passed for a and b are variables local to the context that launches the thread (emphasis: local), so they need to be passed by copy, not reference.

      This is not at all some sort of esoteric task - launching threads with nontrivial local arguments is pretty basic, there's millions of use cases for something like this. Here it is in C++11:

      std::thread([=](){ do_something(a,b); )).detach();

      Little short line of code. Surely for such an obvious, non-esoteric task, C can't be much harder, right? Any takers?

      (Don't bother responding if your code can't meet all of the boldface conditions... in the real world, you can't simplify the system requirements to meet the deficiencies of your coding language)

      --
      "Are you hungry? I haven't eaten since later this afternoon." -- Primer
    59. Re:Write-only code. by Anonymous Coward · · Score: 0

      Good point.

      Everyone on here is coming to save C++ with the "stupid people right stupid code".

      Linus and others are looking at the architecture of C++. It is bad, period. Sure people can do some amazing things, but no diff from PHP, which is also architecturally bad.

      It a short term tool to do complex things, but nowhere near a long term framework for robust systems. Pyhton and Matlab have eclipsed C++ for that nowadays.

      I'll stick with C/Java and assembly--if you're talking bare metal performance.

    60. Re:Write-only code. by Dogtanian · · Score: 2

      The more powerful the language, the more it's like a loaded gun: You can use it responsibly and do amazing things with it, or you can put a bullet through your foot with it. Choice is yours... and the closer you get to bare metal with the language, the greater the chance of lead meeting foot at high speed.

      Oddly, that brings to mind the famous quote from Bjarne Stroustrup himself...

      "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off"

      I've only briefly looked at C++, but when I did, I understood what he meant. C++ lets you do some very complex, powerful and abstract things compared to C, but even in the small amounts I learned (and have since forgotten) you could see the potential for an overly confident smartass to misuse or fail to understand the subtleties of these features and have things go wrong in a manner that was far more convoluted, non-obvious and hard to debug in a sadistically high-level manner than simply overflowing some poxy buffer.

      AFAIK (and IIRC!) Java- which came after C++- is in many respects *less* powerful and more constrained in terms of what you can do (or at least makes you do it more explicitly) and some criticised this as dumbing down for industry that wanted "quantity over quality" programmers. Maybe so, but would you want to deal with some horribly subtle bug that was ten levels of abstraction away, all because some naive just-out-of-college programmer did something a bit too clever for his own good when overloading an operator?

      Now that I think about it, I remember reading criticism of C#'s increased flexibility in operator overloading (compared to the language it was mostly a clone of, Java) as being A Bad Thing for the same reason.

      --
      "Slashdot - News and Chat Sites Deviant". (Click "homepage" link above for details).
    61. Re:Write-only code. by BlackHawk-666 · · Score: 1

      The behaviour is deterministic, it always provides you with a memory location which contains whatever random garbage was previously there. This is actually a useful feature, since c++ doesn't require you to initialise every single variable prior to use.

      Most times I try and declare and initialise a variable at the same time, but there are still cases where you might need to declare it outside an if-else statement and don't want to waste cycles pushing a null value into the memory before you then overwrite it with the actual value you need.

      As for marking every variable declaration with "uninitialized" - do we really need more typing in programming? No thanks!

      --
      All those moments will be lost in time, like tears in rain.
    62. Re:Write-only code. by Carewolf · · Score: 1

      However elsewhere there are problems. Ie, G++ and MSVC++ implement things very differently, depending on the versions and such. Ie, the contents of the v-table, location of the v-table in the object, etc. You've got both a function pointer plus a "fixup" offset to account for multiple inheritance, or thunks, whereas most OS kernels prefer to just have a simple array of function pointers which are capable of being easily used from most any language that follows the CPUs ABI (including assembler). It works on Linux because for a very long time g++ was the only offering and the newer options intentionally remain g++ compatible, whereas elsewhere this may not be true at all.

      It works somewhat on Windows as well as compilers there try to be drop-in upgrades to MSVC. And on OS X since they were using gcc before clang, and clang and gcc agrees on C++ ABI (though mixing libc++ with libstdc++ is not possible since they conflict on definitions).

      C++ ABI is not a real problem anymore. They might not be as similar between platforms as the C-API but they are defined on each platform as much as makes sense for the platform.

    63. Re:Write-only code. by Anonymous Coward · · Score: 0

      C macros are not Turing complete. There is no way that anyone that has spent any significant amount time writing C or C++ could fail know that. This is a typical fallacy that I see often in the judgement of programming languages. Any language that is significantly different from what you are used to is difficult to read. Whenever I try to read Russian I find it impossible. This is an apt comparison be I do not know Russian just like this poster does not know C++. I have tried to learn Russian a few times but have never gained any fluency. Russian may or may not be a difficult language to read. I actually do not know. Unfortunately, this poster does not realize that not knowing C++ he is not qualified to have an opinion on whether C++ is difficult to read. Most likely he is mostly basing his opinion the experience of others, but if that is the case he should be honest and attribute his opinion to his source rather than looking like a fool when it is discovered that he does not know what he is talking about.

    64. Re:Write-only code. by praxis · · Score: 1

      It's both. Type import this from the interpreter, and you'll get this:

      The Zen of Python, by Tim Peters

      Beautiful is better than ugly.
      Explicit is better than implicit.
      Simple is better than complex.
      Complex is better than complicated.
      Flat is better than nested.
      Sparse is better than dense.
      Readability counts.
      Special cases aren't special enough to break the rules.
      Although practicality beats purity.
      Errors should never pass silently.
      Unless explicitly silenced.
      In the face of ambiguity, refuse the temptation to guess.
      There should be one-- and preferably only one --obvious way to do it.
      Although that way may not be obvious at first unless you're Dutch.
      Now is better than never.
      Although never is often better than *right* now.
      If the implementation is hard to explain, it's a bad idea.
      If the implementation is easy to explain, it may be a good idea.
      Namespaces are one honking great idea -- let's do more of those!

      While it doesn't always manage it, if you read the discussions and PEPs relating to the language's design it's clear that the idea of a "Pythonic" way of doing things is one of the top considerations.

      All of what you stated is convention, documentation and community-agreed definition of Pythonic. One can write Python that compiles and works that you will have trouble reading. One generally doesn't because when learning the language, the community and documentation lead one to a more Pythonic path.

      Yes, I'm quibbling over words, not disagreeing that the idea of Pythonic code isn't useful or cool.

    65. Re:Write-only code. by ChrisMaple · · Score: 4, Funny

      The(nice(thing(about(Lisp(is(I(don't(have(to(use(it))))))))))).

      --
      Contribute to civilization: ari.aynrand.org/donate
    66. Re:Write-only code. by LoneTech · · Score: 1
      Neither. The first calls compute() only once per orn, and the second makes the list population clearer (and less error prone). So go for

      borbs = [b for b in map(compute, orns) if b > 12]

      The map can be replaced with another comprehension or generator expression, but at that point I'd place the filter condition on a separate line to call attention to it. This particular combination is a weakness in the comprehension syntax because the output expression can't be named for use in a condition, so we must nest. Breaking it up in two stages may also be viable.

    67. Re:Write-only code. by sjames · · Score: 1

      Yes, you SHOULD use that for casting, but you don't HAVE to.

      In C, you CAN define a base struct that includes an enum specifying the correct type but you certainly don't have to.

      That is, C++ offers a convenient way to do it right but doesn't require it, so it remains easy to cast incorrectly and do a crash and burn.

    68. Re:Write-only code. by Anonymous Coward · · Score: 0

      haha if the kernel was type safe, it would probably lose 10-20% performance

    69. Re:Write-only code. by Anonymous Coward · · Score: 0

      In Java, there is only the one way of writing things. You can architect them differently if you want, but there's usually one way to write them

      For example there are at least 10 was to iterate over a list in Java, without counting the additions in Java 8. With the additions from Java 8 your assertion is fucked in so many cases its not even funny.

      And let's not even talk about macros which is one more way to write things. You can actually write your whole program only through macros. Macros are turing-complete. They're just a language inside the language... This is pure madness.

      Macros are only Turing complete if you do include hackery, so you must mean templates. You know what I call a vector<int> ? convenient. What do you call it in Java? Impossible, you have to write a new vectorInt class ( which a lot of libraries do), or use vector<Integer> ( which is a list of references to objects, about 6x memory overhead, null pointers and a lot of indirection and casting). Special casing generic code for every existing primitive is a pain - and I had to do that a lot.

      Also Turing completeness is overvalued, a lot of really sad languages can be proven Turing complete since the definition gives any program infinite time, space and instructions ( you can simply brute force every possible computation with an infinite list of instructions, no need for branches, jumps, loops, recursion).

    70. Re:Write-only code. by phantomfive · · Score: 1

      Who does that?

      --
      "First they came for the slanderers and i said nothing."
    71. Re:Write-only code. by spitzak · · Score: 4, Informative

      The sample code will copy a and b twice, once to put them in the lambda closure, and then to pass them as arguments to do_something. Some may consider this wasteful (the easiest fix is to modify do_something to take the values as const references).

      This is the general problem with C++, in that the shortest code is often the slowest. Adding const references to the declaration of do_something would remove the useless extra copy. The slowness is visible in C, where you would probably allocate a structure containing the copy of a and b, and have pthread_create call a function that copies them to the arguments to do_something and calls it, then deletes the temporary structure. This is equivalent to what the C++ compiles into but all the inefficiency is visible. This is the primary complaint about C++ verses C.

      PS: I use C++ all the time and prefer it over C. But you do require a good knowledge of what it turns into, often stated in a pseudo-C, to figure out how and why things work and why slight variations (try using [&] instead of [=] in your lambda!) break in horrific ways.

    72. Re:Write-only code. by spitzak · · Score: 1

      "int i; printf( "%d", i );"

      Most compilers are capable of producing a warning that you are using an uninitialized variable in this case.

    73. Re: Write-only code. by Anonymous Coward · · Score: 0

      I doubt your code will ever compile with that ')' instead of '}'

    74. Re:Write-only code. by spiralx · · Score: 1

      All of what you stated is convention, documentation and community-agreed definition of Pythonic.

      My point was that it's not just the community of people using Python, but that it's also part of the community of people who design Python, and has been from the start. The latter feeds into the former, and then vice versa, and without both sides you end up with at best where JavaScript is today - intense focus on making code better, but every single avenue has multiple options and you end up with a bewildering array of choices.

    75. Re:Write-only code. by spiralx · · Score: 1

      It depends :)

      If compute() is a "heavy" function, then the plain loop is the best, although I'd probably use the

      borbs = [b for b in map(compute, orns) if b > 12]

      construction LoneTech posted earlier.

      If it's a small function in a throwaway script then probably just

      borbs = [compute(orn) for orn in orns if compute(orn) > 12]

      as you posted.

      How about something like

      from itertools import dropwhile

      def compute(l):
          for i in l:
              yield i * 2

      borbs = list(dropwhile(lambda b: b <= 12, compute(orns)))

      :D

    76. Re:Write-only code. by Rei · · Score: 4, Insightful

      The sample code will copy a and b twice, once to put them in the lambda closure

      Only without optimization flags enabled. Otherwise the lambda will be inlined in most cases.

      This is the general problem with C++, in that the shortest code is often the slowest

      Compared to what alternative C algorithm? Still waiting here.... ;)

      Beyond that, that's not how you optimize a program. You don't try to optimize the heck out of every last line; that's a recipe for an unmaintainable mess that's not actually that fast. You write clean, organized code, you profile it, and then you optimize where the profiling data tells you that you can make the biggest improvement. Trying to be "clever" and outsmart the compiler with every line of code "in the interest of performance" is how spaghetti code gets made

      The slowness is visible in C, where you would probably

      To reiterate my first post:

      Show me the code (emphasis: show me actual code, don't just say "... this is how I'd do it" and a rough description

      Yes, I knew exactly that people like you would come in and try to pass off a rough description as an implementation. The reality is that the implementation is such an utter, bug-prone PITA in C (compared to a trivial command in C++) that most people don't even bother. Which means that code gets underthreaded, which means that it performs terrible and is prone to lockups.

      Threading is of course just the start here...

      --
      "Are you hungry? I haven't eaten since later this afternoon." -- Primer
    77. Re:Write-only code. by spiralx · · Score: 1

      That is something that would be a nifty construct. About the closest I can think of off the top of my head is using a nested generator expression

      borbs = [b for b in (compute(orn) for orn in orns) if b > 12]

      Which isn't too awkward IMO, it's pretty clear there's two stages: a map and then a filter, and it's more readable than e.g.

      borbs = list(filter(lambda b: b > 12, map(compute, orns)))

    78. Re:Write-only code. by niftymitch · · Score: 1

      I'm not a Linux programmer so I may be out of date on this, but there isn't or wasn't a single C++ ABI on Linux between the various compilers. If the kernel used C++ for those interfaces it would potentially require that the kernal and all kernel modules were compiled with the same toolchain. Rolling their own implementation means the ABI is compatible across all the different compilers and compiler version with a side benefit of being able to write kernel modules in languages other than C/C++.

      The Gentoo crowd had a hoop or two to jump through to get from one version of gcc to another way back when.
      Compilers and ABI designs are important -- the fuzzy rules for ARM ABIs is holding ARM back for some.

      Linus may be correct from where he sits. A lot of where he sits is atop a massive
      pile of C and history written in C going back to Minix and other versions of Unix -- all of which
      were built with and on C.

      Some of the microkernel designs could have a leg up and the close to hardware
      bits could be isolated from upper layers that could be crafted in another language.

      So if you want to start over and build from the ground up... who knows.
      But today "C" is the anchor for the pile of stuff that Linus sits on.

      --
      Truth is stranger than fiction, but it is because Fiction is obliged to stick to possibilities; Truth isn't. Mark Twain.
    79. Re:Write-only code. by Alomex · · Score: 3, Interesting

      Sorry, but the original Lisp got quite a few things wrong itself and by the time it got around to fixing it had missed the boat. Here's a sample

      1. the only data structure available is the list. Scheme includes arrays and so much better for it
      2. it doesn't have pointers, which means it is hell to build a complicated but very efficient data structure like threaded trees
      3. (it(has(too(many(parenthesis) ) ) ) ). In part because it attempts to operate under the illusion that a function call like (ADD 1 2) is the same as the list (ADD 1 2) which it isn't and hence the setq and ' rigamarole. In fact back when Lisp was first introduced its creators thought that not long from there a version 2.0 would be introduced using more standard notation, like ADD(1,2) or even, _gasp_ 1+2.
      4. The main flow control structure is recursion. Recursion can be very nice and elegant, but there are times where one needs a for loop or a while loop, and one can either shoe horn it under recursion, or simply make the language richer and include those control structures (see again Scheme) for things are best understood as a for or a while loop.
      5. variables were a bit of a kludge which lead to juggling of partial results into function parameters

      If modern Scheme had been introduced in 1965 instead of 1975 we might be today programming in some modern dialect of Lisp.

      Now some fanboi will come and explain why these things aren't a bug but a feature in 3, 2, 1

    80. Re:Write-only code. by Coryoth · · Score: 1

      Write-only code is easy in ANY syntax.

      Write-only code is possible in any language. Some languages make it easier than others.

    81. Re:Write-only code. by sjames · · Score: 1

      I've done that. It's not that out there.

      Others use per-type link/unlink functions declared inline.

    82. Re:Write-only code. by Bent+Spoke · · Score: 1

      When you know a language well, there's no problem writing good code in it. But truly few can claim to know C++ well enough to make that assertion. The language is far too big and complicated and provides too many ways to do the same thing.

    83. Re:Write-only code. by spitzak · · Score: 5, Informative

      The sample code will copy a and b twice, once to put them in the lambda closure

      Only without optimization flags enabled. Otherwise the lambda will be inlined in most cases.

      BZZT! Wrong! Think: what happens if a and b are local variables and the function creating the thread returns before the lambda runs? They must be copied to somewhere that is not destroyed by the caller returning. That copy is not in the correct location because they are created before the thread stack, so another copy is unavoidable. The only way to fix it is to make do_something take const references. Though it is true that if do_something was inline it would probably fix it.

      Show me the code

      Yes it is ugly and I never claimed otherwise. The problem is that C++ compiles into the equivalent of this and it is hidden behind the scenes. Here is is pretty obvious that I must not pass a pointer to a or b, not so clear in C++:

      #include <pthread.h>
      #include <stdio.h>
      #include <malloc.h>
      #include <unistd.h>

      void do_something(int a, int b) {
          printf("do_something %d %d\n", a, b);
      }

      typedef struct {
          int a, b;
      } lambda_args;

      void* lambda_run (void *p) {
          lambda_args* v = (lambda_args*)p;
          do_something(v->a, v->b);
          free (v);
          return 0;
      }

      void thread_do_something (int a, int b)
      {
          lambda_args* v = (lambda_args*)malloc(sizeof(lambda_args));
          v -> a = a;
          v -> b = b;
          pthread_t thread;
          pthread_create (&thread, 0, lambda_run, v);
      }

      int main()
      {
          thread_do_something(1, 2);
          thread_do_something(3, 4);
          sleep (1);
          return 0;
      }

    84. Re:Write-only code. by Darinbob · · Score: 1

      An ABI is supposed to be independent of platform. So what C++ has is mostly a gentleman's agreement about what happens on particular turfs.

    85. Re:Write-only code. by kwbauer · · Score: 1

      True, but the c# compiler allows the same thing, declaring without initializing and then initializing in an if-else statement, but complains if you never get around to setting a value in before you try to get a value out.

    86. Re:Write-only code. by ceoyoyo · · Score: 1

      Yup. Simple C++ code is a bit ugly, but it's readable. Even using the straight STL is fine - there's a lot of useful stuff in it. The problem with C++ seems to be that people just can't seem to prevent themselves from being smartasses. Oh look, I can do this, and then this all happens automagically! You just have to remember to.

    87. Re:Write-only code. by Anonymous Coward · · Score: 0

      (You missed a pair of parens)

    88. Re:Write-only code. by MikeBabcock · · Score: 1

      I was thinking the same thing -- I've even used kernel code to explain certain C techniques to new programmers.

      --
      - Michael T. Babcock (Yes, I blog)
    89. Re:Write-only code. by Anonymous Coward · · Score: 0

      The(Bad(Thing(About(C++(Is(This(Could(Be(A(Valid(C++(Program(Depending(On(Your(Compiler(Options(And(Macros)(

      It's true in some other languages as well, but C++ developers actually make use of it.

    90. Re:Write-only code. by Anonymous Coward · · Score: 0

      BZZT! Wrong!

      I wonder if you could have explained that without being a total douche about it.

    91. Re:Write-only code. by exomondo · · Score: 1

      Note that C++ isn't necessarily type safe either. It's not at all difficult to cast an object pointer to the wrong type and crash. It's no harder than it is in C.

      Of course not, that should be pretty obvious to anybody that understands that C++ is a superset of C (clue is in the title), it wouldn't really be a superset then would it? But if you're interested in strict type safety then you wouldn't be doing static (c-style) casts and if you need to do type-casting you would be using C++'s dynamic_cast.

    92. Re:Write-only code. by exomondo · · Score: 1

      Yes, you SHOULD use that for casting, but you don't HAVE to.

      Of course you don't have to, do you really need to be corralled and work in a padded environment to force you to do things correctly? If so then C++ is not the language for you, in fact programming probably isn't for you.

    93. Re: Write-only code. by Anonymous Coward · · Score: 0

      He is correct. Calling him names doesn't make him less correct.

    94. Re:Write-only code. by VerdantHue · · Score: 1

      Racket is being taught: http://programbydesign.org/

    95. Re:Write-only code. by Anonymous Coward · · Score: 0

      The problem is, almost no-one fully understands C++11/14/etc. You find people who would be considered language experts, by most standards, having to ask questions on arcane intersections with other parts of the standard. Have a look at C++11 questions on stackoverflow - half the time, the answer comes from people who are either on the std / working group committees, or have a professional interest in language lawyer-ing. Far too often the standard is ambiguous, and the issue is filed away as platform-specific or UB, rather than being recognized as a need for more rigour in the standard.

    96. Re:Write-only code. by Megane · · Score: 1

      It works really well for embedded programming, especially when you don't have a heap. And anywhere you would consider using a bunch of function pointers, using virtual methods instead will make for a lot cleaner code. Also, classes can be used as an API for hardware devices, something I learned after being introduced to mbed.

      --
      #naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
    97. Re:Write-only code. by prsephton · · Score: 1

      The problem with C++ is that it's way too easy to write write-only code, because the language has so many features that nobody but language experts understand all of them. So we all program in different dialects, and then scratch our heads when we read other peoples' code.

      The English language has such a large vocabulary that no one may possibly be expected to simultaneously comprehend the whole of it...

      Yet it is possible to express yourself concisely in the subset of your choice.

      Write-only code is not the fault of the language, but that of the programmer.

    98. Re:Write-only code. by Megane · · Score: 1

      Also the fragile base class problem.

      --
      #naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
    99. Re:Write-only code. by wonder_wonder · · Score: 1

      Good point you have. I cringed a bit when Java got multiple ways of writing for loops.

    100. Re:Write-only code. by Pinhedd · · Score: 1

      #include
      #include
      #include

      typedef struct
      {
                      void (*function)(int,int);
                      int argA;
                      int argB;
      } threadargs_t;

      pthread_t threadA, threadB;
      void dosomething(int a, int b)
      {
      printf("this is something: %d %d\n",a,b);
      }

      void dosomethingelse(int a, int b)
      {
      printf("this is something else: %d %d\n",a,b);
      }
      void* thread_entry(void* args)
      {
      threadargs_t* threadargs = (threadargs_t*)args;

      (*threadargs->function)(threadargs->argA,threadargs->argB);
      free(threadargs);
      return NULL;
      }

      int main(int argc, char** argv)
      {
      int localA = 0, localB = 1, localC = 2, localD = 3;
      threadargs_t* threadA_args = malloc(sizeof(threadargs_t));
      threadargs_t* threadB_args = malloc(sizeof(threadargs_t));
      threadA_args->function =
      threadA_args->argA = localA;
      threadA_args->argB = localB;
      threadB_args->function =
      threadB_args->argA = localC;
      threadB_args->argB = localD;
      pthread_create(&threadA,0,&thread_entry,threadA_args);
      pthread_create(&threadB,0,&thread_entry,threadB_args);

      fgetc(stdin);
      return 0;
      }

    101. Re:Write-only code. by Pinhedd · · Score: 1

      Bah, formatting got screwed up again. Here's another attempt.

      #include <stdio.h>
      #include <stdlib.h>
      #include <pthread.h>

      typedef struct
      {
              void    (*function)(int,int);
              int     argA;
              int     argB;
      } threadargs_t;
      pthread_t threadA, threadB;
      void dosomething(int a, int b)
      {
      printf("this is something: %d %d\n",a,b);
      }
      void dosomethingelse(int a, int b)
      {
      printf("this is something else: %d %d\n",a,b);
      }
      void* thread_entry(void* args)
      {
      threadargs_t* threadargs = (threadargs_t*)args;
      (*threadargs->function)(threadargs->argA,threadargs->argB);
      free(threadargs);
      return NULL;
      }
      int main(int argc, char** argv)
      {
      int localA = 0, localB = 1, localC = 2, localD = 3;
      threadargs_t* threadA_args = malloc(sizeof(threadargs_t));
      threadargs_t* threadB_args = malloc(sizeof(threadargs_t));
      threadA_args->function = &dosomething;
      threadA_args->argA = localA;
      threadA_args->argB = localB;
      threadB_args->function = &dosomethingelse;
      threadB_args->argA = localC;
      threadB_args->argB = localD;
      pthread_create(&threadA,0,&thread_entry,threadA_args);
      pthread_create(&threadB,0,&thread_entry,threadB_args);
      fgetc(stdin);
      return 0;
      }

    102. Re:Write-only code. by Uecker · · Score: 2

      Little short line of code. Surely for such an obvious, non-esoteric task, C can't be much harder, right? Any takers?

      (Don't bother responding if your code can't meet all of the boldface conditions... in the real world, you can't simplify the system requirements to meet the deficiencies of your coding language)

      Somebody else answered this already and I prefer the C solution. But this example seems rather contrived anyway. Let's do something much simpler: Write a matrix multiplication routine for arbitrary-sized matrices which is not allowed to use the heap.

      void mat_mul(int A, int B, int C, double out[A][C], double in1[A][B], double in2[B][C])
      {
          for (int i = 0; i A; i++) {
              for (int k = 0; k C; k++) {
                    out[i][k] = 0.;
                    for (int j = 0; i B; j++)
                      out[i][k] += in1[i][j] * in2[j][k];
                }
          }
      }

    103. Re:Write-only code. by Anonymous Coward · · Score: 0

      The first rule of programming is: "Do I need to write it?"

      Many many people assume that C++ is naturally better than C, when the reverse is actually true. Straight C is better than C++, but in the same context, you can also say straight Assembly is better than C. It's a matter of how much fine control is needed, and how much performance is wasted.

      In a system kernel, or a device driver, you want as little non-C code as possible, because this is code that is going to remain resident in memory and not change. You can't just swap out pieces while it runs, especially if the linkage changes.

      Where C++ is useful is primarily where "object oriented" programming makes logical sense. Anywhere where data organization can be arranged as containers it can be used, but the question is "should it?" If performance is vital (again, System kernel, drivers, and some system "daemons" that poll hardware that require precise timing, it's better to stick to straight C.

      To give an idea. stuff like LibPNG or FFMPEG can be written in C++, and have C bindings and they are no more worse for wear, because you're never going to use these components in the system kernel. Where people get into trouble is when they use C++ bindings, because the libraries will never be "reusable" anyway, so you may as well just statically link the whole damn thing.

      Like... we do "need" a new programming language that is easy to understand (C is mostly easy to understand, Javascript is mostly easy to understand, everything else out there is a mess because it relies on OOP principles that you just can't get people to understand.)

      Like here's the thing with HTML. People don't understand how it works because when HTML came out, people were still printing calendars using spreadsheets. So the logical derived from that was that everything must be a table and fit together like square puzzle pieces. Now things changed to everything is a container, and the "DOM" now actually makes sense.

      The compulsion to keep writing wrappers and frameworks needlessly needs to stop though. This is bad behavior in Javascript/HTML land, and it's painfully error-prone in C/C++ land.

      Not invented here - the compulsion to write your own stuff (or wrap things so you throw your own style of logic on top,) even when someone else has a perfectly acceptable license to a library that already does what you want AND the source code is available to strip it down to just what you need.
      Invented here - The compulsion to seek a third party library to do everything, even tiny things that may only take 10 lines of code, but you load in large bloated libraries (not even stripping them down to the part you need)

      jQuery+plugins in html/javascript land is the worst offender for this, and this behavior is creeping heavily into Java and C++

    104. Re:Write-only code. by sjames · · Score: 1

      *I* don't, but some of those people Linus was talking about probably do.

      My point isn't that C or C++ have bad type safety (or good type safety for that matter) just that if type safety is a real concern for you, C++ isn't really going to leave you better off than C. In either one, the compiler won't save you if you make a type related error. Note that dynamic_cast adds a RUNtime test, the compiler still doesn't save you.

    105. Re:Write-only code. by TheRaven64 · · Score: 1

      An ABI is supposed to be independent of platform

      Absolutely not! ABIs are part of the definition of a platform. The Itanium C++ ABI is more or less the same on all (non-AArch32) *NIX systems, but the C ABIs are very different. For example, the C ABI on x86-32 on FreeBSD will pass a union of a pointer and an integer in a register, the Linux ABI will pass it on the stack.

      --
      I am TheRaven on Soylent News
    106. Re:Write-only code. by TheRaven64 · · Score: 3, Insightful

      This is true. On Linux, the only compilers that I know of that use the same C++ ABI as gcc are clang, ICC, XLC, ARMcc, Open64 and Path64. If you're using something else then you may encounter problems.

      --
      I am TheRaven on Soylent News
    107. Re:Write-only code. by TheRaven64 · · Score: 1

      For example "int i; printf( "%d", i );" and you have a code with undefined behavior. At runtime it'll print a random number even though you never called rand() to indicate that's what you wanted.

      This is a feature, not a bug. If uninitialised variables were default-initialised to some value, then this code would still be buggy, but now your compiler / static analyser would not be able to tell you that it contained a bug.

      if you need that behavior for some reason make it "uninitialized int i; printf( "%d", i );"

      If you don't want that behaviour, then initialise the value at the declaration. Coding styles typically discourage initialising with a sentinel though, because you lose the ability for your compiler to check that you've assigned the correct value on every code path.

      --
      I am TheRaven on Soylent News
    108. Re:Write-only code. by TheRaven64 · · Score: 1

      You might want to look at the std::array template in C++11. It lets you do exactly this, only with compile-time checking of the arguments that the lengths match. Actually, you can skip the A, B, C parameters because your function template would be able to extract them from the .size() of the matrix parameters.

      --
      I am TheRaven on Soylent News
    109. Re:Write-only code. by Anonymous Coward · · Score: 0

      15 lines of code, most of it not in line to the method creating the thread, vs. a one liner. Not a single line of error handling, if thread creation fails you just ignore it and leak some memory. Classical C code.

    110. Re:Write-only code. by Anonymous Coward · · Score: 0

      (->> it use to have don't I is Lisp about thing nice the)
      Which doesn't make any sense, but You don't make any sense either.

    111. Re:Write-only code. by Anonymous Coward · · Score: 0

      Yeah, ASTs are so difficult to understand and having a tree-based editor to edit these trees doesn't help at all. Better to have a weird English-esque language and 300 pages of translation rules how this English sentence gets transformed into an AST /s

      That weird anti-learning attitude in programming circles is really getting old.

    112. Re:Write-only code. by Anonymous Coward · · Score: 0

      This is a potential problem with every single programming language ever. No exceptions. C is somewhere in the middle with that risk, but it is no where near the worst. I'd give that medal to Perl.

      The more powerful the language, the more it's like a loaded gun: You can use it responsibly and do amazing things with it, or you can put a bullet through your foot with it. Choice is yours... and the closer you get to bare metal with the language, the greater the chance of lead meeting foot at high speed.

      I'd compare C to a handgun and C++ to a shotgun. It's much harder to accidentaly shoot yourself in the foot with the shotgun. But when you do ...

    113. Re:Write-only code. by goose-incarnated · · Score: 3, Interesting

      I found, after decades of experimentation, that simplicity and consistency beats everything else if you want to produce reliable software. Now, I use C exclusively just so I don't have to deal with multiple different ways to do something because the C++ standards committee got a bee in its bonnet about the latest hot new concept that first came out in 1959 and was forgotten until last year.

      The problem with possessing multiple ways to solve a problem is that every developer takes it as a personal challenge to find and use all the different ways. To make things easier I simply wrote a library containing those things that I usually need (sane string operations, c/line parsing, vectors, etc) and found that 90% of what you can do with X lines of fairly complex grammar in C++ can be done with around 1.5X of straightforward C grammer. I don't need the remaining 10% if it needs 300% cognitive effort to get.

      The library is here: Extended C library, libxc, so help yourself (BSD license)

      .

      Documentation is over here: PDF link, but html available, although the documentation on the website is out of date. If you download the library source you get the full up-to-date docs.

      --
      I'm a minority race. Save your vitriol for white people.
    114. Re:Write-only code. by ChunderDownunder · · Score: 1

      Dan Grossman's Coursera offering has Racket as one of the languages too.

      https://www.coursera.org/cours...

    115. Re:Write-only code. by Anonymous Coward · · Score: 0

      That rule has always struck me as being an odd one in Python, because for many use-cases I've never seen so many ways of doing things in other languages. As an exercise, count the number of features that Python has for dealing with the lack of multi-statement anonymous functions.

      A comparison with Ruby would be apples to apples and while I don't like Ruby, I find it extremely ironic that in a language that supposedly followed the TIMTOWTDI philosophy of Perl, the choices one has to make are much more clear-cut. And this extends far beyond language features, but to the libraries available in the ecosystem. Python's ecosystem, starting from the build tools and going to high-level frameworks, is a complete clusterfuck.

      From my point of view, Python isn't simple, or easy, or powerful, or elegant. And whenever another language is advertised "like Python", I personally run.

    116. Re:Write-only code. by goose-incarnated · · Score: 3, Informative

      (Don't bother responding if your code can't meet all of the boldface conditions...

      Challenge accepted, see here for my first go that satisfies all the bolded conditions. Any further conditions you impose now will make you look even more like an ass than you already do for posing such a fanboyism challenge. Note well: there are literally only four lines of code to achieve this - I posted the other lines to give the readers some context.

      struct foo_t {
      size_t one;
      size_t two;
      };

      void *do_something (struct foo_t *array)
      {
      printf ("%zu, %zu\n", array[0].one, array[1].two);
      }

      #define THREAD_CREATE(fptr, type, a, b) do {\

      // Start of challenge
      type array[] = { a, b };\
      pthread_t tmp;\
      pthread_create (&tmp, NULL, (void *(*) (void*))do_something, array);\
      pthread_detach (tmp);\

      // End of challenge, you're welcome
      } while (0)

      int main (void)
      {

      ...
      struct foo_t first, second;
      ...
      THREAD_CREATE (do_something, struct foo_t, first, second);

      ...
      ...
      }

      in the real world, you can't simplify the system requirements to meet the deficiencies of your coding language)

      As you can see above, no deficiency found - in the actual real world, as opposed to the one populated by inexperienced fanboys like yourself, the above solution would not be discarded from the solution set if it meant changing the codebase from C to C++.

      You can now be an adult about the whole thing, accept that what you can do in C++ can be done in a readable manner in C as well. I don't think you will, though - I have a feeling you'll come up with another idiotic "C++ can do this, can C do this?" question, at which point I will once again be happy to smack you in the face with a solution like I did just now.

      Consider yourself schooled.

      --
      I'm a minority race. Save your vitriol for white people.
    117. Re:Write-only code. by Anonymous Coward · · Score: 0

      Scheme does have a preprocessor, it's the macro expander.

    118. Re:Write-only code. by silentcoder · · Score: 1

      This is generally one of the things I love about python. The pythonic way of coding really does encourage simple, readable code.
      That said occasionally you can run into annoyances.
      I had a case a few months ago where two code reviewers couldn't stop arguing about one of my classes.

      One insisted that getters and setters are not pythonic and should be removed. The other insisted that this class had special case considerations and not only should it use getters and setters but the attributes they get and set should be private so that anybody who does want direct access will be forced to use the private path to them and have to justify doing so in a comment. (Personally I agreed with the former reviewer - I did not believe the case was special enough to justify coding it in such an unpythonic way)

      After three days of watching them argue I finally resolved the issue by dropping a few convenience methods and replacing the class with a NamedTuple. Which they both passed, ironically of course, the guy who was insisting on getters and setters never considered that using a NamedTuple removed the possibility of them and enforced direct attribute access as the only way (which is, in fact, the pythonic way).
      Generally these days I work on the basis that any class which does not need other methods should be a NamedTuple unless there is a good reason for it not be. A one-line implementation that is well understood just reduces the potential for bugs by too much not to use it when you can.

      --
      Unicode killed the ASCII-art *
    119. Re:Write-only code. by Anonymous Coward · · Score: 0

      Java is quite simple at its core, way simpler than C++.

      If you really think Java is just as complex, you haven't understood at least one of these languages.

    120. Re:Write-only code. by silentcoder · · Score: 1

      And this version has the massive advantage that if compute is very expensive and safe to parallelize then you can do a simple drop in replacement of map with Multiprocess.Pool.Map and get it powerfully done in parallel with very little effort or risk of introducing bugs.

      --
      Unicode killed the ASCII-art *
    121. Re:Write-only code. by serviscope_minor · · Score: 2

      This is the general problem with C++, in that the shortest code is often the slowest.

      Well, that's better than the general problem when the shortest code in C normally leads to a crash or a memory leak. Yep, if you copy structs-with-pointers around like containers willy-nilly you soon screw up and get a leak or a segfault.

      The other thing of course is that you have 1 line ot find the slowness, not 30 as in the C code.

      --
      SJW n. One who posts facts.
    122. Re:Write-only code. by serviscope_minor · · Score: 1

      You're confusing simplistic with simple.

      If you write numerics code, for example, Java is a nightmare whereas in C++ it looks pretty close to the maths written on the page. The C++ code is much simpler precisely because the language is less simplistic.

      Macros are turing-complete. They're just a language inside the language... This is pure madness.

      Yeah I know, right? I mean the idea that a programmer might want to program the compiler to automate common tasks is just Evil, Bad and Wrong and possibly also Cruel and Unusual.

      --
      SJW n. One who posts facts.
    123. Re:Write-only code. by Anonymous Coward · · Score: 0

      Aww. Now you went and destroyed the virginity of his Standard Challenge. From now on he has to introduce the challenge as "Here's my standard challenge for C people - I've given it many times in these sort of threads and once got a real response that meets the specs."

    124. Re:Write-only code. by silentcoder · · Score: 1

      >Are there many ways to skin a cat? Sure, but they're all going to involve cats and skin.

      Except that in C++ there are at least three ways where the cat is replaced with a badger and skinning it involves clipping it's toenails while brushing it's teeth.

      --
      Unicode killed the ASCII-art *
    125. Re:Write-only code. by Anonymous Coward · · Score: 0

      However, Scala seems to he the second coming of Lisp. Sadly, it is being mandated in my workplace. Scala is the ugly child of c++ and lisp.

    126. Re:Write-only code. by Anonymous Coward · · Score: 0

      i {
          don't {
              know {
                  why {
                      this {
                          is {
                              considered {
                                  to {
                                      be {
                                            better;
      }}}}}}}}}

    127. Re:Write-only code. by Rei · · Score: 5, Informative

      BZZT! Wrong! Think: what happens if a and b are local variables and the function creating the thread returns before the lambda runs?

      BZZT! Wrong yourself! And let this be a lesson to you to not be so haughty when replying. What you describe never happens. The lambda is built synchronously, but called asynchronously.

      To prove it, try out the following code:

      #include <iostream>

      void do_something(int a, int b) { std::cout << a << b; };

      int main(int argc, char** argv)
      {
      int a = 12, b = 23;
      ([=](){ do_something(a,b); })();
      }

      Compile it with "g++ --std=c++11 -S -O4" and check out the .S file (compare it to the -O0 version too). In the -O4 version you'll see the following:

      main: .LFB1262:
      leal 4(%esp), %ecx .LCFI6:
      andl $-16, %esp
      pushl -4(%ecx)
      pushl %ebp .LCFI7:
      movl %esp, %ebp
      pushl %ecx .LCFI8:
      subl $12, %esp
      pushl $23
      pushl $12
      call _Z12do_somethingii

      You see that? It's pushing the local values directly onto the call stack. There is no intermediary step for the lambda.

      Okay, so maybe my test case was too simple? Let's complicate it.

      #include <iostream>
      #include <stdio.h>

      void do_something(int a, int b) { std::cout << a << b; };

      int main(int argc, char** argv)
      {
      int a, b;
      scanf("%d", &a);
      scanf("%d", &b);
      std::cout << 34;
      #if 0
      ([=](){ do_something(a,b); })();
      #else
      do_something(a,b);
      #endif
      }

      Try it again with -O4 with the if set to 0 or 1 and compare the two versions together. You'll see that they're exactly the same. In both cases, main is:

      main: .LFB1262:
      leal 4(%esp), %ecx .LCFI6:
      andl $-16, %esp
      pushl -4(%ecx)
      pushl %ebp .LCFI7:
      movl %esp, %ebp
      pushl %ecx .LCFI8:
      leal -16(%ebp), %eax
      subl $28, %esp
      pushl %eax
      pushl $.LC1
      call scanf
      popl %eax
      leal -12(%ebp), %eax
      popl %edx
      pushl %eax
      pushl $.LC1
      call scanf

      --
      "Are you hungry? I haven't eaten since later this afternoon." -- Primer
    128. Re:Write-only code. by Rei · · Score: 0

      Sorry, but first off, you didn't meet the spec. I'll repeat:

      do_something(Foo a, Bar b) (emphasis: two arguments, arbitrary size)

      And:

      (Don't bother responding if your code can't meet all of the boldface conditions... in the real world, you can't simplify the system requirements to meet the deficiencies of your coding language)

      You changed the spec to try to make the task easier for you. In the real world, you can't do that. "do_something" is often, say, a library call.

      Secondly, your code is broken. You're passing a pointer to a local variable as your argument to a thread, which runs asynchronously, and thus has no guarantee that the local variable will still exists when it runs.

      Thank you once again for demonstrating why C is such a terrible language, as with the other attempted responses in this post. Every time people try this simple challenge for a common task, they come up with these gigantic pieces of code that leak.

      --
      "Are you hungry? I haven't eaten since later this afternoon." -- Primer
    129. Re:Write-only code. by goose-incarnated · · Score: 1

      Sorry, but first off, you didn't meet the spec. I'll repeat:

      do_something(Foo a, Bar b) (emphasis: two arguments, arbitrary size)

      Reread my solution - there's more than two arguments. I predicted you'd change the constraints once they were met, but you aren't even doing that, you're ignoring your own spec.

      And:

      (Don't bother responding if your code can't meet all of the boldface conditions... in the real world, you can't simplify the system requirements to meet the deficiencies of your coding language)

      Firstly, in the real world you don't get to change languages based on something that is easily fixable in the current language with three extra lines of code (6 extra lines if you fix the errors in your spec). Secondly, I adhered to the spec - you said two local arguments passed by copy - that's what I did. If there were additional restrictions I would have met those two, because those of us with real CS degrees from a real university already know that one turing-complete language is equivalent to another turing-complete language.

      You changed the spec to try to make the task easier for you. In the real world, you can't do that. "do_something" is often, say, a library call.

      Then you should have specified in your spec, in which case add these three lines to the solution which now addresses your extra constraints:

      void *kickoff_twin (struct foo_t *array) {
      do_something (array[0], array[1]);
      }

      Secondly, your code is broken. You're passing a pointer to a local variable as your argument to a thread, which runs asynchronously, and thus has no guarantee that the local variable will still exists when it runs.

      That's what your one line example did, and I've already read the previous poster handing your ass to you because you did not realise that you made this mistake in the first place. Since the spec called for compatibility with the C++ example you gave, I gave you bug-for-bug compatibility.

      Thank you once again for demonstrating why C is such a terrible language, as with the other attempted responses in this post. Every time people try this simple challenge for a common task, they come up with these gigantic pieces of code that leak.

      Your "challenge" has thus far had 3 different successful solutions. They all adhered to your requirements. And, as a matter of fact, I just have you 3 extra lines that even adhere to your brand-new made-up-because-you-got-your-ass-handed-to-you requirements.

      --
      I'm a minority race. Save your vitriol for white people.
    130. Re:Write-only code. by gnupun · · Score: 1

      Your solution is not practical either. If "orns" were a huge array, "mid" would consume a lot of time and memory. Instead, OP's solution with the large for loop is the best answer, although it looks ugly.

    131. Re:Write-only code. by Anonymous Coward · · Score: 0

      You just won. Thank you for being here.
      Your information was insightful. (This is not sarcasm.)

    132. Re: Write-only code. by alecb · · Score: 1

      > those of us with real CS degrees from a real university already know that one turing-complete language is equivalent to another turing-complete language. Troll/10

    133. Re:Write-only code. by Anonymous Coward · · Score: 0

      Your C code leaks memory if pthread_create fails.. THE main benefit IMHO of C++ is deterministic finalization which allows smart pointers and RAII/RRID. Anything that requires memory allocation or dealing with mutex locks etc in an exception safe manner is simplified. And yes the code generated by the compiler is hideous. But to provide the same guarantees in C code results in a sprawling mess, especially if you need to also deal with SEH.

    134. Re:Write-only code. by Anonymous Coward · · Score: 0

      You above code does not work using gcc 4.8 and the --std=c++11 option yields this error message:
      error: 'thread' is not a member of 'std'

    135. Re:Write-only code. by jeremyp · · Score: 1

      To be fair, the one liner didn't do any error checking either.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    136. Re:Write-only code. by Anonymous Coward · · Score: 0

      If it turns out to be slow in your application (profile!) you are probably better of making a and b std::shared_ptr and writing:

        "std::thread([=](){ do_something(*a,*b); )).detach();"

      This will work, fast, and is completely safe.

    137. Re:Write-only code. by Anonymous Coward · · Score: 0

      To be fair, I want you to write the same code using the c++03 standard and not the c++11. Linus made the comment in 2007, so c++11 was not available. You will find that the C++ code will look similar to the C code.

      Putting that aside, you will also find that not all C++ compilers implement this in a bug-free way. So now you must debug not just your code but your compiler.

      Worse is the fact that a typo in that line will produce several screens of errors which may or may not indicate the issue. For example, what would be the error messages if b were a pointer? Missing a single character (*) would produce numerous errors many of which are spurious.

    138. Re:Write-only code. by gatkinso · · Score: 1

      Elegant means nothing if the code is shit. Poco is a prime example of this. Beautiful interface and API's... that suck balls when you actually use them.

      --
      I am very small, utmostly microscopic.
    139. Re:Write-only code. by gatkinso · · Score: 1

      Were a and b moved or copied? In your example we can't know.

      --
      I am very small, utmostly microscopic.
    140. Re:Write-only code. by Anonymous Coward · · Score: 0

      Ze vord is "assembly" my dear German friend

    141. Re:Write-only code. by Anonymous Coward · · Score: 0

      Clang can do this in an C when using the caveat of blocks extension and the libdispatch library.

      dispatch_async(myQueue, ^{
              do_something(a,b);
      });

    142. Re:Write-only code. by Anonymous Coward · · Score: 0

      'All features of C++ have their uses and it's possible and necessary to master them all.'

      Hopefully you are joking, but if you are serious about this, then you are the poster child for what is wrong with C++.

      Used with restraint, it is a useful and powerful language.
      Without retrtaint as you suggest it is makes code the mere mortals find unreadable.
      If you do this in a big enough code base it becomes unmaintainable.

      Please tell me you are joking.

    143. Re:Write-only code. by serviscope_minor · · Score: 5, Insightful

      because the C++ standards committee got a bee in its bonnet about the latest hot new concept that first came out in 1959 and was forgotten until last year

      Give one example of that ever happening. The C++ standards committee is notoriously conservative which is why the language evolves so slowly. This comes across as you just making shit up when you haven't got a clue.

      The problem with possessing multiple ways to solve a problem is that every developer takes it as a personal challenge to find and use all the different ways.

      That might be *your* problem but it isn't mine. Every decent place (staffed by true scotsmen of course) with project teams has things like coding standards and code reviews.

      If your developers are committing crap code to the mainline then the trouble is that (a) your developers and (b) your process sucks. The thing is it will suck in any language.

      The library is here: Extended C library, libxc, so help yourself (BSD license)

      OK, I'll bite.

      Well, if you think having XVEC_DEREF(some_vector, i, float) for resisable arrays but array[i] for builtin ones is better than having array[i] for both, well, then I guess we're just on completely different pages here.

      The thing is there's massive syntactic overhead to your code. And the overhead is more like 1000% not 150%.

      vector<float> = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9};

      works perfectly in C++, whereas that's 10 lines of C code!

      And I was wondering how it worked underneath, and I had to dig into the code. So you're storing pointers to the elements, not the elements themselves! I never even realised that. Wow, so that means you can't even do:

      xvector_ins_tail(tfar, &1f);

      You have to do:

      some_float_which_has_the_same_scope_as_tfar_and_is_never_reused = 1;
      if(!xvector_ins_tail(tfar, &some_float...))
      { //Do something error related here //probably a longjmp or goto. //Don't forget to free all that memory!
      }

      versus:

      tfar.push_back(1.5);

      It also means you're in nightmare memory management from hell since you now have to manage all those bits of memory by hand.

      It *also* means that you have no memory locality since it's a big array of pointers, so performance will almost certainly be bad as well.

      The equivalent C++ code to your xvector/main.c is something like:

      vector<float> sfar = {1.1, 2.2, ...};
       
      for(const auto& f:sfar)
        cout << f << endl;
       
      eg_t eg[] = {...};
       
      vector<eg_t> teg, sub;
      for(const auto& e:eg)
        eg_t.push_back(e);
       
      for(auto e:teg)
      {
        e.i += 2;
        e.f -= 5.0;
        sub.push_bach(e);
        cout << "Returning " << e.i << " // " << e.f << endl;
      }
       
      //Well, the nativea bit is basically already working in the C++ code since internally, std::vector uses a native array

      And that gets us to line 90 or so. There's more, but you missed the error checking for if something isn't found in the xvector. It also took me a while to verify that all the allocations are matched by the respective free. It would be nearly impossible to be sure for less trivial code.

      So, I'm not convinced you've made a case for C over C++ here.

      --
      SJW n. One who posts facts.
    144. Re:Write-only code. by Anonymous Coward · · Score: 0

      The [linux] kernel loses BADLY

      Compared to C++ kernels, like the NT one?

      Yes, let's use NT kernel for our servers, because it's so well engineered :)

      This C vs C++ bullshit is pretty much vi vs emacs. There are not winners in this wall, just a lot of autism.

    145. Re:Write-only code. by gatkinso · · Score: 1

      Oh come on now. It isn't all that complicated.

      --
      I am very small, utmostly microscopic.
    146. Re:Write-only code. by Anonymous Coward · · Score: 0

      Kernel people explicitly refuse to keep ABI compatibility inside kernel, as they only promise ABI compatibility for user space applications.

    147. Re:Write-only code. by mvdwege · · Score: 1

      The only point still valid is point 3, and that's a matter of taste.

      The ANSI standard is Common Lisp, and it addresses all your points. Wake up and smell the coffee, the 50s are over.

      --
      "I know I will be modded down for this": where's the option '-1, Asking for it'?
    148. Re:Write-only code. by internerdj · · Score: 1

      STL was a dirty word in the CS program I attended. It wasn't introduced until the very last day and it was essentially: Here are some standard classes to use or not. My first job I was the lone developer and I rolled a lot of stuff on my own. I feel bad for whoever has to maintain that code now because instead of using well-used, presumably well-tested STL classes there are a bunch of one off classes that are used in one package written by one very young developer with no tester. I may lose something for leaning on the STL stuff but I've gained a whole bunch of testers as well. That last part usually goes a lot further than anything I'd get from rolling my own.

    149. Re:Write-only code. by Anonymous Coward · · Score: 0

      System.Threading.Tasks.Task.Run(delegate { do_something(a,b); });

      I know you meant C people, but I find C# to be far better than either C or C++ due to exactly the reasons you're stating and exactly the reasons the GP stated. It's the best of both worlds. You get the safety of not using C++ and the flexibility of not using C.

      (And it should be noted that my code meets the boldfaced conditions because the "use C" restriction isn't one of them.)

    150. Re:Write-only code. by Yunzil · · Score: 1

      It is not complex by any reasonable definition, unless you're comparing it to BASIC or something. Part of the reason Java is ugly is that it's so simple, in fact - it eschews syntax sugar and various conveniences that'd make the code shorter and prettier.

      Let me guess: you're a Java developer.

    151. Re:Write-only code. by Anonymous Coward · · Score: 0

      I'm just an anonymous asshole, but I'm mentally modding you up to the sky.

      Your BZZT debunking is both accurate and brutal. Well done.

    152. Re:Write-only code. by Yunzil · · Score: 1

      On the contrary, if you don't think Java is just as complex, it's you that hasn't understood at least one of these languages.

    153. Re:Write-only code. by tobiasly · · Score: 1

      Good heavens, this was the best discussion I've seen on Slashdot in a LONG time. Bravo, you just won the internet for today.

    154. Re:Write-only code. by friesofdoom · · Score: 2

      I know debugging templates in c++ can be challenging for a rookie, but at least they /are/ debuggable. I'd like to see someone trying to debug some of those crazy macros... Talk about read-only code!

    155. Re:Write-only code. by serviscope_minor · · Score: 1

      An ABI is supposed to be independent of platform.

      Why? What possible benefit would there be to sharing the same ABI on Windows 10 and an Arduino?

      So what C++ has is mostly a gentleman's agreement about what happens on particular turfs.

      Nope, it has a collection of standards. Just like programming on unix has the ISO C standard and the POSIX C standard. Having C++ added in also adds in the Itanium ABI standard.

      --
      SJW n. One who posts facts.
    156. Re:Write-only code. by serviscope_minor · · Score: 1

      There should be one-- and preferably only one --obvious way to do it.

      Almost every language offers multiple ways of doing just about everything. Think about iterating over an array. You can:

      Use some sort of automatic list handling function, e.g. map.

      List comprenehsions.

      Use a for loop from 0 to size-1.

      Use a range based for loop.

      Use recursion.

      That's 5 ways of doing even the most basic thing and are common to almost every language. There's never ever EVER EVER EEEVVVEEERRR only one way of doing anything.

      Ever.

      --
      SJW n. One who posts facts.
    157. Re:Write-only code. by Uecker · · Score: 1

      Not at all the same thing. This would give me templatic code for static - not dynamic - arrays.

    158. Re:Write-only code. by friesofdoom · · Score: 1

      The shortest code in C leads you to MACRO_HELL.

    159. Re: Write-only code. by Uecker · · Score: 1

      It will also throw a runtime exception with my default version of g++ if I don't add a '-pthread' line. Why is this not a compile time error? Insane.

    160. Re: Write-only code. by Anonymous Coward · · Score: 0

      Care to elaborate? Seems good to me but I'm a novice.

    161. Re:Write-only code. by Anonymous Coward · · Score: 0

      > The(nice(thing(about(Lisp(is(I(don't(have(to(use(it))))))))))).

      Pfft, Java programmer. Should have checked your code in the REPL before posting something that malformed.

      Here's 10 cents to go buy yourself a proper language.

    162. Re:Write-only code. by david_thornley · · Score: 1

      Which is one reason why C++ gives you abstraction features to stay away from the bare metal if you like. In C, an array is a raw chunk of memory, and if you pass it around all you've got is a pointer into it and a type. You don't have a size. You access elements in a way that's defined in terms of pointer arithmetic (and leads to expressions like 2["abcde"] being perfectly legal, unless they've changed that in later standards). Memory off the heap is referred to by a pointer, with no check to see if the memory is ever freed, or if it's freed twice. Strings are character arrays with strange functions operating on them.

      In C++, you would normally use std::vector instead of an array, which has defined properties and can easily do range-checked access (and Stroustrup, in his "The C++ Programming Language" shows how to make the usual array notation checked access). Strings are done by std::string, which is another case of a (badly designed) library-defined type that's easy and intuitive to use. Memory off the heap is normally referred to by smart pointers, which prevent double-freeing and the use of dangling pointers, and make it hard to actually leak memory.

      With C, you're always fairly close to the metal. C++ lets you get considerably further away.

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

      some naive just-out-of-college programmer

      Working for a company that typically hires people just out of college, that's what standards and code reviews are for. We typically don't get weird bugs out of them (well, no more often than with the more experienced people).

      As far as Java goes, when I last looked at it there were things in it less safe than their C++ counterparts. (Please correct me if things have changed.) Data structures tended to be defined as structures of Object or some subordinate object, losing strong type safety, while in C++ you'd typically use a templated container class that knew the type of its elements.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    164. Re:Write-only code. by KingMotley · · Score: 1

      System.Threading.Tasks.Task.Run(()=>do_something(a,b));

    165. Re:Write-only code. by david_thornley · · Score: 1

      C++ can do pretty much anything C can do, so it can indeed be type-unsafe. However, it's easier to write type-safe code in C++.

      Don't use C-style casts. Use the C++ awkward-looking casts, which specify more precisely what the cast is doing and are much more visible and findable. This includes dynamic_cast, which has some type safety built into it.

      Use C++ library algorithms. Those are generally type-safe. C's qsort() is a lot less type-safe than C++'s std::sort.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    166. Re:Write-only code. by gatkinso · · Score: 1

      (Hmm, actually, the answer is obvious... after some study of move semantics).

      --
      I am very small, utmostly microscopic.
    167. Re:Write-only code. by david_thornley · · Score: 1

      Since I don't know exactly what those defines do, do they keep track of type in the container? If you use a push macro to push an int onto the stack, and a pop macro to pop a double from the stack, is the compiler going to catch it?

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    168. Re:Write-only code. by Anonymous Coward · · Score: 0

      The proliferation of macros makes C++ utter shit, end of story.

    169. Re:Write-only code. by david_thornley · · Score: 1

      Your printf() example works precisely the same in C. I don't know why you're bringing it up as a C++-specific problem.

      Most compilers will warn about i being uninitialized if they can (it's undecidable in general whether i will be given a value before being used), so I'd suggest that this is a quality-of-implementation issue.

      There's also errors like "int i; printf("%f", i);", which C++ iostreams will avoid completely (not that I recommend them for all purposes).

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

      There's a pretty concrete idea of what "Modern C++" is, also, and that's generally pretty readable and safe. I don't see an advantage to either C++ or Python here.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    171. Re: Write-only code. by Anonymous Coward · · Score: 0

      when did telling the truth become trolling?

    172. Re:Write-only code. by david_thornley · · Score: 1

      Dialects of Lisp differ. Common Lisp is an ANSI standard, so let's go with it.

      Common Lisp has a lot of data structures built in, which include arrays. It also has built-in iteration support. Not everybody likes the loop macro, but there are other ways to iterate.

      Most languages don't have pointers in the C sense. All Lisps I know of have pointers in the Java sense, in which they're there and very common and never referred to. I don't know what you mean by this.

      I don't understand what you mean by variables either. Putting partial results into function parameters is pretty much necessary for functional programming, no matter how you're doing it. Is it that you don't like functional programming? If so, you can use Common Lisp without it, but you're missing some good stuff.

      The parentheses are there for a reason. (Yes, I'm going to call this a feature.) Having lists be evaluated as function invocations makes it very easy to add user-defined types that work like the built-in ones, and makes it very easy to do code generation. Lisp macros are much like C++ templates, but with far better syntax. Macros are extremely powerful in practice, and make it easy to add things to the language. In "On Lisp", Paul Graham devoted one chapter, not particularly long, to making Common Lisp object-oriented because he didn't seem to like the Common Lisp Object System. The reason there was no version 2.0, which was abandoned over fifty years ago, was that people realized that it wasn't a good idea.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    173. Re:Write-only code. by The_Informant · · Score: 0

      I was under the impression that if you are not Linus Torvalds and writing Kernels & modules, embedded code, or drivers then C++ does memory management. With C you have to write the code to handle memory and if done incorrectly you will have security issues, crashes, or buffer overflows. Therefore, if you don't care about the size of the program, C++ is the way to go. Linus is also right for what he does. Like most good programmers, he avoids trends albeit he's obsessive about it, he sticks to what he knows and that made him very good at C programming.

    174. Re:Write-only code. by Anonymous Coward · · Score: 0

      Little short line of code. Surely for such an obvious, non-esoteric task, C can't be much harder, right? Any takers?

      Actually, it can. Because that is OS-dependent. Not part of C, to my knowledge.

      Hence, "you are not even wrong."

      This doesn't sound like a language issue at all, just you seem confused what is part of the OS
      and what is not.

      Show us all the assembly and C and whatever else code your little line does behind the scenes, that
      someone else wrote, that you just call.

      If you want to argue syntax that is one thing. But to pretend "just one line of code" has anything to do with "can't be much harder" and the fact your "one little line" is not one little line at all...

      Threads are an OS-specific thing. That is why there are POSIX threads and Windows does their own thing...there is no standard definition of what a "thread" is.

      Your "challenge" makes no sense. What would make sense:

      -- show us how, for your operating system/kernel, using C++ is cleaner for supporting threads than C
      -- show us how, for your operating system/kernel, using C++ is cleaner for implementing a "fork()" function than C

      Then we could actually compare.

    175. Re:Write-only code. by Anonymous Coward · · Score: 0

      The reality is that the implementation is such an utter, bug-prone PITA in C (compared to a trivial command in C++)

      That is not "implementation" that is "calling someone else's code"

      If you want to argue C++ has this as "standard" and C does not have threads as a "standard" feature AT ALL then make that argument.

      To argue over something that is not even in C ... you might as well argue that ASCII sucks donkey balls because it has no "not equal" sign, unlike EBCDIC or some other ancient encoding that includes
      that character standard.

      My lord, != is SO MUCH MORE WORK.

      Your challenge still makes no sense, cherry-picked.

    176. Re:Write-only code. by spiralx · · Score: 1

      I think I know what you mean - once you get "under the hood" there really are ways to customise everything. Metaclasses, abstract base classes, descriptors, descriptors, context managers, types, properties... all on top of plain-old multiple inheritance ;) It does take some time and restraint to not go meta-overboard - if I feel myself doing it, I just remember (trying to) work with Zope, which takes this sort of thing to a ridiculous extreme.

      All that stuff came way later though, for going from zero to code Python is pretty simple - you don't need all that stuff for 98% of use cases.

    177. Re:Write-only code. by spitzak · · Score: 1

      Um you might try passing the lambda to a function that takes a std::function as an argument, rather than just directly executing it. It is nice that the compiler optimizes the direct call but that is not what the thread creation does.

    178. Re:Write-only code. by Anonymous Coward · · Score: 0

      And you might want to learn the basics of optimization, the first rule is, "don't try to outsmart the compiler at every turn".

      Rule number 2 is "don't assume g++ everywhere"

      You have said absolutely nothing about C++. Sound and fury, signifying nothing.

      Is g++ the official C++ compiler now, available everywhere? Or are you just making up wild stories still?

      Just continuing to make up cherry-picked examples, are we?

      Great, g++ of a specific version happens to work like you say, for your CPU. That is nice, they optimized to a suitable level for you.

      Even if I was a C++ programmer, I wouldn't listen to you, because you are trapped in your own world, and think everyone else's world is the same as yours.

    179. Re:Write-only code. by spitzak · · Score: 1

      You are correct that the lamda_args object is leaked.

    180. Re:Write-only code. by shutdown+-p+now · · Score: 1

      By your definition of ABI, then, C doesn't have a stable one, either.

    181. Re:Write-only code. by spiralx · · Score: 1

      After three days of watching them argue I finally resolved the issue by dropping a few convenience methods and replacing the class with a NamedTuple.

      Ah, the namedtuple, love that type, makes small property bags simple and efficient, and yet you still go nuts and sub-class it if you really have to :) Can't remember what I did before it appeared - write a lot more classes, most likely.

      *checks*

      Looking at my user-site directory, apparently write my own Properties class - actually, three different classes for some reason, all slightly different and way more complicated than the namedtuple :)

      My only niggle is the declaration syntax with the redundant type name

      Point = namedtuple("Point", "x y")

      which just looks ripe for danger lol.

    182. Re:Write-only code. by shutdown+-p+now · · Score: 1

      This is a feature, not a bug. If uninitialised variables were default-initialised to some value, then this code would still be buggy, but now your compiler / static analyser would not be able to tell you that it contained a bug.

      Arguably, this is a design defect. It would have been a feature if initializer was required, but there were some way to indicate that you don't want to initialize it just yet, e.g. "int i = undefined". The number of cases where you want to declare a variable but initialize it later on are dwarfed by the number of cases where you want to initialize it immediately, so for the sake of safety the language should be geared towards the former.

    183. Re:Write-only code. by Anonymous Coward · · Score: 0

      Passing by value was a requirement. It's possible that passing by const reference into do_something might cause synchronization problems between threads. Yes, the threads running do_something can't change the variables, but it is possible the main thread could later. Without knowing more, it's difficult to say what was the best solution or not. Rei might want to see if using lambda capture by reference would improve performance (measure, measure, measure!), though I strongly suspect he (she?) is correct that the compiler is able to optimize this away.

    184. Re: Write-only code. by spitzak · · Score: 2

      His code is constructing a lamda as a local value, not copying it anywhere, and directly calling it, then destroying it. When the call is done every detail of the lambda is known precisely, and this can be optimized (apparently g++ does so, too).

      The original post constructs a lambda and passes it by value to the thread constructor and then exits before the lambda is used. This requires a and b to be copied. Later the forked thread executes the lambda. It is highly unlikely the locations of a and b in the lamda structure are in the memory location that the lambda function looks for them, so they must be copied (and memmove is explicitly not allowed by C++, you must use the copy or move constructor).

      The fix is to make do_something take the arguments as const references, which are really pointers, and then the lambda caller can just make the pointers point at where a and b are in the lambda structure.

      C++ would have been helped considerably if all arguments to functions were const references (with the compiler allowed to choose whether to copy or make a reference depending on which is more efficient). You could use volatile to make a non-const reference if needed (though most code I have seen use a pointer for out parameters). This apparently would break too much code, but is by far the biggest source of unexpected inefficiency in C++ and really should be fixed rather than having the code writers decide whether a copy or reference is faster.

    185. Re:Write-only code. by Anonymous Coward · · Score: 0

      > Oh come on now. It isn't all that complicated.

      The language itself isn't so bad, it's all the esoteric stuff the argument above illustrates... a "simple" thread solution that the "experts" here can't agree whether a given solution is broken or not. This is why programming is such a minefield, and your language of choice can't save you.

      Seriously, everytime I pick up a programming book these days and it covers the basics like variables, conditional expressions, iteration, recursion, etc. and I wonder "how the hell do you get from this beginner's crap to knowing how to write production code?"

      There's a huge learning gap in the "journeyman" stage of the trade, where it's almost impossible to learn the ropes on your own. You need a mentor who has been through the flames and come out on the other side, charred but still standing!

    186. Re:Write-only code. by spiralx · · Score: 1

      True, but you can generally get by with learning one way while learning, then expand options later. For a lot of Python IMO the complexity is very well-hidden from a beginner, and little things like the help() and dir() functions make life easier.

      Couldn't live without IPython now though, I've been totally spoilt by auto-call, ? and ??, the history tools, the ed command, etc etc....

    187. Re:Write-only code. by spiralx · · Score: 1

      Use a generator function for mid instead, then values will only be pulled out one-by-one as needed.

    188. Re: Write-only code. by suy · · Score: 1

      Ironically, many (if not all) the usability issues that you mention that C++ could change, are nearly impossible to fix due to the C legacy. But having C as legacy is also a big strength: you can use native OS APIs with ease.

    189. Re:Write-only code. by spitzak · · Score: 1

      No, the lambda must not take the arguments by reference. This is because the original values can be destroyed before the lambda is run, invalidating the references.

      do_something can take them by reference, the lambda calls it and the lambda is not destroyed until after it returns.

      I think the job of figuring out which is more efficient should belong to the compiler, but this would require C++ to be redefined such that all arguments are possibly const references (ie a function cannot modify it's own arguments, or perhaps modification forces a copy inside the function).

    190. Re:Write-only code. by TheRaven64 · · Score: 1

      Huh? You want on-stack arrays, std::array gives you an on-stack array. You want to pass them to a function, a template function that takes std::array references would work fine.

      --
      I am TheRaven on Soylent News
    191. Re:Write-only code. by Grishnakh · · Score: 1

      I found, after decades of experimentation, that simplicity and consistency beats everything else if you want to produce reliable software. Now, I use C exclusively just so I don't have to deal with multiple different ways to do something because the C++ standards committee got a bee in its bonnet about the latest hot new concept that first came out in 1959 and was forgotten until last year.

      The problem here is that you're missing out on a lot of really useful features that C++ has, which can make programming simpler and need less boilerplate code (just look at all the fake-OO stuff in the Linux kernel for example).

      The key is that while C++ does have a LOT of features, some of them questionable, you aren't forced to use any of them. It's entirely possible (and even common in some software shops, especially ones doing embedded coding) to use a stripped-down subset of the C++ language. I've heard it called "C with classes". Take a look at the DO-178 standard for C++ coding sometime.

      The problem with possessing multiple ways to solve a problem is that every developer takes it as a personal challenge to find and use all the different ways.

      This isn't a problem. Go to any company doing avionics software in C++ and look at how they do it: they have a published coding style which basically forbids large swaths of C++'s feature set (including exceptions). Developers simply aren't allowed to use any of these! And to make sure they don't, all the code is code-reviewed by other developers to make sure it meets the coding standard. Anyone who insists on breaking the standard won't be working there for long.

      found that 90% of what you can do with X lines of fairly complex grammar in C++ can be done with around 1.5X of straightforward C grammer.

      Yes, so now you've inflated your SLOC by 50% for nothing just because you're too undisciplined to hold yourself to a C++ coding standard. That's 50% more lines where you can have bugs.

    192. Re:Write-only code. by gnupun · · Score: 1

      That is the most complex solution presented here and that too for a simple problem. Let's face it, Python list comprehensions are not perfect and are useful only for the most common cases. So unless they update the syntax to accommodate this use-case (i.e., no double compute() or extra temp list), it's simply easier to write and maintain the code using the for loop.

    193. Re:Write-only code. by Uecker · · Score: 1

      But the array dimensions would be template parameters - and not be dynamic.

      Also the type would look something std::array< std::array<double, 3 >, 3 > . This is a lot more complicated than int[3][3]. But again, I need int[A][B] where A and B are not constant. And this is a simple example, god forbid you need a temporary array on the stack... Maybe you can use alloca (which is not standard I think) and compute the array indices by hand.

      As far as I know, there is no good C++ solution. I guess this is the reason std::dynarray and runtime arrays have been proposed for C++14 (did one of them got in?).

    194. Re:Write-only code. by Darinbob · · Score: 1

      Hmm, gdb is making good progress debugging macros. Templates last I used them were very difficult in gdb, but presumably there have been improvements.

    195. Re:Write-only code. by Darinbob · · Score: 1

      By platform I meant CPU and operating system, as opposed just the CPU standalong. Windows 10 and Arduino have nothing in common, not even a CPU, so as an example that doesn't make sense.

      Ie, the PowerPC ABI & EABI are technically for System V, however they is used by just about everything OS available. This means you can share the same object library and it can work across operating systems (assuming the library is independent of the OS, for example a math or crypto lib). Similar for the ARM ABIs out there. Don't know about Itanium stuff as I haven't done PCs for decades.

    196. Re:Write-only code. by sjames · · Score: 1

      They link and unlink prev/next pointers built in to the objects. Since those pointers are type specific, you will get warnings/errors when you compile if you try to link the wrong thing into the container.

      So a foo_t struct will have prev/next pointers defined as pointer to foo_t. So if we have b, a pointer to bar_t and try to do insert(foo_head, b), the types mis-match.

    197. Re:Write-only code. by Anonymous Coward · · Score: 0

      Are you being intentionally obtuse?

      The original code was passing the lambda to another thread. The examples you gave which "prove" that the compiler can inline everything aren't passing the lambda anywhere, and especially not to a thread, which no compiler could optimize out.

      This is why I stick to C. You C++ programmers think you know more than you actually do. Like Perl programmers you spend way too much time dicking around with language features, of which C++ has too many.

      When C becomes too tedious, I switch to a different class of language entirely, like Lua. But for the low-level stuff it's much easier to reason about the C code. When you're dealing with threading especially, transparency is the most important quality you want in code.

    198. Re:Write-only code. by Anonymous Coward · · Score: 0

      The C++ ABI on Linux has _just_ changed. Not because of calling conventions, but because C++11 and C++14 require significant changes to many of the low-level data structures, including std::basic_string and std::list. See https://lwn.net/Articles/632118/

    199. Re:Write-only code. by Anonymous Coward · · Score: 0

      Worse is the fact that a typo in that line will produce several screens of errors which may or may not indicate the issue. For example, what would be the error messages if b were a pointer? Missing a single character (*) would produce numerous errors many of which are spurious.

      You mean, like this?

      int x=1, y=2;
      int *pointer =
      std::thread([=](){do_something(pointer, y);}).detach();

      Clang 3.5:

      main.cpp:14:20: error: no matching function for call to 'do_something'
                      std::thread([=](){do_something(pointer, y);}).detach();
                                                          ^~~~~~~~~~~~
      main.cpp:6:6: note: candidate function not viable: no known conversion from 'int *const' to 'int' for 1st argument; dereference the argument with *
      void do_something(int a, int b){
                ^
      1 error generated.

      GCC 4.8.2:

      main.cpp: In lambda function:
      main.cpp:14:43: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
          std::thread([=](){do_something(pointer, y);}).detach();
                                                                                            ^
      main.cpp:6:6: error: initializing argument 1 of ‘void do_something(int, int)’ [-fpermissive]
        void do_something(int a, int b){
                  ^

    200. Re:Write-only code. by Pieroxy · · Score: 1

      You choose not to use them but the day you're asked to maintain someone else's code full of macros, bang, you're in (or out if you choose to leave or refuse the project of course).

    201. Re:Write-only code. by Pieroxy · · Score: 1

      It's not Evil, Bad and Wrong, but it's way too powerful. It's so powerful you can actually write your entire program with macros. This means people (like beginners) might be tempted to get too much logic in there and shit happened right there that anyone maintaining the code will have to stir or rewrite.

      It's like operators overload and your numerics analogy. It's nice. Sometimes I wish i had it in Java because nicely used it's powerful. But then you can do crazy stuff with them that will confuse to hell most programmers trying to figure out what you wanted to do in the first place. That's the definition of write-only code.

    202. Re:Write-only code. by TheRaven64 · · Score: 1

      Well, fuck you Slashcode! Apparently I was using too many junk characters by having the temerity to post code snippets. Posting lots of mathematics also triggers it. Remember when this place used to be for nerds? Rather than try to work around the filter, I have placed the contents of my post here: http://pastebin.com/HtQXTnX0

      --
      I am TheRaven on Soylent News
    203. Re:Write-only code. by Stealth+Potato · · Score: 1

      Macros are also inherited wholesale from C and are discouraged (if not resolutely forbidden by good style guides) in C++, so calling them part of "the problem" with C++ seems unfair.

      And unless you count macros, the differences between C++ and Java in terms of "ways to write things" begin to disappear. C++ supports operator overloading and doesn't require you (mindlessly, IMHO) to place every function inside a class, but aside from that, you have many of the same options when it comes to structuring a given representation of a program.

    204. Re:Write-only code. by Alomex · · Score: 1

      First of all, I was giving some reasons why it didn't take off. Second Scheme/Lisp still doesn't have easy to use pointers to implement a threaded binary tree which is point (2). Third, point number (3) is not a matter of taste. This is like saying that not liking a shit sandwich "is a matter of taste".

      Lastly, the person who needs to wake up and smell the coffee is you: Lisp hasn't taken off. So clearly there must be powerful reasons why this is so. I listed some, and the way you deal with them is plain old denial. I've learned Lisp thirty years ago, and heard arguments like yours back then. With your attitude I can guarantee you that we will be having this same conversation in another thirty years.

    205. Re: Write-only code. by Anonymous Coward · · Score: 0

      "Yes, so now you've inflated your SLOC by 50% for nothing just because you're too undisciplined to hold yourself to a C++ coding standard. That's 50% more lines where you can have bugs."

      Yes, you should opt for the highest level of abstraction which will get the job done. Less code means less bugs

    206. Re:Write-only code. by Uecker · · Score: 1

      Yes, these are the C++ answers which I expected and they demonstrate the problem: You can only have static arrays which can live on the stack or dynamic arrays which then must live on the heap. My real world requirement (this is not a synthetic example) is to have dynamic arrays on the stack, because allocation overhead would be huge if you have to allocate temporary arrays each time you process a voxel of 3D volume. Of course, you could work around this ans pre-allocate the temporary memory outside of the loop, but this would unnecessarily complicate the design, especially when you then parallelize the loop. That C++ has no good way of doing this is simply a deficiency of the language.

      I don't think that putting this on the stack is "fundamentally wrong". First of all, it is 2015: 424 bytes are not much at all. You can have Gigabytes of stack and it does not matter. On all modern systems with a MMU, it is virtual memory, so if you don't use it it does not cost you anything. With multi-threading on 32 bit there is the risk that you can run out of address space (some compilers support split stacks for this reason). On 64 bit this issue simple does not exist any more. There is no reason whatsoever to not use the stack as much as you can.

      But even if you have bounded stack space for some reason (e.g. an embedded system without MMU), this not even a valid argument against VLAs at all. Dynamic arrays are not necessarily bigger than static arrays, or other stuff people are putting on the stack. In fact, the opposite is true: If you need to put things on the stack (see above) and do not have dynamic arrays, you would have to put an array of the maximally possible size on the stack. This is clearly worse.

      You have a minor point that heap allocation might give you a useful error while stack overrun might corrupt some other part
      of the memory. I do not think this is really true in practice though. For the following reasons:

      - Usually with memory overcommitment you would not get a allocation error even on the heap, but a SEGFAULT when accessing a new page which cannot be allocated. To get an actual memory allocation error you basically have to limit your heap size.

      - With a stack overrun you would also get a SEGFAULT which you can catch. You are right that there is the possibility to jump over the guard area with a large allocation, but remember, the guard area is virtual memory and on 64bit you can make it very big at no cost at all. Finally, if you really need to close this loophole, you could use a compiler which inserts run-time checks. So this is not a language-level problem at all.

    207. Re: Write-only code. by Grishnakh · · Score: 1

      Maybe, maybe not. Another factor you're missing here is performance. If you can do the job with fewer lines but in Perl or some other interpreted language, but the application calls for good performance, that's not a good idea. But C++ gives very good performance (good enough for high-performance games apparently) unlike a lot of other languages; you get C-like performance with a higher level of abstraction.

    208. Re: Write-only code. by Anonymous Coward · · Score: 0

      "If you can do the job with fewer lines but in Perl or some other interpreted language, but the application calls for good performance, that's not a good idea"

      Well then you would not be "getting the job done." Performance is one of the things to consider when evaluating how high level you should go. You wouldn't write an OS kernel in Java, hopefully.

    209. Re:Write-only code. by CamiloNino · · Score: 1

      This:

      float vector[9] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9};

      Compiles fine in GCC, and it doesnt use pointers, it assigns the values directly to the array (MOV instructions on the generated assembly code)

    210. Re:Write-only code. by spiralx · · Score: 1

      ... Python list comprehensions are not perfect and are useful only for the most common cases.

      I'm sure that Guido weeps himself to sleep every night knowing that this feature is only useful for 90% of use cases and not 100% ;)

      Sure they're not perfect, but as you say they work for most cases and when they don't they're easy to replace with your customised solution - perfect is the enemy of better, and list comprehensions definitely make Python "better" :)

    211. Re:Write-only code. by exomondo · · Score: 1

      My point isn't that C or C++ have bad type safety (or good type safety for that matter) just that if type safety is a real concern for you, C++ isn't really going to leave you better off than C.

      Of course it is, C++ has static_cast and dynamic_cast for example, C does not.

      In either one, the compiler won't save you if you make a type related error.

      Yes it will. Here I'm trying to cast a string to an int, are you actually telling me you think this compiles?

      std::string str("hello");
      int val = static_cast<int>(str);

      Note that dynamic_cast adds a RUNtime test, the compiler still doesn't save you.

      So? Who cares whether the compiler saves you or a runtime test saves you?

    212. Re: Write-only code. by Anonymous Coward · · Score: 0

      There should be a concerted effort by ISO to deprecate all headers of the cstdlib/cstdio/etc form, and have the compiler produce warnings that you appear to be nothing more than a C+ programmer.

      All new C++ code should avoid the legacy stuff as if it was hot lava. It was fine to allow C++ to compile C code in its early days but, if you want to be a C++ coder, embrace the C++ way of doing things.

    213. Re:Write-only code. by Anonymous Coward · · Score: 0

      For example "int i; printf( "%d", i );" and you have a code with undefined behavior. At runtime it'll print a random number even though you never called rand() to indicate that's what you wanted.

      This is a prime example of what they mean when they say "C assumes the programmer knows what he is doing." It will not hold your hand. Typically the C programmer is expected to know how to use a debugger.

      Spending too much time debugging? Write better code! :)

    214. Re:Write-only code. by Anonymous Coward · · Score: 0

      > Pfft, Java programmer.

      How about: AbstractThreadsafeNestedParensProxyFactoryInterface = new AbstractThreadsafeNestedParensProxyFactoryInterfaceGeneratorFactory.generateFactory();

    215. Re: Write-only code. by Anonymous Coward · · Score: 0

      "BZZT! Wrong" and "[you were being] a total touche" are more or less equivalent. Hence, we must ask whether one of these comments had more justification than the other?

      Although in the douche's favor, the rest of his comment was polite and extremely informative. So the question becomes, how much do you care about an impolite introduction?

    216. Re:Write-only code. by silentcoder · · Score: 1

      True, passing the Type name as a parameter when you're already assigning the output of the function to a class with the same name is less elegant than I would like.
      Though I suppose to avoid that would require a lot of introspection which, while perfectly possible in python should be avoided unless it's absolutely required because introspection is dangerous and can introduce very hard-to-fix bugs.

      --
      Unicode killed the ASCII-art *
    217. Re:Write-only code. by sjames · · Score: 1

      The runtime test doesn't necessarily save you. If the only option at that point is to crash, you haven't been saved. Thinking you are somehow safe because you used dynamic_cast is part of the problem.

      If the code is well thought out enough that it can salvage itself at that point, the programmer probably already thought the cast over three times before using it.

      Again, not saying it's necessarily bad, but there's no point in claiming type safety there.

    218. Re: Write-only code. by Anonymous Coward · · Score: 0

      (What (does(Lisp(have(to do(with(the price(of eggs(in China))))))))).

    219. Re:Write-only code. by serviscope_minor · · Score: 1

      Yeah, but then the vector isn't resizable, so it's not equivalent to the code the OP was talking about. The point was about his resizable array library versus the equivalent in standard C++.

      --
      SJW n. One who posts facts.
    220. Re:Write-only code. by Anonymous Coward · · Score: 0

      You're crushing my plan to use a global metaclass to enforce new types decorate all methods with custom descriptors provided by my GlobalNameProvider singleton, which uses the __new__ hack to ensure there's only one instance - having more than one would just be confusing! Anyway, as all objects are now within that object's __dict__, it can assign the variable name automatically based on the type name.

      Simple! Didn't even need abstract base classes ;)

    221. Re:Write-only code. by spiralx · · Score: 1

      Lol, it looks like i posted that anonymously in shame, rather than forgetting to login :)

    222. Re:Write-only code. by silentcoder · · Score: 1

      ...I am so hard right now...

      --
      Unicode killed the ASCII-art *
    223. Re:Write-only code. by mvdwege · · Score: 1

      I was not arguing that Lisp has taken off or should have taken off, so you can take that strawman and stick it up your arse.

      Secondly, since all but one of your points are factually untrue, that can't be why Lisp hasn't taken off. You are making points that do not support your argument, leading credence to the conclusion that you are merely trying to rationalise a personal dislike of Lisp. Nothing wrong with not liking a language, but at least do your audience the courtesy of being honest about it.

      Lastly, it is the height of stupidity to double down on a position when you have already proven that you do not know what you are talking about. No amount of impressive sounding words is going to hide your basic lack of knowledge of the development of Lisp since McCarthy's time.

      --
      "I know I will be modded down for this": where's the option '-1, Asking for it'?
    224. Re:Write-only code. by Anonymous Coward · · Score: 0

      Secondly, since all but one of your points are factually untrue,

      As a true fanboi, you get your panties all in a knot so much so that you cannot even read what I wrote.

      If you had you would have seen that I was explicitly describing and I quote "original Lisp [which] got quite a few things wrong itself and by the time it got around to fixing it had missed the boat" and then I refer to how by 1975 Scheme had addressed most of those but Lisp "had missed the boat".

      So if you want to know the height of stupidity is to come out all guns blazing when you haven't even read the original post, and then make a fool out of yourself in front of every one like you just did.

    225. Re:Write-only code. by mvdwege · · Score: 1

      Then don't write in the present tense if you don't want people to compare your points to the present state of Lisp. It's as easy as that.

      Here's a nickel kid. Go buy yourself a decent education.

      --
      "I know I will be modded down for this": where's the option '-1, Asking for it'?
    226. Re:Write-only code. by rdnetto · · Score: 1

      The problem with C++ is that it's way too easy to write write-only code, because the language has so many features that nobody but language experts understand all of them. So we all program in different dialects, and then scratch our heads when we read other peoples' code.

      Less so than C, especially as used in the kernel. Seriously read some of the Linux kernel and compare it with any good C++ project. The kernel loses BADLY. The manually implemented virtual classes are not pretty and not type safe, and neither are all the ugly macros needed to do things that would safe, automatic and easy to read in C++.

      I disagree completely - I think the issue you're dealing with is that the kernel is not written in C++, and its style reflects that. The kernel is one of the best written pieces of C I've seen, easily better than an average C++ project. IMO, the only feature that the kernel would really benefit from is templates (for added type safety) - everything else works fine.

      Furthermore, your argument about things being automatic in C++ is exactly the reason why most kernel developers use C instead! When you are writing a kernel, you absolutely do not want anything happening implicitly - it needs to be explicit, otherwise it's going to cause problems because it's not going to be obvious when it's interacting with something else. To give you an example, it's possible code in the block I/O subsystem to get stuck in an infinite loop upon allocating memory, since that request can result in paging, which results in disk operations via the block I/O subsystem, etc.

      Context: I have experience doing both kernel programming (in C) and application development (in C++ with Qt). I think C++ is a powerful language which can lead to some rather beautiful code when used with Qt. I also think that C makes it far too easy to write bad code (buffer overflows, null terminated strings, needing to check return codes without defining a consistent scheme for whether 0 is success or failure, etc.). For any other project, I'd go with C++ in a heartbeat (or maybe D, depending on what libraries I needed). But in the context of kernel development, C++ is definitely the wrong tool for the job.

      --
      Most human behaviour can be explained in terms of identity.
    227. Re:Write-only code. by rdnetto · · Score: 1

      There should be one-- and preferably only one --obvious way to do it.

      The problem with this rule is that it means limiting your feature-set so that you have N features with clearly defined regions of use, instead of 2N features with overlapping use cases. Switch statements are one example of this - they've been around since C (or possibly earlier) because they're clearer than a massive if-elseif-etc. statement, but Python lacks them, and people sometimes try to hack something similar into existence using dictionaries of lambdas.

      Another is Python supports both functional and imperative programming, which means there's inherently two different ways of performing many simple tasks. Obviously many other languages chose only one of these, and Python is clearly more powerful for having both, but it's a good example of how having more than one way to do things results in a more expressive language.

      --
      Most human behaviour can be explained in terms of identity.
    228. Re:Write-only code. by X · · Score: 1

      > So we all program in different dialects, and then scratch our heads when we read other peoples' code.

      The practice of programming in dialects is more a function of the origins of the language than the size of the language. Stroustrup's most recent book does a marvelous job of demonstrating how little you have to know to program in C++ effectively: http://www.stroustrup.com/prog...

      C++'s C compatibility is both its strength and its weakness, and the weakness primarily comes from people treating it as a bunch of add ons to C. If you scrap that attitude, it is entirely possible to be proficient in the language after a year of use and capable of reading most anyone's code (assuming they aren't shooting for obscurity) in another year or two. That's longer than some simpler languages, but it is hardly sufficient to excuse people's ignorance.

      --
      sigs are a waste of space
    229. Re:Write-only code. by X · · Score: 1

      > The sample code will copy a and b twice, once to put them in the lambda closure, and then to pass them as arguments to do_something. Some may consider this wasteful (the easiest fix is to modify do_something to take the values as const references).

      No, the easiest fix is for a & b to be moveable types, which they may well be, in which case one of those copies becomes a move, and all is right in the universe.

      --
      sigs are a waste of space
    230. Re:Write-only code. by trumpetplayer · · Score: 1

      > It is not complex by any reasonable definition, unless you're comparing it to BASIC or something.

      Java is significantly more complex than C, if only due to its OO nature.

    231. Re:Write-only code. by exomondo · · Score: 1

      The runtime test doesn't necessarily save you.

      Just doing a "test" is never going to save you no matter what that test is, that is obvious to everybody. I can c-style cast at runtime and have no idea whether it worked or not until I run it or - if im expecting that it can fail in some cases - I can do a dynamic_cast and test the result and not crash.

      Again, not saying it's necessarily bad, but there's no point in claiming type safety there.

      Rubbish, C++ offers type safety features where C does not. And this is an advantage that C++ has over C. I've already pointed out that you get static_cast which is checked at compile time and dynamic_cast that you can check at runtime so contrary to your assertion you are better off with C++ as it provides type checking features.

      It appears you're now trying to move the goal posts and say "well it isn't idiot-proof", and of course nobody ever claimed it was.

    232. Re:Write-only code. by dddux · · Score: 1

      I read that article completely and Linus' main point was not that C++ is a crap language, but that it's a computer language more susceptible to bad programming practices, which all of your posts more or less confirm. If you ask him, I think he would tell you exactly that, and it's the truth. C++ can be brilliant and awful at the same time, depending on who's "behind the wheel".

      --
      "It is no measure of health to be well adjusted to a profoundly sick society." - Jiddu Krishnamurti
    233. Re:Write-only code. by spitzak · · Score: 1

      That will not work out well if a and b are local variables. You will have to make a copy in order to make the std::shared_ptr point at them, so just as many copies are done as before (the second copy is when *a is copied to the argument to do_something, and, as before, can be avoided by making do_something take a const reference.

      The basic lambda [=] syntax will work better. First it makes only one pointer to a sort of box containing the copies of both a and b, rather than two pointers. Also it uses something much more like std::unique_ptr which is much more efficient.

    234. Re:Write-only code. by spitzak · · Score: 1

      You mean the caller has to do something like this (not sure of the syntax and I think it requires C++17)?

        std::thread([std::move(a), std::move(b)](){do_something(a,b);}).detach();

      Not sure if that is a good advertisement for C++.

      It would be nice if this happened automatically when possible, but apparently for complex language rule reasons it cannot. The following code must make a copy of A:

        void f() {
                ComplexThing A(FunctionReturningComplexThing()); // move
                DoSomething(A); // the copy is here
        }

      While this code, which seems like it should be what the above optimizes to, will only use move:

        void f() {
                DoSomething(FunctionReturingComplexThing());
        }

      That is annoying and the fact that such optimizations are not allowed is a good sign that there are problems with the design of C++.

    235. Re: Write-only code. by spitzak · · Score: 1

      C compatibility could be preserved by passing and POD and any structure containing only POD (no member functions and no private or protected data) always by copying. Since any more complex structure or class cannot be part of the C api it should not break compatibility if they were passed by const reference.

    236. Re:Write-only code. by sjames · · Score: 1

      You claimed the runtime saves you, I argued that it doesn't unless you take special measures to make it save you. I can take such measures as well in C as in C++.

      Who's moving the goalposts again?

    237. Re:Write-only code. by exomondo · · Score: 1

      You claimed the runtime saves you

      Stop being an idiot, you know damn well the ability to avoid a problem based on a test is predicated on acting on the result of that test and not the test itself. You've been proven wrong and now you're trying weasel words to get out of it.

      I can take such measures as well in C as in C++.

      Demonstrate how do you do that both at runtime *and* compile time then.

      Who's moving the goalposts again?

      I already told you that in my last post, it's you. But you're still wrong on both counts, if you use the language features you can get type safety at the compiler and/or runtime levels.

    238. Re:Write-only code. by spiralx · · Score: 1

      Wait until you see my new triple-underscore magic methods! That's 50% more magic, and you can see their jutting prows standing firmly erect within your code.

    239. Re:Write-only code. by spiralx · · Score: 1

      My view is that Python is an imperative language that is moving towards functional programming - much like both Ruby and JavaScript it's never going to get there, but it's a definite shift from when I started coding it at version 1.5, and IMO it's much cleaner to consider code as a series of transforms of varying kinds than a grab bag of tools.

      I suspect switch lost out due to the C-style switch-with-fallthrough and "clever" shenanigans like Duff's Device that can make them anything but obvious what's going on, and back in 1991 avoiding that probably looked like a good idea for an easy to learn language. I once worked on an application that's core consisted of a 3,000 line switch statement for handling messages, with both fall-through all over the place, and parts of it callled back into itself in what may have been an attempt at code re-use, but was probably just as stupid as it looked... *shudder*

      I like Coffeescript's switch, but that's partly because I like having every construct being an expression, removing an element of the code/data divide.

    240. Re:Write-only code. by rdnetto · · Score: 1

      IMO it's much cleaner to consider code as a series of transforms of varying kinds than a grab bag of tools.

      I agree entirely - functional approaches tend to result in much more elegant code, where suitable.

      I like Coffeescript's switch [coffeescript.org], but that's partly because I like having every construct being an expression, removing an element of the code/data divide.

      That looks very similar to Rust's match construct, which is basically the same thing but with C-style syntax. Another useful feature I've seen (that would be incompatible with Python's preference for duck typing) is D's final switch, which ensures that cases exist for all members of an enum.

      --
      Most human behaviour can be explained in terms of identity.
    241. Re:Write-only code. by silentcoder · · Score: 1

      I think we've officially pushed this joke past breaking point...

      --
      Unicode killed the ASCII-art *
    242. Re:Write-only code. by spiralx · · Score: 1

      Well yes, but if we were Perl programmers, we'd have just both been telling jokes at each other while trying to work out what was supposed to be funny about the other's joke.

      If we were PHP programmers we'd have got the punchline and the setup in the wrong order, and be getting confused over all of the similar sounding jokes that aren't funny, but never seem to go away.

      If we were JavaScript programmers we'd be on StackOverflow, asking for the best joke ever and a word-by-word explanation of why it was funny.

      I really will stop now.

    243. Re:Write-only code. by spiralx · · Score: 1

      When first announced here Rust looked very interesting, with some bold ideas for making programs better in the lower-level problem domain. Since then it's been under tons of development and community vigour, version 1 looked very different to 0.0.1, I need to reinvestigate!

      The final switch seems like it would be a useful construct. Python doesn't really have good Enums unfortunately, just some approximations such as using namedtuple._make(). Whereas in CoffeeScript you can assign the result of an if-else block to a variable, which allows for silly conditionals always a potential :)

    244. Re:Write-only code. by silentcoder · · Score: 1

      begin
        if we were pascal programmers we would argue about when to end a joke on a semi-colon
        and when to end it on a fullstop.
      end;

      If we were cobol programmers the joke would span 4 pages, look like something an accountant wrote and nobody could find the punchline.

      If we were object pascal programmers we'd be making jokes about classnames starting with T (a relic from pascal days and the way OP treats classes and Types as the same thing).

      If we were Ruby programmers all our jokes would be about how the language is better than python but everybody else is too stupid to know it.

      If we were C programmers we'd still think the "long johns" joke was funny.

      If we were assembler programmers we'd be making knock-knock jokes... sorry make that knk-knk jokes.

      (and (if (we (were (lisp (programmers (nobody (could (read (the (jokes)))))))))))

      --
      Unicode killed the ASCII-art *
    245. Re:Write-only code. by spiralx · · Score: 1

      Thank you, I'm late enough for work as it is :)

      Nothing for the Java devs here I see. Because there's nothing funny about Java. It's just stolid and lumpen.

    246. Re:Write-only code. by rdnetto · · Score: 1

      When first announced here Rust looked very interesting, with some bold ideas for making programs better in the lower-level problem domain. Since then it's been under tons of development and community vigour, version 1 looked very different to 0.0.1, I need to reinvestigate!

      I used it for a bit a while ago (0.9). It's a pretty nice alternative to C, but needing to explicitly deal with object lifetimes made it a bit too painful to be used as a high level language, which is a little ironic given the significant influence of Haskell in its design. There are ref counted pointers, but last I checked the syntax for them was pretty clunky. (An earlier version used a dedicated operator for them, but that got obsoleted. It's a shame, since that would have made it more usable as a high level language, similar to D.)

      The final switch seems like it would be a useful construct. Python doesn't really have good Enums unfortunately, just some approximations such as using namedtuple._make(). Whereas in CoffeeScript you can assign the result of an if-else block to a variable, which allows for silly conditionals always a potential :)

      Python has enums as of 3.4, though namedtuple._make() seems to resemble Haskell records more than a C-style enum.

      --
      Most human behaviour can be explained in terms of identity.
    247. Re:Write-only code. by silentcoder · · Score: 1

      A java developer tried to make a joke once but he ran out of memory before he could remember the punchline.

      --
      Unicode killed the ASCII-art *
    248. Re:Write-only code. by Anonymous Coward · · Score: 0

      > That will not work out well if a and b are local variables.

      Of course it works if a and b are local variables:

      auto a = std::make_shared(...);
      auto b = std::make_shared(...);
      std::thread([=](){ do_something(*a,*b); )).detach();

      (You can keep using a and b in the parent thread)

      This is safe, can't leak, is also exception safe, I think it is simple, and incurs no copies.

      > You will have to make a copy in order to make the std::shared_ptr point at them, so just as many copies are done as before (the second copy is when *a is copied to the argument to do_something, and, as before, can be avoided by making do_something take a const reference.

      No, if you need to access some state from different threads you just put it in the heap in the first place (no copies). If you know that the child thread's lifetime is shorter than the lifetime of the parent threads stack frame in which it is spawned, you could put a and b on the parent's thread stack and pass them by reference. But your problem statement explicitly says that you don't know this, so the right solution is to put a and b on the heap in the first place using `std::make_shared` (which is self-descriptive, you want to _share_ a and b between threads).

      > The basic lambda [=] syntax will work better [...] Also it uses something much more like std::unique_ptr which is much more efficient.

      No, the [=] just makes a copy. It cannot ever use an `std::unique_ptr` since `std::unique_ptr` does not model the CopyConstructible concept (it is a non-copyable move-only type). You really want to use `std::shared_ptr` and `std::make_shared` here. If a and b would be `std::unique_ptr`, you could:

      auto a = std::make_unique(...);
      auto b = std::make_unique(...);
      std::thread([c = move(a), d = move(b)](){ do_something(*c,*d); )).detach();

      (You can't use a and b in the parent thread anymore since they have been moved from, that is,
      they are in a valid but unspecified state).

      Since you want to keep using a and b in the parent thread, `std::unique_ptr` would invoke undefined behavior.

    249. Re:Write-only code. by spitzak · · Score: 1

      Above AC is an excellent example of the problems with C++. He has quite a few misconceptions.

      a = std::make_shared(x) does make a local shared pointer, but not the data itself, which is allocated on the heap.

      The lambda absolutely does use the equivalent of a unique ptr. There is a block of memory allocated and a and b are copied to it (this block also contains a pointer to the actual code, which in the example will be something to further copy or move a and b to the stack and call the do_something function). This is the copy that is unavoidable. This block is freed when the pointer goes out of scope. Since it is passed by value move semantics mean that there is never more than one pointer, so it is concievable that the optimizer will do a unique ptr to it (though it is likely that something more like a shared ptr is done, or the boost intrusive_ptr).

      Yes you can force it to use std::move but this should be an automatic optimization, it is nonsense that I have to type that. But even a move is much less efficient than direct use. The block is freed when no longer needed by the execution of the lambda (in the parallel thread).

      I do not want to use a and b in the parent thread. That is the whole point. Way to get completely confused there!

    250. Re:Write-only code. by spiralx · · Score: 1

      Fucking PermGen space. It's like they've specifically added a setting that's nothing more than a ticking time bomb, just to keep people on their toes.

    251. Re:Write-only code. by Carewolf · · Score: 1

      That is not C++ ABI, that is STL ABI, and they are not significant changes. It is in fact one minor change to a few STL templates, but just done now gcc is increasing the major number anyway.

    252. Re:Write-only code. by Paradise+Pete · · Score: 1

      Talk about read-only code!

      Hmmm. How would something like that get written?

    253. Re:Write-only code. by Anonymous Coward · · Score: 0

      > a = std::make_shared(x) does make a local shared pointer, but not the data itself, which is allocated on the heap.

      I never said that the data is on the stack. Instead I said that "if you need to access some state from different threads you just put it in the heap in the first place (no copies [of the data])."

      The point being, per variable captured either in C or C++ you need to either pass the variable storage or a pointer to it to the child thread. If the size of the variable is less than size of a pointer, you don't care if you pass a pointer or make a copy (unless you need reference semantics). If the size of the variable is larger than the size of a pointer you do care and are better off putting the data on the heap in the first place.

      >The lambda absolutely does use the equivalent of a unique ptr. There is a block of memory allocated and a and b are copied to it (this block also contains a pointer to the actual code, which in the example will be something to further copy or move a and b to the stack and call the do_something function). This is the copy that is unavoidable.

      You are wrong about allocation. Lambdas are allocated on the stack. In particular this lambda will be allocated on the stack of the parent thread, and then moved to the stack of the child thread.

      You are also wrong about a pointer to any code. Lambdas have static dispatch, there are no pointers to any code involved.

      > value move semantics mean that there >is never more than one pointer, so it is concievable that the optimizer will do a unique ptr to >it (though it is likely that something more like a shared ptr is done, or the boost intrusive_ptr).

      Do you read what you write? Your unique pointer analogy is extremely unclear, hard to follow, and makes no sense at all since: you can copy a lambda, and lambda's can have references to their environment (they do not own it). You cannot copy unique pointers, and unique pointers do own the data they point to. They are not like lambdas at all.

      > Yes you can force it to use std::move but this should be an automatic optimization, it is nonsense that I have to type that. But even a move is much less efficient than direct use. The block is freed when no longer needed by the execution of the lambda (in the parallel thread).

      No it isn't. If a and b are unique pointers and you try to capture them in a lambda by value your code won't even compile. You need to tell the compiler how the environment of a lambda is to be captured by the closure object.

      Seriously, you might be a good C programmer but you ruin your reputation by bashing about things you have no clue about. The fact that you argue like a child and can't precisely express yourself doesn't help. You are wrong, in almost every single point you make. If you don't want to use a and b after spawning the new thread you have to either put a and b on the heap and copy pointers to them to the new thread, or put them on the stack of the parent thread and copy them to the child thread's stack. These copies are unavoidable in both C and C++ unless you know that the parent thread stack frame outlives the child thread, in which case you still have to copy a pointer to the stack variables of the parent thread to the new thread. This is true in both C and C++, and can be done in both. Doing it in C++ is way easier, cleaner, and safer than doing it in C. The performance is exactly the same.

    254. Re:Write-only code. by Anonymous Coward · · Score: 0

      1. Discipline: If you need to enforce that much discipline you aren't going to get it reliably. Far better to build those rules into the language and/or the compiler.

      2. The head coder can get transitioned upward or outward. As can the next layer up of management. There go your standards.

      3. Coding standards often don't last 5 years, and less often are even enforced for 5 years.

      4. Regardless, some coder is going to ask his bosses boss, or one level above: "Can I write this in Fortran? It will be faster!". And there goes the neighborhood.

      If you're trying to create large projects, with distributed development, using volunteer programmers, (Such as the LINUX KERNEL), then C++ is an engineering disaster.

      If you've got a situation where each different programmer, and each different group, uses a different subset of the language, and that language also requires exceptional human organization for implementation to work, then that language is a bad choice.

    255. Re:Write-only code. by spitzak · · Score: 1

      I have no idea why you are arguing but saying EXACTLY the same things I am.

      I am not saying to make a and b into unique pointers to a copy. I am saying "a and b ARE LOCAL VARIABLES!!!!!" They will be copied to make the lambda, it is NOT POSSIBLE to avoid this!!!! The function can return before the lambda is destroyed. And you seem to think "constructing on the stack" does not involve a copy of a and b, which is wrong. You do mention the "move" which does do another copy (though move semantics could cause a more-efficient version but it is not zero). Actually the lamda data structure is created on the heap because this is more efficient than the move.

      The rest of my comments were about how the C++ compiler will actually do better than your attempts at premature optimization by forcing a and be to be on the heap. There will be only a single "shared pointer" to the lambda object, not one to a and another to b. Also what boost calls an "intrusive ptr" will be used, avoiding a lot of overhead of std::shared_ptr. And as my C code shows, it is possible to avoid multiple references to the lambda object, thus a unique_ptr could be used, though I believe this will require the optimizer to have access to the implementation of the thread constructor so it knows the lambda is not copied.

    256. Re:Write-only code. by Anonymous Coward · · Score: 0

      I guess we are just 2 random people shouting at each other on the internet arguing about stuff we both agree on, so I want to apologize for my tone before, I was out of line.

      > I am saying "a and b ARE LOCAL VARIABLES!!!!!" They will be copied to make the lambda, it is NOT POSSIBLE to avoid this!!!! The function can return before the lambda is destroyed.

      I agree, unless you know that the function doesn't return before the lambda is destroyed (i.e. the detached thread terminates), in which case you can take a pointer to the parent's thread stack (which also needs to be copied...).

      > And you seem to think "constructing on the stack" does not involve a copy of a and b, which is wrong. You do mention the "move" which does do another copy (though move semantics could cause a more-efficient version but it is not zero).

      Do you mean constructing the lambda on the stack? If you capture by value you copy the other stack variables into the lambda, if you capture by reference you construct in the lambda a reference (which is just a pointer) to point to the stack variables. For a lot of types (e.g. all PODs) a move is just a copy. As a general rule of thumb, everything that can be allocated on the stack will be copied by a move, the only (but huge) saving of move is that heap allocated data will not be copied.

      >Actually the lambda data structure is created on the heap because this is more efficient than the move.

      No, the lambda is not created on the heap. Why do you think this? The std::thread constructor copies whatever is passed to it into the stack frame of the new thread (if you pass it an rvalue like in the code above, it can perform a move instead of a copy). That is, the lambda will be allocated on the stack of the parent thread, then a new thread will be created, and finally the lambda will then be moved into the new thread's stack. Both threads share the same heap, but the new thread has its own stack, with its own program counter, and its stack starts with the code in the lambda. An optimizer can avoid constructing the lambda on the parent thread (i.e. construct it directly into the child thread's stack), but that's about it.

      > The rest of my comments were about how the C++ compiler will actually do better than your attempts at premature optimization by forcing a and be to be on the heap. There will be only a single "shared pointer" to the lambda object, not one to a and another to b. Also what boost calls an "intrusive ptr" will be used, avoiding a lot of overhead of std::shared_ptr. And as my C code shows, it is possible to avoid multiple references to the lambda object, thus a unique_ptr could be used, though I believe this will require the optimizer to have access to the implementation of the thread constructor so it knows the lambda is not copied.

      Which compilers do this? I'm familiar with both the clang and the gcc implementation of lambdas, and with the libc++ and libstdc++ implementation of threads, and never ever have seen these compilers doing that. Lambdas are always allocated on the stack, a heap allocation can throw, so it _can_ have observable side-effects, making such an optimization illegal.

    257. Re:Write-only code. by Anonymous Coward · · Score: 0

      If you want a while loop or any language feature in Lisp, just fucking add it!

      That is what makes Lisp great, if it is missing a feature you can add it as a first class language feature.

  2. Almost got me by halivar · · Score: 5, Insightful

    I always get halfway through a Nerval's Lobster summary before my anger/indignation/smug validation gives way to the sad realization that Dice has trolled me yet again.

    1. Re:Almost got me by gargleblast · · Score: 1

      With friends like Nerval's Lobster and Jeff Cogswell, C++ doesn't need enemies.

  3. Re:Ugh by Twinbee · · Score: 1

    I'd the this 'real language' to get rid of those god-awful headers and support ^ as exponentiation - something so commonly used. Less bloat would be nice too.

    --
    Why OpalCalc is the best Windows calc
  4. Full Disclosure by mu51c10rd · · Score: 5, Informative

    Could we stop having Dice articles submitted by Nerval's Lobster? Why not fully disclose that the story was submitted by the corporate parent of Slashdot?

    1. Re:Full Disclosure by Anonymous Coward · · Score: 2, Interesting

      Slashdot used to do full disclosure, under its previous owner. Dice lacks even basic business ethics.

    2. Re:Full Disclosure by Anonymous Coward · · Score: 0

      Nerval's Lobster is the standard account to post Dice fluff. It used to be the account to cross-post stuff from SlashBI (which was an idea equally as stupid as Beta). At least now NL is posting stuff that fits in with Slashdot culture, as opposed to stuff that only a PHB would love to read.

    3. Re:Full Disclosure by Anonymous Coward · · Score: 0

      It's ok, I hope with adblocks they won't get much out of the clicks anyway. Adblocks cleanse the net from profit motivated content, steering it back to its academic roots.

  5. Re:Ugh by mellon · · Score: 4, Insightful

    Oh no, on the contrary. There are plenty of idiots who can write code in C++.

  6. Another troll-FP? *Excellent*! by pla · · Score: 2

    / Grabs popcorn
    // Dons asbestos armor

  7. C++ by Anonymous Coward · · Score: 1, Insightful

    C++ deserves all the hate it gets. Life is too short and mental health too precious to become an expert in C++.

    1. Re:C++ by Anonymous Coward · · Score: 4, Insightful

      Life is tough, but it's tougher if you're stupid.

    2. Re:C++ by gyroheli · · Score: 2

      Good excuse for being lazy. I guess C++ is only for the iron willed. C++ is like a russian prison, you'll know who the men are real quick.

    3. Re:C++ by Anonymous Coward · · Score: 0

      C++ deserves all the hate it gets. Life is too short and mental health too precious to become an expert in C++.

      I'm an expert in C++, you insensitive clod!

    4. Re:C++ by Anonymous Coward · · Score: 0

      programming is tough, but it's tougher if you're using stupid c++

    5. Re:C++ by Prune · · Score: 1

      you'll know who the men are real quick

      But you won't, apparently, know how to write "really quick".

      --
      "Politicians and diapers must be changed often, and for the same reason."
    6. Re: C++ by Anonymous Coward · · Score: 0

      Ummm... Or, better yet, "really quickly"?

    7. Re: C++ by Prune · · Score: 1

      You got me.

      --
      "Politicians and diapers must be changed often, and for the same reason."
    8. Re:C++ by Anonymous Coward · · Score: 0

      C++ is a stupid person's idea of a smart language.

    9. Re:C++ by Anonymous Coward · · Score: 0

      Drawing comparisons between C++ and feral, unprovoked, might-makes-right violence is surprisingly appropriate.

  8. depends upon what you're making by circletimessquare · · Score: 0

    if you're writing an OS or firmware? sure, use C++, it exposes abilities you might need

    but you can shoot your foot off easily doing esoteric things with C++ that other languages just don't allow you too do easily, because for 99% of programming tasks they aren't necessary. other languages provide straightjackets and limited functionality in low level tasks that, well, for safety reason you actually want, it protects you

    maybe those esoteric things are important to do. but usually they aren't

    --
    intellectual property law is philosophically incoherent. it is your moral duty to ignore it or sabotage it
    1. Re:depends upon what you're making by swilly · · Score: 3, Informative

      I haven't read Linux's rant against C++ for a while, but he is correct that C++ isn't a good choice for an OS kernel. The only major kernel written in C++ that I know of is Windows NT, and it uses only a subset of C++ language features. In particular, it disables exceptions, disables RTTI, removes new/delete, and it doesn't have the standard library. Microsoft wrote their C++ compiler with this in mind, and there is a compiler flag to disable kernel unfriendly features (documented here). For everyone else, it's easier to just say that the C++ subset for kernel development is C (minus the standard library).

      For non kernel use, C++ is superior to C in the hands of an expert programmer, but mediocre programmers who don't understand the language tend to write absolutely horrible code. And you can't take an expert C or Java programmer and expect them to write expert C++ code with just a few weeks practice. C++ is one of those languages that you have to dedicate a lot of time to, but it can be worth it if you require highly optimized code, have low latency requirements, or have low space requirements (areas where higher level languages like Java don't do well).

    2. Re:depends upon what you're making by sjames · · Score: 1, Insightful

      I wouldn't use it for most firmware either. Firmware often has size constraints that C++ is less than friendly about. It also often runs in a limited environment that may not be friendly to C++.

    3. Re:depends upon what you're making by tibit · · Score: 1

      C++ is a fairly modern, high-level language where it's fairly easy to produce type-safe, grounds-up designs that use zero unsafe C features. And if you must call into C or precambrian C++, you can wrap those in type- and otherwise safe wrappers.

      The "esoteric" things in C++ are precisely the things that let you use it as a high level language, and not as Java or C. C++ offers a higher level of abstraction than Java, at least since the arrival of C++11. About the only mainstream feature still absent from C++ is free-form introspection. It's already possible to use template machinery to create types with full introspection, but any such approach doesn't apply to the types created manually using plain C++ syntax. The other feature is imperative compile-time programming, also known as LISP macros, but then only LISP really has those and nothing else IIRC.

      --
      A successful API design takes a mixture of software design and pedagogy.
    4. Re:depends upon what you're making by tibit · · Score: 0

      The C++ that was available during NT kernel's design is quite literally a different programming language than modern C++, or even C++98. C++ is an excellent choice for an OS kernel.

      --
      A successful API design takes a mixture of software design and pedagogy.
    5. Re:depends upon what you're making by Anonymous Coward · · Score: 0

      Depends on the type of firmware and the system. And I guess what you consider firmware. I've been writing drivers, BIOS's and embedded system code in C++ for nearly 20 years and have never run into a problem. But then I've always had to follow a very strict (and enforced) process that only includes a subset of MISRA.

      http://en.wikipedia.org/wiki/Motor_Industry_Software_Reliability_Association.

    6. Re:depends upon what you're making by Sarten-X · · Score: 1

      Honestly asking out of ignorance, not malice, Sad that I have to note that, but I digress...

      Are there any notable kernels written in modern C++ (or even C++98)? I've never bothered to keep track of what kernel was written in which language, so I'm sure my knowledge is sorely lacking in this area. Hurd? Mach? Any of the many RTOS kernels?

      --
      You do not have a moral or legal right to do absolutely anything you want.
    7. Re:depends upon what you're making by jcr · · Score: 4, Informative

      The only major kernel written in C++ that I know of is Windows NT,

      Apple uses a subset of C++ known as "kernel C++" for drivers in OS X and iOS. Back in the NeXTSTEP days we used Kernel Obj-C, and it's very sorely missed.

      -jcr
       

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    8. Re:depends upon what you're making by Anonymous Coward · · Score: 0

      C++ is a fairly modern, high-level language where it's fairly easy to produce type-safe, grounds-up designs that use zero unsafe C features.

      Benjamin Franklin explains why C++ code is easy to exploit.:
        "Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety."

    9. Re:depends upon what you're making by tibit · · Score: 2

      There aren't, because C++11 is, well, a standard for 4 years only, and C++98 implementations were spotty well into the middle of the following decade. Finally, not that many people are writing kernels from scratch...

      --
      A successful API design takes a mixture of software design and pedagogy.
    10. Re:depends upon what you're making by Anonymous Coward · · Score: 1

      Tell that to the makers of BEOS. https://haiku-os.org/legacy-docs/benewsletter/Issue2-25.html There is also a Wikipedia page.

      Lack of ABI makes using C++ to define a system call interface impossible/impractical.
      Fragile base classes make use of inheritance in a kernel impossible/impractical.

      Etc.

    11. Re:depends upon what you're making by Anonymous Coward · · Score: 0

      Give 1 mediocre programmer a task to do in C++, and a second mediocre programmer the same task to do in C.

        Programmer A will complete this task in 2x less code, with 2x less bug in a type-safe language, with RAII. Nuff said.

        The argument about C vs C++ always boils down to the same stupid and dishonnest argument : C++ programmers are bad, C coders are good. That is just not true. Never has been, and never will. The fact that AT SOME POINT IN HISTORY, new kernel devs were familiar with C++ and were less experienced than old kernel dev about the kernel is a piss poor sorry excuse for an actual data set to determine the quality of C++ programmers and indeed an even less valuable data point to judge the quality of C++.

    12. Re:depends upon what you're making by Pseudonym · · Score: 2

      The only major kernel written in C++ that I know of is Windows NT [...]

      Symbian, BlackBerry OS, Wii U System Software, OKL4.

      I'm sure I left some out.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    13. Re:depends upon what you're making by AaronW · · Score: 1

      Back in the mid 1990s I worked on a complex ATM (Asynchronous Transfer Mode) networking driver for OS/2 that was written in C++ and it was actually quite elegant compared to the Windows NT driver which was written in C. It had more functionality yet was less than 1/3 the amount of code. It used new and delete as well as templates but other than that it was somewhat limited in its use of C++. Granted, C++ has evolved quite a bit since then but it showed me that C++ can be used for low-level stuff. Performance was actually quite good, at least as good if not better than the C counterpart. The code was also easier to debug and tended to have far fewer bugs than the 360KLOC C driver. This driver was around 100KLOC of mostly C++ with a small amount of assembly and some C for the OS bindings. It included the full signalling stack, lan emulation and all the other various parts needed for an ATM stack.

      Adding features was also much easier than the C driver. The code base was also used for other operating systems and compilers as well (i.e. AIX running on Power).

      --
      This post is encrypted twice with ROT-13. Documenting or attempting to crack this encryption is illegal.
    14. Re:depends upon what you're making by xx_chris · · Score: 1

      Yes, they use zero unsafe C features. They use unsafe C++ features.

    15. Re:depends upon what you're making by MobyDisk · · Score: 1

      Do you know why they didn't use new/delete? They are simply syntactic sugar to create a less error prone version of malloc/free.

    16. Re:depends upon what you're making by jeremyp · · Score: 1

      Not while it still suffers from the fragile base class problem.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    17. Re:depends upon what you're making by Anonymous Coward · · Score: 0

      It's not really new/delete which are removed. The keywords still exist. However, those usually lead to calls of `operator new/operator delete`, which by default are functions in the standard library (and thus missing). You can still provide your own.

      Note that this is pretty much the same as C. `operator new` is the equivalent of `malloc`, and `malloc` isn't in the kernel either. While not officially allowed by ISO, Windows won't complain if you link in your own `malloc` implementation.

    18. Re:depends upon what you're making by Anonymous Coward · · Score: 0

      There aren't, because C++11 is, well, a standard for 4 years only, and C++98 implementations were spotty well into the middle of the following decade. Finally, not that many people are writing kernels from scratch...

      Symbian was C++. Last time I looked at the kernel source which was a couple of years ago. Pick it up for yourself and look: https://archive.org/details/SymbianOpenSource

    19. Re:depends upon what you're making by shutdown+-p+now · · Score: 1

      Out of curiosity, what is in that subset? Is it pretty much the same as what MS uses as described above? i.e. the only valuable thing that it brings to the table is RAII?

    20. Re:depends upon what you're making by david_thornley · · Score: 1

      Which C++ features do you consider unsafe? Just going through a C program and replacing arrays, raw pointers, and C-style strings with vectors, smart pointers, and C++ strings will eliminate a great many chances to screw up.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    21. Re:depends upon what you're making by jcr · · Score: 1

      Out of curiosity, what is in that subset?

      As I recall, they don't allow you to use multiple inheritance, templates, or C++ exceptions. You can find the full details in Apple's IOKit documentation.

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    22. Re:depends upon what you're making by Anonymous Coward · · Score: 0

      Why would I waste my time with mediocre programmers?

  9. How much is it C++ and how much the compilers? by Anonymous Coward · · Score: 1

    I've found a lot of the stuff C++ does that people come to hate with a passion is a direct result of what the compiler does, rather than anything the programmer intended.

    1. Re:How much is it C++ and how much the compilers? by david.emery · · Score: 2

      A better specified language, with fewer holes in its design, wouldn't have these problems between 'language' and 'compiler'.

    2. Re:How much is it C++ and how much the compilers? by RailGunner · · Score: 3, Informative

      A better developer who understands what it is he or she is trying to accomplish would help more.

      I'd say I've seen just as much piss poor code written in Java and C#, but that'd be a lie. I've seen FAR worse code written in Java and C# than I have in C++ because the level of entry is much lower.

      When I was in college, not understanding pointers means you didn't graduate. Now... I interview "C# Developers" who claim 10+ years experience who can't tell me the difference between pass-by-value and pass-by-reference, and don't know the difference between the heap and the stack.

    3. Re:How much is it C++ and how much the compilers? by david.emery · · Score: 5, Interesting

      Bad programmers can produce bad code in any language, including one as well/thoroughly specified as Ada. The difference, though, is that what that code actually does is less subject to interpretation by the compiler.

      I've observed that two Ada programmers will argue, "Is this program legal?" If the program is legal, they both -know- what the compiler will do (modulo the rare compiler/optimizer bug, which was usually caught through the stringent compiler validation.)

      Two C++ programmers will argue, 'What will my compiler do with this code?"

    4. Re:How much is it C++ and how much the compilers? by RailGunner · · Score: 2

      Two C++ programmers will argue, 'What will my compiler do with this code?"

      You have a very good point, but that's less about the language and more about the compiler. Arguably the most broken compiler was (and likely still is) Microsoft's Visual C++.

      But somehow C# is "fixed". LOL.

    5. Re:How much is it C++ and how much the compilers? by david.emery · · Score: 1

      Two C++ programmers will argue, 'What will my compiler do with this code?"

      You have a very good point, but that's less about the language and more about the compiler. Arguably the most broken compiler was (and likely still is) Microsoft's Visual C++.

      But somehow C# is "fixed". LOL.

      I argue the exact opposite! C++ the programming language leaves way too many decisions to the compiler implementer. A better specified language, such as Java, Ada, Eiffel, etc, doesn't have that problem of different compiler interpretations of the standard.

    6. Re:How much is it C++ and how much the compilers? by CSMoran · · Score: 1

      I argue the exact opposite! C++ the programming language leaves way too many decisions to the compiler implementer. A better specified language, such as Java, Ada, Eiffel, etc, doesn't have that problem of different compiler interpretations of the standard.

      Interpretations of the standard? C++ standard has few ambiguities, hard to come with many interpretations. Perhaps you mean the bits that are left as implementation-dependent? I think grandparent was talking about dumb programmers who argue about precise results of undefined behaviour.

      --
      Every end has half a stick.
    7. Re:How much is it C++ and how much the compilers? by phantomfive · · Score: 1

      If you want to get a taste of what the Visual C++ compiler might look like, Check out this 16000 line file from .net, and realize that it was written after Microsoft had already cleaned up their coding habits quite a bit.

      --
      "First they came for the slanderers and i said nothing."
    8. Re:How much is it C++ and how much the compilers? by tibit · · Score: 1

      That's silly. As long as the code doesn't invoke undefined or implementation-defined behavior, you can be exactly sure what the compiler can and cannot do, modulo implementation bugs. If you're invoking undefined behavior, you can argue all you want, because for all I know you'll be getting different assembly output every time you compile the thing, and it's your own fault. C++ admittedly lacks in full identification and diagnostics of undefined behavior, so a bit too much checking is still left in programmer's hands. That's my only lament with C++. Otherwise it's a cool language.

      --
      A successful API design takes a mixture of software design and pedagogy.
    9. Re:How much is it C++ and how much the compilers? by Anonymous Coward · · Score: 0

      Ada also punishes those who are inefficient. Objects are harder to use in Ada so simpler concepts such as variant records, generics, and protected types often get used instead - making bad design easier to identify.

      In this way and through the well documented standard libraries it doesn't force the writer to use the taint stain of modern software design (OOP) to create powerful modern programs.

    10. Re:How much is it C++ and how much the compilers? by serviscope_minor · · Score: 1

      As long as the code doesn't invoke undefined or implementation-defined behavior, you can be exactly sure what the compiler can and cannot do, modulo implementation bugs.

      Well, not exactly.

      The templating mechanism is turing complete, so that becomes the same as the argument as "what does this program do".

      But I challenge the OP to find a language where it's not possible to argue about what a carefully chosen program does. I mean sure, there's a right answer but it might not be obvious.

      But anyway that's just a truism about programming combined with the orthogonal fact that the compiler is programmable.

      --
      SJW n. One who posts facts.
    11. Re:How much is it C++ and how much the compilers? by david_thornley · · Score: 1

      It looks to me like the complaint is about the amount of undefined, unspecified, and implementation-defined behavior. (Undefined means anything can happen, unspecified means that any reasonable interpretation can happen, implementation-defined is something like unspecified, except that the behavior needs to be consistent and documented.) I consider this a reasonable complaint.

      I can give you some historical background on how things came to be that way, and why much of this was initially necessary* but that doesn't make it a good thing. One problem is that it's often difficult to spot undefined behavior, particularly for the inexperienced. While many compilers try to do something reasonable with undefined behavior, g++ will simply assume everything's defined when it's optimizing hard, and that can lead to surprises.

      Another issue is the "as if" rule, which also allows the compiler some liberties. If you are writing a crypto function that temporarily uses a chunk of memory, and you casually zero it out before releasing it back to the pool, the compiler is entitled to notice that this doesn't affect the observable behavior of the program and just not do it. ("Observable behavior" in C++ is calls to I/O library functions and accesses to volatile memory.) There are ways to force that to happen, but it's not immediately obvious that it's necessary. This allows some aggressive optimization, and people have been complaining about such optimization longer than most of you have been alive.

      In other words, there are traps for the unwary that generally don't exist in other languages. These exist to make the language portable, efficient, and extremely optimizable, but they have their downsides.

      *C was originally intended to be efficient and portable, and there was a much wider variety in target platforms that we generally get today. This meant that there were decisions the language standard simply couldn't make. Consider overflow in signed integer arithmetic. Should it raise some sort of exception or signal, or should it return something, and, if so, what? In some target machines, it would raise a signal or do the equivalent. If it was supposed to return a value, every operation that could overflow would need a range check before it. In some target machines, it would return a known value, but I doubt it was the same in all of them. If it was supposed to raise a signal, again there would have to be range checks. If it was supposed to return a particular value, then all systems that didn't return that value would need range checks. The choice Ritchie made was to call it undefined, since specifying anything would require that arithmetic be spotted with range checks on a large number of systems.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  10. Re:Ugh by Anonymous Coward · · Score: 0

    +1

  11. No by Anonymous Coward · · Score: 2, Insightful

    Linus was not going overboard. In this rare instance, I'd argue he hasn't gone far enough.

    1. Re:No by boristhespider · · Score: 5, Insightful

      A clickbait article about a flamebait rant, commented on by trolls.

      God bless Slashdot.

    2. Re:No by Anonymous Coward · · Score: 0

      I'd argue he hasn't gone far enough.

      I demand nothing short of economic sanctions against community project using C++.
      And thermonuclear war is on the table.

    3. Re:No by Anonymous Coward · · Score: 1

      Linus is seldom wrong. He is sometimes vocal and uses his language creatively, but when he does he usually makes sure that the one he is using it against is deserving of it.

    4. Re:No by Bing+Tsher+E · · Score: 1

      Then apparently the kernal should have been written in Assembly Language. One hell of a spectrum there.

    5. Re:No by Anonymous Coward · · Score: 0

      I agree with Linus. :-)

      In C, you know that the dot operator has no side-effects, etc. C++ isn't quite high level enough to displace C, and C++ has had a really really long time to kill off C; it won't. The point of a higher layer than C should be to provide safety by default that C cannot. Just about any other language designed to link nicely with C could have done that. Unsafe code is ok, but the compiler should scream loudly about all logical inconsistencies and memory unsafe use; and for the developer to assert the missing conditions that will satisfy the compiler. That way, when there is a giant security hole that exposes a million users, you have a limited number of locations to search for it.

      C++ compilers are as blind as C compilers, forcing you to still use a higher language in conjunction with it; even if it's just to orchestrate a bunch of processes.

    6. Re:No by BESTouff · · Score: 1

      Yes and no. I didn't RTFA but I enjoy the "debate" here on /.

    7. Re:No by david_thornley · · Score: 1

      :Linus is seldom wrong about things that apply to kernel programming. Subversion, for example, isn't suited for Linux kernel development, but Linus didn't specify that when he blasted it.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    8. Re:No by Anonymous Coward · · Score: 0

      Subversion isn't suited for anything other than idiots.

  12. No by bhcompy · · Score: 2

    The ability to fuck it up is a good thing, because there's a spectrum, and you can also knock it out of the park.

  13. Flamefest thread by fph+il+quozientatore · · Score: 4, Funny

    What comes next, a thread on "is Emacs better than Vi"?

    --
    My first program:

    Hell Segmentation fault

    1. Re:Flamefest thread by bigtrike · · Score: 1

      For programming C++?

    2. Re:Flamefest thread by TechyImmigrant · · Score: 1

      What comes next, a thread on "is Emacs better than Vi"?

      Well? Is it?

      --
      I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    3. Re:Flamefest thread by RailGunner · · Score: 2

      Emacs lost that argument when it added a vi mode. :)
      gVim FTW

    4. Re:Flamefest thread by sconeu · · Score: 4, Funny

      You mean that EMACS is now a good OS because it finally has a decent text editor?

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

      No.

    6. Re:Flamefest thread by Anonymous Coward · · Score: 0

      Don't tell me you missed the part where emacs has a video player+editor?

    7. Re:Flamefest thread by Anonymous Coward · · Score: 0

      If only VI would do likewise.

    8. Re:Flamefest thread by Anonymous Coward · · Score: 0

      Yes, try out spacemacs.

  14. Ahhhh, C++ by segedunum · · Score: 2, Insightful

    Although the language itself isn't truly, truly bad, the only thing that made it tolerable was a library like Qt. STL and Boost are so shocking it isn't even funny, as well as the attitude amongst many that they are some kind of 'standard'. That's where C++ really did go off the rails.

    1. Re:Ahhhh, C++ by Anonymous Coward · · Score: 0

      What is wrong with STL as of C++'11+? I'm thinking of the algorithms, containers, and smart pointers in particular.

    2. Re:Ahhhh, C++ by Anonymous Coward · · Score: 0

      Guess what the "S" in "STL" means :)

    3. Re:Ahhhh, C++ by gnupun · · Score: 4, Insightful

      Although the language itself isn't truly, truly bad,

      Any language that allows the programmer to override the '=' operator is truly, verily, bad. That makes the language over-programmable and a write-only language when trying to maintain other developer's code. Java may have fewer features, but that doesn't stop the developers from getting stuff done.

    4. Re:Ahhhh, C++ by JustNiz · · Score: 1

      QT is awful. Any helper library that also needs its own preprocessor has definately lost the plot somewhere.
      QT also enocurages bad programmers to use endless amounts of signals and slots that break encapsluation and obscure program flow, where a normal function or method call would have been used before. Good luck trying to figure out program flow with heavy use of those abominations.

    5. Re:Ahhhh, C++ by BarbaraHudson · · Score: 2

      Doesn't mean that it doesn't suck big time. TR1 sucked. The STL sucks. Templates suck. The original goal of c++ - c with classes - was good, but come on - this has gone way too far off track.

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    6. Re:Ahhhh, C++ by TechyImmigrant · · Score: 1

      Although the language itself isn't truly, truly bad,

      Any language that allows the programmer to override the '=' operator is truly, verily, bad. That makes the language over-programmable and a write-only language when trying to maintain other developer's code. Java may have fewer features, but that doesn't stop the developers from getting stuff done.

      Why is overriding '=' bad? If I've defined a class for a thing for which equality means something other than the usual, e.g. a mod 11 class where 'a = 13' should result in 'a==2', I would want to override '=' to do the right thing.

      --
      I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    7. Re:Ahhhh, C++ by crunchygranola · · Score: 3, Interesting

      Any language that allows the programmer to override the '=' operator is truly, verily, bad.

      This is, to my mind, the most fundamental problem with C++: it is impossible to look at a page of code in isolation and know what it does, with confidence. Any of the operators could have been redefined to do anything. This is not a theoretical problem, I encountered a code base of horrors that a nerd who though he was God's gift to nerd-dom dreamed up, which had numerous standard operators reassigned to make the code he wrote "look elegant". It was impossible to analyze or maintain.

      When the meaning of a simple programming construct is indeterminate, the language that supports it has failed disastrously.

      --
      Second class citizen of the New Gilded Age
    8. Re:Ahhhh, C++ by neokushan · · Score: 1

      It's bad because someone can think of a niche case where it can be abused. In my experience, it never happens. You tend to find that those smart enough to know how to overload say the = operator are also smart enough to only do it for a good reason.

      I've seen bad developers utterly abuse just about every language out there, if there's a language feature then it can be abused. C++ just happens to have a lot of features.

      --
      +1 IDisagreeSoHeMustBeATrollOrAnAstroturferOrAShill
    9. Re:Ahhhh, C++ by TechyImmigrant · · Score: 1

      It's bad because someone can think of a niche case where it can be abused. In my experience, it never happens. You tend to find that those smart enough to know how to overload say the = operator are also smart enough to only do it for a good reason.

      I've seen bad developers utterly abuse just about every language out there, if there's a language feature then it can be abused. C++ just happens to have a lot of features.

      Fair enough. In return for not being able to overload '=', please can I have the ability to define infix operators? So I can have 13 is_congruent_to 2 == True.

      --
      I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    10. Re:Ahhhh, C++ by tibit · · Score: 1

      You're completely off base. Code generation is a vital productivity tool. Properly applied, it lets you produce code quicker and with less defects. If you're developing a large scale project and are not using various code generators to ease your job in repetitive tasks, you're doing it wrong. Qt's use of moc is exactly what code generators are supposed to be used for. I lament that they haven't taken it far enough, in fact.

      --
      A successful API design takes a mixture of software design and pedagogy.
    11. Re:Ahhhh, C++ by Yunzil · · Score: 2

      Java may have fewer features, but that doesn't stop the developers from getting stuff done.

      This is a stupid argument. You could just as easily say, "Assembly language may have fewer features, but that doesn't stop the developers from getting stuff done."

    12. Re:Ahhhh, C++ by JustNiz · · Score: 1

      >> You're completely off base.
      No you are. neenner.

      >> Code generation is a vital productivity tool.
      except maybe for generating event handler stubs for GUI code, or throwaway protoype apps, I strongly disagree.

      Auto-generated code is often unmaintainable and supporting it long term is way more of a time-consuming pain in the ass than it saves. Generally, if you need a program to write code for you, chances are you have other problems.

    13. Re:Ahhhh, C++ by byuu · · Score: 1

      This exactly. When I tried to use the STL and Boost, I hated the language as well. The STL is so crippled that std::string is basically std::vector. If you want to replace "foo" with "bar" in a string, you have to write your own function to do it, because std::string::replace is just a glorified memcpy wrapper. Same goes for char transform, string reverse, split/explode, etc.

      And since C++ lacks unified function call syntax, you can't extend std::string unless you subclass it (and then everyone does that, and they're not compatible with each other.) So instead, people revert back to treating C++ like C with shit like "replace(mystring, "from", "to")" instead of "mystring.replace("from", "to")". Yet it goes out of its way to offer esoteric features like custom allocators.

      Qt is a rather buggy toolkit, because it tries to do way too much for its own good. (seriously, you can apply a CSS stylesheet to do a radial gradient effect on the text color of a QLabel. Yes, that's cool, but there's so much code that it's 40MB of run-time DLLs, takes hours to compile said library DLLs, and is just full of bugs that vary per platform.) However, once you get past moc/signals/slots (function pointers, and now lambdas, work for 99% of the cases you'd encounter), the API is truly a thing of beauty. (you might even like signals/slots, but I personally can't stand all the added build rules, or the "just use qmake" crowd.)

      Since I've started just writing my own C++ libraries, I've found the language to be a thing of beauty. The obvious downside is that the system won't work if everyone uses their own libraries (Qt does this as well, eg QString, QList, etc.) C++14 really needs a renaissance, where a new team builds a new run-time library from scratch, with clean designs as with Qt.

    14. Re:Ahhhh, C++ by Anonymous Coward · · Score: 0

      Why is overriding '=' bad? If I've defined a class for a thing for which equality means something other than the usual

      Why is it so bad to just define something that describes what you are actually doing instead of hiding important details in overloaded operators?

      When someone else defines a class for which equality means something other than the usual and your like ... WTF 2 == 13 ... who wins? What is the upside other than less typing for those still using vi to write code?

    15. Re:Ahhhh, C++ by TechyImmigrant · · Score: 1

      Why is it so bad to just define something that describes what you are actually doing instead of hiding important details in overloaded operators?

      When someone else defines a class for which equality means something other than the usual and your like ... WTF 2 == 13 ... who wins? What is the upside other than less typing for those still using vi to write code?

      Because typing mod11_assign(&a,13) sucks compared to a = 13.

      If you're doing finite field arithmetic, the rules are the rules and having a programming language that is too stupid to anything beyond elementary school arithmetic is counterproductive.

      --
      I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    16. Re:Ahhhh, C++ by tibit · · Score: 1

      I'm sorry, you're really doing it wrong, and I'm not trying to pull a "no true scotsman" on you. moc output code doesn't have to be readable, even though it's not an outright mess. For other code that you'd be writing generators for, it's on you to make it readable, and with the right approach it can work wonderfully. The 0mq folks use their own tool, gsl, and even though their own use of code generation inside of gsl is an abominable mess, you can actually use gsl to generate some very nice, readable code. In fact, the whole point of such code generation is that it will be, by necessity, much more uniform and of higher quality than handwritten code - once you debug the generator, it'll do its job whether you are tired or not.

      It's not the only tool like that out there. If you're masochistic enough, you can even write code generators in xslt :)

      --
      A successful API design takes a mixture of software design and pedagogy.
    17. Re:Ahhhh, C++ by Anonymous Coward · · Score: 0

      Any language that allows the programmer to override the '=' operator is truly, verily, bad.

      a = b; is the same as a.copyOf(b). Why is that so hard to understand?

      Java even has its own similar feature clone(). Which was designed so badly that nobody should use it, in stark contrast to operator= which is one of the central parts of value semantics in c++.

      In c++ operators are just fancy names for function calls, there is no magic, nothing hard to understand. Its just plain simpler to read 20 * a + b * c instead of new SomeNumber(20).times(a).plus(b.times(c))). If you can't believe that b * c acts as it should how can you trust b.times(c) ?

    18. Re:Ahhhh, C++ by ChrisMaple · · Score: 1

      The ability to overload operators makes it possible to write human-readable code. A class of matrix math, or non-standard length floats, results in code with a few operator symbols instead of a mass of function calls or macros.

      There are advantages to using C++ wisely. If comments don't make it clear what's happening, it hasn't been used wisely.

      --
      Contribute to civilization: ari.aynrand.org/donate
    19. Re:Ahhhh, C++ by spitzak · · Score: 1

      I don't know why you want to modify strings in-place. Seems like you are complaining that it is not C-like. It would be much better if values were returned, for instance your "mystring.replace("from","to")" would not change mystring, but instead return a new string with the replacement done.

      One of the biggest mistakes in std::string is that operator[] returns a non-const reference. This is so all those people raised on Visual Basic could capitalize by doing a[0]=toupper(a[0]). It also means that efficient copying of strings by using reference counts is impossible.

      Making it a template just because a bunch of loonines thought that you could not do Unicode unless you made all the characters the same size was another mistake. Not only is the code unreadable and impossible to optimize, those idiots ended up with UTF-16 which is variable sized anyway. Duh.

    20. Re:Ahhhh, C++ by Pseudonym · · Score: 1

      I think this is exactly backwards. I've been using C++ for 20 years, and in my experience, it's the inclusion of Simula-style classes which was the clear mistake in retrospect. Almost every well-written C++ program uses the class system as a module system, and limits inheritance to abstract base classes only.

      The STL is one of the few things that makes C++ worth using. The template syntax sucks, but that's explainable by all the good syntax already being taken.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    21. Re:Ahhhh, C++ by JustNiz · · Score: 1

      Yeah I take it you're a web developer or something similar where most code is considered throwaway or "here today gone tomorrow".

      Auto code generation of any kind just doesn't fly (literally) in my field (embedded, avionics).

    22. Re:Ahhhh, C++ by putaro · · Score: 1

      You can abuse the C pre-processor as well. The early versions of the Bourne Shell are, essentially, written in Bourne Shell through the use of a mess of C macros. When I was working at a Unix vendor I was assigned to track down a bug in the shell and that was just...wrong. Some time around Sys V somebody un-macro'ized the code.

    23. Re:Ahhhh, C++ by byuu · · Score: 1

      I don't know why you want to modify strings in-place

      Because I care about performance? Memory allocations are extremely heavyweight. Doing that in a tight loop (say, an assembler building a large project) can really bog down your performance. It's nice to offer both, but you'd need some kind of naming convention since they can't both be called replace. So when I don't want in-place, I just say auto copy = string{mystring}.replace("from", "to"); and move semantics avoids the extra copy.

      std::string doesn't offer either version of replace (in-place or new copy), it just has a version that is basically memcpy with bounds-checking. That assumes you already know where the string is, and that from/to are of equal length.

      Making it a template just because a bunch of loonines thought that you could not do Unicode unless you made all the characters the same size was another mistake. Not only is the code unreadable and impossible to optimize, those idiots ended up with UTF-16 which is variable sized anyway. Duh.

      Oh, don't get me started on UCS-2/UTF-16, wchar_t and A/W (Windows) nonsense. I've built wrapper functions for basically every Windows function so that I can use UTF-8 like sane people. I can't believe all that BS still exists, even after surrogate pairs came about.

    24. Re:Ahhhh, C++ by Anonymous Coward · · Score: 0

      I don't know avionics, the code might have to be reviewed, if you are talking about actual people avionics, but in embedded world there is nothing stopping you from using auto code generation. It doesn't have to be the whole code being auto generated, but maybe an interface or something.

    25. Re:Ahhhh, C++ by Anonymous Coward · · Score: 0

      QT is awful. Any helper library that also needs its own preprocessor has definately lost the plot somewhere.

      Qt pre-dates the first real C++ standard by several years, there where few things it could rely on. The C++ standard also has an aversion to useful meta data something Qt uses heavily.

      QT also enocurages bad programmers to use endless amounts of signals and slots that break encapsluation and obscure program flow

      Bad programmers do what bad programmers do.

    26. Re:Ahhhh, C++ by Anonymous Coward · · Score: 0

      I find this such a strange argument. Can you tell me exactly what the value of c is, looking at the code below in isolation?

      typedef struct
      {
              int numerator;
              int denominator;
      } rational;

      rational a = { 1, 2 };
      rational b = { 2, 3 };
      rational c = multiply(a, b);

    27. Re:Ahhhh, C++ by Anonymous Coward · · Score: 0

      That's bad, but what's worse is that C++ REQUIRES you to define many standard operators for many of your classes if you plan to use them in certain ways. (Not "requires" in the standards sense, but in the "otherwise your program won't work right" sense.)

      When you start to read all the best practices for defining classes in C++ (e.g. the Rule of Five, copy&swap, etc.), it becomes clear that there are some serious design problems with the language.

      And "modern C++" is only worse in this respect, since now you have to handle all those things but you're also writing more code to account for move semantics.

    28. Re:Ahhhh, C++ by Anonymous Coward · · Score: 0

      I don't know if you just woke up from a 20 years sleep, are a paid troll, or just work for Fox News...

        FYI : what you call "STL" is dead, has been for 15 years basically. The Standard C++ Library is (yes I know crazy) some kind of Standard yes, in that it is well... ISO ! Most of the great Boost libraries were standardized, the overwhelming too crappy ones (or just too specific) were left alone in Boost.

        Qt keeps augmenting the language with very complex, additional constructs that will bite you in the ass so hard your balls will fall off.. I mean I love it, but the moron who thinks Qt simplifies C++ hasn't written a C++ or Qt line in the last 10 years.

        I've done almost exclusively C++ \ Qt in the last 5 years. I've trained people on massive code-bases using this technology, people with various coding experience.

        It is much harder to train someone to use correctly Qt than it is to use correctly Standard, idiomatic, typical C++11/14.

        Qt is BIG. It is a bit bloated, the performance trade-offs are not explicit all the time, and it is possible to write (almost C like) complex spaghetti code with signal×slots that "it isn't even funny" to quote Linus. I mean it is a MILLION times better than Gtk, for coding and for cross platform, but still. QMake is somewhat nice for simpler stuff. The translation stuff works great.

        Basically you are considering C++ like you are C, which is a classic C coder mistake. C++ evolves MUCH faster. It is beens really transformed in the last 15 years in a retro-compatible WAYv !!!! C is basically the same.

    29. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      Oh what utter bullshit.

      Because in any other language you magically know what the do_stuff() function that's referred to but not defined on that page is.

      In C++ = means operator=(). + means operator+(). etc etc.

      If you don't understand that then you simply don't understand C++.

      --
      SJW n. One who posts facts.
    30. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      Out of interest, what do you use? Something stricter like Ada?

      Don't get me wrong, I like C++ a lot, especially for scientific computation. It allows me to tackle much larger projects single handed than any other language would. But I can see why avionics people might want to steer clear.

      --
      SJW n. One who posts facts.
    31. Re:Ahhhh, C++ by petermgreen · · Score: 1

      On the other hand in a language like C or java any code that needs to work with a custom numeric type (complex numbers, integers modulo something other than a power of 2, integers larger than the compiler supports, matricies etc) becomes a horrible mess of function calls (or macros in the case of C) that obscure the maths you are trying to write/read.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    32. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      The STL sucks.

      You've been doing this a lot recently: just making bald statements with nothing to back them up. So go on, share: why does the STL suck.

      (a clue: it doesn't).

      --
      SJW n. One who posts facts.
    33. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1

      Yes, I've been doing that a lot lately, because it's true. But don't take my word for it - ask Linus.

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    34. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      Well, I'm beginning to suspect you're simply a troll. You make bald, contraversial statements with nothing but very glib comments to back them up.

      Linus's comments on C++ have been thoroughly debunked:

      http://warp.povusers.org/OpenL...

      Do you actually have an opinion of your own that you can back up with any sort of reasoned argument?

      --
      SJW n. One who posts facts.
    35. Re:Ahhhh, C++ by david_thornley · · Score: 1

      Given a page of C code that calls functions not on the page, the meaning is indeterminate.

      Stroustrup explicitly decided not to leave stuff out just because it was abusable. If there was a good reason for a feature to be in (and he was pretty strict on that), he wouldn't reject it because somebody would do something stupid and confusing with it. You may disagree with that, but there are advantages, in that it's possible to have non-buiilt-in arithmetic types (like matrices or vectors or complex numbers) and work with them in intuitive and easily readable notation.

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

      In C++ (and C), '=' is the assignment operator. Is it your opinion that assignment from one class instance to another should be specified by the language? What do you do when an object has a pointer to allocated memory? Copy the memory? Only copy the ponter? What should the language define? Or should it be impossible to use '=' to assign a value to a user-defined type, so you can use an ugly and unintuitive function instead?

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    37. Re:Ahhhh, C++ by BlueTrin · · Score: 1

      Although I use C++ myself, I would like to see someone reply to the debunk link you posted.

      Only when there has been a thorough exchange going both ways, we can affirmed that each of his point has been debunked properly

      --
      Don't you know it is now both immoral and criminal to think beyond the next quarterly report?
    38. Re:Ahhhh, C++ by spitzak · · Score: 1

      auto copy = string{mystring}.replace("from", "to"); and move semantics avoids the extra copy.

      The string constructor does an unnecessary copy. You are correct that move semantics avoids yet another copy from the result to "copy". I have not found any way to do this except by having two different functions, one which does an in-place modification and another that returns a newly constructed string. This produces questions about how to name them, as only one of them gets the "good" name.

      I have seen attempts to make a "modstring" subclass where the methods happen in-place. Not sure if this is a great idea.

      I suspect disagreement about how to do this is why all these useful functions have not been added to strings.

      In any case I also apologize, your style of in-place modification would not prevent reference-counting implementations. The problem is operator[] only. If in fact you changed characters with a string.replace_char(n,c) it could be done with reference counted strings.

    39. Re:Ahhhh, C++ by spitzak · · Score: 1

      Thanks for your comments about UTF-16 and Windows. You are correct that wrapper functions are about the only solution on Windows. Microsoft refuses to make the multibyte api accept UTF-8.

    40. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      Well, you can read it and form your own opinion, too. I think it's a very well written article, and does point heaps of easily identifiable logical fallacies in the original rant.

      --
      SJW n. One who posts facts.
    41. Re:Ahhhh, C++ by gnupun · · Score: 1

      Java solved it correctly -- just copy the pointer, instead of overloading the '=' operator. When you you see a simple statement like shown below in C++,

      a = b;

      you may be unaware that an assignment operator overloaded function may be lurking in there and the side effects that are caused by it. It would be worse if b were part of a function/method's arguments. It's just poor design -- add hacks to solve a problem and end up creating more problems.

    42. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1

      Here's a thought - why don't YOU try to debunk part of it, by playing the devil's advocate.

      I have no problem using C++. I have a HUGE problem with templates, TR1, and the STL. Ever run into a programmer who claims a decade of C++ experience, but if it's not in the STL or a class available online, they're lost? These are the same jokers who can't figure out when to use inheritance and when to use composition/aggregation. They're painful to work with.

      Just one example to start with. The gets() argument is bogus. You've always been free to replace it with your own implementation. Also, when it was created, it wasn't a problem because the input field from the terminal device wouldn't allow the user to input enough characters to overflow the buffer. Or you could use getc() and write into your own buffer. Or you could write your own terminal handler, since it's all serial anyway.

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    43. Re:Ahhhh, C++ by tibit · · Score: 1

      About 80% of my work is embedded. You still writing out those state machines by hand? Tsk tsk tsk. I can't even begin to imagine being productive in embedded work without lots of code-generating tools. With a proper high-level language used to define communications protocols, for example, I can do in a day what would probably take me two weeks after all bugs are out. I have many such examples. I only use code generation because it works. And the code it produces can be as pretty, readable and comprehensible as I want it to be.

      --
      A successful API design takes a mixture of software design and pedagogy.
    44. Re:Ahhhh, C++ by david_thornley · · Score: 1

      Java solved it for some cases, and if you're dealing with pointers in C++ you can do the same copy.

      I am very aware that an assignment may be an overloaded assignment operator, since I write those things frequently. What I don't see is what the problem is, provided the program is written reasonably well. The assignment operator will do the right thing (whatever that might be), as efficiently as you'd expect, with no surprising side effects.

      In order to keep this going effectively, you do need a culture of code reviews. C++ is a powerful tool, and it's easy to do lots of damage if you're stupid, but it's very effective when used properly. I consider it the Swiss Army chainsaw of languages.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    45. Re:Ahhhh, C++ by BlueTrin · · Score: 1

      I did form my own opinion, this rant from Linus is fairly old and I discussed it many times with colleagues and friends. When I discuss it with friends, opinions varies alot about STL, some are pro-STL and some others are anti-STL. Some mention boost and how C++11 improves or not things, ... etc.

      I agree with you that the article has many valid points, I just want to see a reply to this article.

      --
      Don't you know it is now both immoral and criminal to think beyond the next quarterly report?
    46. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      Here's a thought - why don't YOU try to debunk part of it, by playing the devil's advocate.

      Because I agree with it. To play devils advocate I'd have to engage in logical fallacies and sophistry for the sake of it. I have no desire to do that.

      I have a HUGE problem with templates, TR1, and the STL

      So you keep saying, but you've never said why.

      but if it's not in the STL or a class available online, they're lost?

      Programmers who don't really get programming and rel exclusively on libraries and stack overflow code snippets are universal. Nothing special about that, and nothing specific to C++.

      And about the rest: huh???

      --
      SJW n. One who posts facts.
    47. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      I did form my own opinion,

      Care to share? Seriously, what is your opinion?

      --
      SJW n. One who posts facts.
    48. Re: Ahhhh, C++ by BlueTrin · · Score: 1

      I just do not want to join this flamefest. If I knew you, I would not mind discussing it but just read the comments here: I do not want to be flamed.

      The short version of my opinion is that C++ has a lot of libraries and I see many people who do not understand how the STL is implemented or even read any kind of documentation. Because in some places you can get by, if you are not curious by nature you might end up writing poor code. Also, in some places, for some reason people use C++ even though they shouldn't: this is very common in the Finance industry for example and many of these programmers cannot be bothered learn more than the basics of syntax and learn using he code base which was itself written by some people who were new to C++. This ends up creating teams of people who write bad code. For some reason, newcomers to C++ are prone to over engineering and complex classes hierarchy with multiple inheritance.

      I have been working on some horrible code base with massive god objects with horrible state mechanism and objects containing a mix of raw and safe pointers on anything that is related without any kind of logic written by random people who probably learned C++ while writing their code 7 to 10 years ago ... Etc

      I also believe that some languages filter a bit more subpar programmers as they are not as mainstream.

      However, I enjoy reading opinions of people who have much more experience than myself and discuss them with some colleagues and friends.

      --
      Don't you know it is now both immoral and criminal to think beyond the next quarterly report?
    49. Re: Ahhhh, C++ by BlueTrin · · Score: 1

      Befor you correct me: this can happen in any language but for some reason it seems that C++ was the first language of many sub par programmers and I see bad and costly to maintain C++ code at work than in any other language.

      --
      Don't you know it is now both immoral and criminal to think beyond the next quarterly report?
    50. Re:Ahhhh, C++ by Bent+Spoke · · Score: 1

      Worse, to understand any of a C++ program, you need to understand all of it, due to the tentacles of inheritance ...

    51. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1

      I already debunked the gets() argument. Maybe I'll do the others. Maybe not. It's not a priority of mine. For what it's worth, c isn't perfect either. Far from it. I've always said Java sucks as well, but that doesn't stop me from using it. Perl is line noise, but I use it as well. There are parts of c++ I like. But there's a god-awful ton of stuff that's been larded onto it that should properly NOT be shoved into the standard.

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    52. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      So, your one debunking about C++ is an ancient C library function that was grandfathered in and is long deprecated even though it's not actually been removed. Funnily enough it's not part of the standard library generally referred to as the STL (i.e. the SGI derived stuff).

      So basically you have yet again failed to provide any substance to your claims, instead resorting to misdirection.

      So all I know is according to you the "STL sucks", but I have not the slightest clue why you think that. Your unwillingness to actually answer leads me to think that you've simply formed your opinion form loads of misinformed anti C++ rants on the internet and don't really have an opinion of your own.

      --
      SJW n. One who posts facts.
    53. Re: Ahhhh, C++ by serviscope_minor · · Score: 1

      I just do not want to join this flamefest. If I knew you, I would not mind discussing it but just read the comments here: I do not want to be flamed.

      I do try to avoid flaming people who are reasonable but I disagree with. It's just the "lol C++ sux" people that annoy me because they post nothing but emotional fluff culled from internet rants.

      For some reason, newcomers to C++ are prone to over engineering and complex classes hierarchy with multiple inheritance.

      There are some languages which seem to trigger this, Java is another one. I'm beginning to form a hypothesis. Both languages are designed to provide facilities for BIG projects, where large scale engineering is needed to manage complexity. I think in many cases seeing those facilities is like a red rag to a bull, and people start to envision the awesomeset massive system that does everything, and then completely overuse said features.

      I think providing the facilities for large engineering makes the ability to overengineer sit right at your fingertips.

      I'm not saying this is a minus point: large projects are hard withoug such features, but it does require a bit more taste, restraint or guidance.

      first language thing from other post

      Yeah. That was certainly a big problem in the 90s. Then Java took a lot of the heat and they had exactly the same bad effect on the Java ecosystem. C++ and Java are slowly recovering, but the reputation is taking a while to shed. I don't know where the mediocre hoards who love massive overengineering are currently.

      --
      SJW n. One who posts facts.
    54. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1
      The article you quoted gave that as an example, so I debunked it. Not happy? That's not my problem. You set up a challenge under YOUR terms, I complied, and now YOU'RE all butt-hurt?

      BTW:

      Here's a thought - why don't YOU try to debunk part of it, by playing the devil's advocate.

      Because I agree with it. To play devils advocate I'd have to engage in logical fallacies and sophistry for the sake of it. I have no desire to do that.

      You refuse to engage in even the appearance of trying to find holes in your logic - they must love you at church, where you accept everything without question. But you'd fail any course in philosophy or critical thinking, or even debugging 101. And you'd get an F in science, since they all involve challenging your assumptions at one point if you're doing it right.

      In other words, your argument is that of a pseudo-intellectual poseur. Have a nice day in your closed world. :-)

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    55. Re:Ahhhh, C++ by JustNiz · · Score: 1

      We use C or C++ with provisos depending on what Design Assurance Level (A-E) the product is, (See FAA standard DO178B that covers software development for avionics). We have to comply with our processes based on DO178B so depending on the DAL of the project we may or may not be able to use mechanisms that lead to unpredictable code paths such as exceptions, recursion, inheritance etc. IMHO the actual effect of that is to make the risk of potential problems worse.

    56. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      The article you quoted gave that as an example, so I debunked it.

      I've been trying to get you to elaborate on "STL sucks" with something more profound than your usual "lol stl si teh sux0rZ11!!11 trolololoollolol sux lolol!!!" line of argument.

      So far in order to prove the STL sucks, you've picked on an ancient, long deprecated C library function grandfathered into C++ from it's C heritage and ignored the STL (i.e. SGI STL derived portions of the standard library) entirely.

      So far all you've debunked is the idea that you have the slightest understanding of either C or C++.

      You refuse to engage in even the appearance of trying to find holes in your logic

      Um, if I'd spotted holes in my logic, I'd have fixed them before posting the argument. Unlike you who apparently blathers the first thing that comes to mind all over the internet without letting any rational part of the mind intervene. In your case, I certainly admit it would be exceptionally easy to play devils advocate since your arguments are completely nonexistent.

      In other words, your argument is that of a pseudo-intellectual poseur.

      OK, well, let me spell out my argument for you one more time:

      Unless you provide some form of argument for why the STL sucks beyond "It sucks", then you're basically full of it.

      --
      SJW n. One who posts facts.
    57. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1
      As I said before, the reasons (excuses, really) to refuse to play devils advocate are bogus and indicate someone who is not capable of critical thinking. You're still a poseur.

      So far in order to prove the STL sucks, you've picked on an ancient, long deprecated C library function grandfathered into C++ from it's C heritage and ignored the STL (i.e. SGI STL derived portions of the standard library) entirely.

      No - the link YOU chose did that, - did you even read it????

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    58. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      This is hilarious:

      You can't rebut my arguments and so your new tactic is to demand that I rebut my own because REASONS (i.e. ad-homenin attacks).

      okeydokey. How about no. You see a debate is generally between at least two people, one person arguing one side and then the same person arguing the other side.

      No - the link YOU chose did that, - did you even read it????

      Your responses in this thread are so garbled and meandering that I literally have no idea what you are even talking about any more.

      I also see that in the other thread you eventually quietly gave up trying to assert GCC is worse than everything else because RMS and GPL despite all evidence to the contrary.

      --
      SJW n. One who posts facts.
    59. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1

      GCC is on the way out. Everyone sees the writing on the wall - except you, I guess.

      Also, don't blame me for your choice of articles to rebut. If you like the STL, then use it. I don't. I won't. Problem solved.

      Honestly, I'd rather go back to writing in assembler than be stuck with the STL.

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    60. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      GCC is on the way out. Everyone sees the writing on the wall - except you, I guess.

      Uh, well I don't know what the future of GCC has to do with what it's like now. You claimed that the commercial compilers are better: a fact which is objectively untrue by many measures. But yet again you twist and squirm and try to avoid having to support the point you made.

      Honestly, I'd rather go back to writing in assembler than be stuck with the STL.

      And you you haven't even given a single reason beyond "I don't like it" why. Hell, I like the STL and yet I can point to many flaws in it. You've not managed to point to a single one.

      --
      SJW n. One who posts facts.
    61. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1
      Search for c++ barf bag. Others have already gone into it at great length. However, it's obvious you've been trolling all this time if you finally admit the stl is flawed.

      As I said before, I don't like it. It's fugly. If you like it, that's your business. I don't have to subscribe to your world view.Templates are ugly as well, but that's another issue. Template meta-programming was an accident. That it's been leveraged to what it is today, well, that's not my problem.

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    62. Re:Ahhhh, C++ by spongman · · Score: 1

      > Generally, if you need a program to write code for you, chances are you have other problems

      My compiler writes assembly code for me. Is that a problem?

    63. Re:Ahhhh, C++ by spongman · · Score: 1

      yay, the "i haven't yet worked out how to use it effectively in my job, so it must be useless for everyone" fallacy.

      thanks for helping me with my flame-war fallacy bingo card.

    64. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      Search for c++ barf bag.

      I did, nothing obvious came up.

      However, it's obvious you've been trolling all this time if you finally admit the stl is flawed.

      Only in your weird little world. It's not perfect but it's not fatally flawed in any way. IOW good, but not perfect.

      As I said before, I don't like it.

      Yes and that's all you've said.

      It's fugly.

      Well, that's a rational, well thought out argument.

      --
      SJW n. One who posts facts.
    65. Re:Ahhhh, C++ by crunchygranola · · Score: 1

      Big, big difference between explicit function references (known to have definitions elsewhere) and redefining the meaning of arithmetic primitives.

      Stroustrup explicitly decided not to leave stuff out just because it was abusable. If there was a good reason for a feature to be in (and he was pretty strict on that), he wouldn't reject it because somebody would do something stupid and confusing with it.

      And C++ stands as a monument to what you get when you follow that philosophy.

      Notice that other languages since have tended to focus on a tighter coherent set of core features.

      --
      Second class citizen of the New Gilded Age
    66. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1

      Code can be beautiful. It contributes to its maintainability. You will never hear that accusation made against the STL.

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    67. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      Code can be beautiful. It contributes to its maintainability. You will never hear that accusation made against the STL.

      The STL is well designed: code using the STL is much more maintainable tha nthe alternatives. There you go, I made precisely that accusation.

      Now put up or shut up. What *precisely* is bad about it.

      --
      SJW n. One who posts facts.
    68. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1

      Let's reverse the question - what is so good about it that it should qualify as a part of the language standard?

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    69. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      OK, fine.

      Let's reverse the question - what is so good about it that it should qualify as a part of the language standard?

      The entire concept based design is extremely elegant. The idea of separating data and algorithms based purely on small sets of semantics of the data and datastructures is an extremely elegant idea and pretty revoloutionary when it was introduced.

      The result it a standard library which is elegant to use partly because you can extend it with your own containers and yet it still interacts with the other STL algorithms and facilities in the same way as the original containers.

      It also means that the algorithms can be applied to a container appropriate to the task. For example many languages provide a priority queue. With the STL, the implementation is independent from the container. Therefore when I'm all the way down on a deep embedded device, I can use a pqueue on a statically allocated chunk of memory rather than the free store, and this works because the general separation of concerns by concept.

      So, the underlying design is very sound and esentially splits things by rather high level ideas into orthogonal chunks.

      The STL also provides a lot of useful algorithmic primitives, such as set union, difference, symmetric difference, heap primitives, nth_element and so on and so forth. It's one of the best libraries I've used in that regard.

      The implementation is generally fine. For example making a resizable vector, or a map or set, etc is simple and easy, the code is short and straightforward to read, so much so that the gross syntax has been quite widely adopted across other languages too.

      Finally the principle of "do't pay for what you don't use" is stuck to in the STL. I write a lot of high performance code (numerics/scientific) and I can generally make do with the STL, and image class and some linear algebra ones. The STL is efficient enough that I almost never need to reimplements something for speed.

      So, there you go. 4 reasons why it's a good library.

      --
      SJW n. One who posts facts.
    70. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1

      In the end, it's your opinion. If you think that someone who can't write their own resizable vector, map, or set should be allowed in the playpen, you're entitled to it. However, I agree with Linus on this one. C provides a barrier to entry, as does C++ without templates or the stl. I've seen programmers who can't write a simple string or bchunk class, or a linked list on their own. They're just one step above "google cut-n-paste" coders.

      That's just my opinion, but let's face it, if you can't write them yourself, then you really don't know what's going on behind the scenes, and when it comes time to implement something outside that collection, you're kind of hosed.

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    71. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      In the end, it's your opinion.

      It is, but you've yet to provide a reason for your own. The reasons you provide below are essentially against any lanuage ever from having any kind of standard library. That applies equally well across the board.

      If you think that someone who can't write their own resizable vector, map, or set should be allowed in the playpen, you're entitled to it.

      Well, you can make up opinions that you believe I have if it suits you. It doesn't make you correct however. I never claimed that at all.

      One *ought* to be capable of writing all the basic data structures and algorithms from scratch. I certainly have, for example my static_vector class which presents the same resizable array concept as std::vector, but is backed by a stack allocated, fixed size array. I've also (in the past) written heaps, sorts and all that sort of thing.

      The question is, though, why on earth would I want to do that every time? Algorithmically, it makes no sense. If every (N) programmers maintains a library of M basic structures, there's O(MN) effort, required. If however the library is more or less centrally maintained, it's O(M) effort. Implementing a sorting algorithm which is both bug free and efficient on a wide variety of data is frankly a pain in the ass (see e.g. the recent Timsort bugs). Can I do it? Yes: I have my own radix sort kicking aroud for special occasions. Do I want to? Nope, not unless I really, really need to.

      The main implementations of the STL must be some of the most well specified and thoroughly tested code out there in existence, and so I can be sure they're going to work bug-free every single time on more or less any of the major platforms.

      Secondly, If everyne uses the same library of basic structres, it cuts down on the effort because I don't have to figure out how to represent a serviscope_minor::vector as a barbra_hudson::resizable_array.

      I don't have to take the time to figure out that your .append() method is the same as mu .push_back() or whatever.

      --
      SJW n. One who posts facts.
    72. Re:Ahhhh, C++ by BarbaraHudson · · Score: 1

      I have no problem with a language having a minimalist standard library. The current c++ goes well beyond that. There's no need for more - people can share their own creations that do the necessary jobs and only the necessary ones, without creating a huge tangled web of dependencies that make debugging harder.

      That was the original vision. It's been perverted. We've seen this pushed to the extreme with Java. I have no problem with it being an option, chosen by the end user, same as Boost was; but to push it into part of the language itself was a bad idea.

      You'll notice that even "you said you can do so if you really really need to" - how much do you want to bet that the average STL user can't? Which makes you wonder if they're not just "black box programmers."

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    73. Re:Ahhhh, C++ by serviscope_minor · · Score: 1

      I have no problem with a language having a minimalist standard library

      Alright then, where do you draw the line?

      Can you comment on my remark about the effective complexity of having eac hprogrammer with their own library?

      I have no problem with it being an option, chosen by the end user,

      It pretty much is in C++: it sticks to the "don't pay for what you don't use" principle. Using std::vector won't introduce iostreams. Using std::map won't bring in std::sort.

      how much do you want to bet that the average STL user can't?

      No idea. But back in the 90s they just used third party libraries anyway. A lack of libraries won't make awful programmers better.

      --
      SJW n. One who posts facts.
    74. Re:Ahhhh, C++ by JustNiz · · Score: 1

      No it doesn't write code. It compiles the code you wrote. Thats why its called a compiler.

    75. Re:Ahhhh, C++ by spongman · · Score: 1

      i'm sorry, but most compilers use another language as an intermediate representation. gcc uses several of these, including a couple of abstract trees and platform-specific assembly. c-front used C, as did ghc. moc uses code as an intermediate representation. it's common practice in the industry.
      get. over. it.

    76. Re:Ahhhh, C++ by JustNiz · · Score: 1

      No you get. over. it, Your statement is clueless.
      The compiler is not doing anything creative or original at all so it is definately not WRITING code. It is simply compiling it which most usually includes intermidiate steps such as conversion to lexemes, then to trigraphs, then to assembly, then optimized assembly, then target-specific binary.
      Each step is simply converting the output of the previuos step to another logically equivalent form. There is no create input so It is not writing (i.e. creating) anything at all itself. That is ONLY the file you wrote that forms the initial input.

    77. Re:Ahhhh, C++ by spongman · · Score: 1

      > Each step is simply converting the output of the previuos step to another logically equivalent form.
      and moc is doing what different, exactly?

    78. Re:Ahhhh, C++ by JustNiz · · Score: 1

      Generating source code.

    79. Re:Ahhhh, C++ by spongman · · Score: 1

      dude, you're a fucking moron.

      moc generates C++ code. gcc generates .as code. they both generate code, and they both use that code as an intermediate form.
      mov "converts the output output of the previous step to another logically equivalent form". as does gcc.
      with moc, you use a tool (gcc) to include the intermediate form in your final output. with gcc, you use a tool (as/ld) to include the intermediate form in your final output.

    80. Re:Ahhhh, C++ by JustNiz · · Score: 1

      >> dude, you're a fucking moron.

      "Dude" go fuck yourself.

    81. Re:Ahhhh, C++ by spongman · · Score: 1

      Nice argument, troll.

    82. Re:Ahhhh, C++ by GbrDead · · Score: 1

      Operator overloading is just a special case of polymorphism. By your reasoning, it is impossible to look at a page of code written in any OO language in isolation and know what it does, with confidence.

  15. Feature Request by Rhyas · · Score: 3

    Need the ability to moderate an entire Article/Summary as Clickbait or Troll.

    1. Re:Feature Request by jandrese · · Score: 1

      Isn't this what the tags are for?

      --

      I read the internet for the articles.
  16. Python/C++ Combo by EmperorOfCanada · · Score: 4, Insightful

    I have read maybe 1 billion articles about language X being better than language Y and in many cases it is pure religious fanaticism; someone has committed to a language and now justifies that commitment with zealotry. A very common refrain about any given language is how many people write poor code in that language. This argument is often reserved to support the more "sophisticated" languages. For instance it is pretty much a gold medal sport to crap on PHP; and yes there is lots of terrible PHP which probably stems from the fact that it is often someone's first language and that someone is self teaching.

    Then other languages are looked at as toy languages by those who resent them, Python would often be a victim here.

    Then there are the wonderful charts of speed which in theory would justify everyone using ASM optimized to their CPU.

    But for me it is not one language but a pairing that has caught my heart. Python and C++ do just about everything I want. Python is just so damn productive. Then I use C++ for where Python falls down on speed or the environment itself is not conducive to C++ (embedded and multi-platform Mobile).

    But to answer his cry about people over-engineering things with silly STL uber inheritance type crap. That is where oddly enough the zealots of C++ are their own worst enemies. They love C++ so much they are giving it a bad name. Many people use STL in some purist way that completely blows Keep It Simple Stupid out of the water.

    But I really do hold a special revulsion for anyone who claims that their language "Enterprise" which translates to me as so shitty that nobody will notice that most of your drone developers are also shitty.

    1. Re:Python/C++ Combo by Anonymous Coward · · Score: 1

      Er, STL? Inheritance? What planet are you on? STL almost exclusively uses compile-time generic programming via templates. The only time you'd ever use inheritance with the STL is if you're writing your own iterators or allocators.

    2. Re:Python/C++ Combo by Anonymous Coward · · Score: 0

      Objective-C++ allows C++ for the speed, while objective-c has about the same semantics as python.

    3. Re:Python/C++ Combo by Dan667 · · Score: 4, Interesting

      why not Python and ANSI C? Then you have productivity and glue code of Python and the raw speed of C without all the clutter.

    4. Re:Python/C++ Combo by Trailer+Trash · · Score: 1

      PHP is awful regardless of who uses it. The language was created as a Perl for Dummies and never moved beyond its roots until version 5 (which retains backward compatibility with all the madness). Any "extensions" - such as the ability to access an RDBMS server - had to be compiled in to the interpreter since the language initially didn't have the various pieces necessary to write such connecting code in actual PHP. And these extensions simply dumped a bunch of crap into the global namespace. So, if you compiled in support for MySQL, you ended up with a bunch of "mysql_whatever" functions to call. Better yet, there was little to no coordination between projects so mysql_whatever functions may or may not have analogous pgsql_whatever functions should you want to change to another RDBMS.

      While a lot of that has been fixed there are simply a lot of historical problems like that. I don't see those sorts of issues in C++, Python, Ruby, Perl, or most other modern languages. No, PHP is a breed apart.

      Other than that I agree with most of what you say. I don't find C++ to be terrible but I haven't touched it in 15 years, either.

    5. Re:Python/C++ Combo by phantomfive · · Score: 2

      I'd rather work with skilled programmers in assembly than lousy programmers in (whatever amazing language you have).

      It's the programmers that matter, not the language.

      --
      "First they came for the slanderers and i said nothing."
    6. Re:Python/C++ Combo by radtea · · Score: 2

      But for me it is not one language but a pairing that has caught my heart.

      I'm in the same boat, with the same languages. Python for convenience, C++ for speed. I also use C for really low level embedded (PIC) stuff, but that's it.

      This combination gives me the optimal mix of portability and power for the problem domains I'm interested in, and at this point I don't see any reason to leave C++ for anything else. The big trick is to adopt and strictly adhere to a set of reasonable coding standards that keeps you from doing all the stupid things the language lets you do.

      C++ demands a higher level of discipline and maturity from developers than most languages because Linus is right: it is incredibly easy to abuse. A bad programmer will write bad code in any language, but C++ makes it really easy for bad programmers to express themselves, and that's a bad thing. That doesn't mean the language is bad, but it does mean it should only be used where its advantages (portability, efficiency, expressive power) are sufficiently great to overcome its weaknesses (excessive complexity, mediocre type safety, excessive complexity.)

      --
      Blasphemy is a human right. Blasphemophobia kills.
    7. Re:Python/C++ Combo by Bing+Tsher+E · · Score: 1

      PHP was created as a Personal Home Page toolbox.

      That's it.

    8. Re:Python/C++ Combo by Wootery · · Score: 1

      No, Objective-C is also really damn fast.

      Its method-dispatch is somewhat slower than C++'s, but it's by no means slow.

    9. Re:Python/C++ Combo by mvdw · · Score: 1

      This. I use python usually when I need the language features (libs etc), and C for my embedded stuff. I don't bother with C++; I find C to be more than adequate for my needs. Most of the "C++" I've seen written in the small embedded space is basically C with a bit of C++ syntactic sugar (Arduino, I'm looking at you). Why not just use C??

    10. Re:Python/C++ Combo by Anonymous Coward · · Score: 0

      People that care about performance don't use Python for glue code. They use Lua.

    11. Re:Python/C++ Combo by Anonymous Coward · · Score: 0

      Er, STL? Inheritance? What planet are you on? STL almost exclusively uses compile-time generic programming via templates. The only time you'd ever use inheritance with the STL is if you're writing your own iterators or allocators.

      Actually, the only time you'd use inheritance on the STL is if you wanted to create the most beautifully implementation-specific piece of code.

      The chance of something that uses STL inheritance compiles is so uncertain it makes quantum physicists blush.

    12. Re:Python/C++ Combo by Anonymous Coward · · Score: 0

      I agree with you. However, there are 2 or 3 classes from standard c++ that I always end up needing (or wanting) that prevent me from writing 100% C. Those are vector, map, and string.

    13. Re:Python/C++ Combo by EmperorOfCanada · · Score: 1

      Actually that pretty much describes much of my C++ code. But some of the modern C++ like how cleanly a vector can be iterated through is actually pretty damn useful. I don't think that I have had an off-by-one error in literally a few years.

    14. Re:Python/C++ Combo by EmperorOfCanada · · Score: 2

      Yup. Fully agreed. That is why enterprise languages exist. They aren't build for coding they are the devil's tools for building the 10th ring of hell (still under construction, 90% done, next milestone won't be missed just as long as that milestone is a report on why they are missing all the milestones)

      And who is sent to this coding hell? Crappy programmers.

    15. Re:Python/C++ Combo by EmperorOfCanada · · Score: 1

      I don't so much use it for glue code but I use it for whole programs. Once in a blue moon I will combine the two. But my primary thing is to use each for where it is best. Often I will have a shrink wrapped software product that uses data that has been massively noodled or will send data to a server for noodling. So the pre and post noodling will be done with python (in so few lines of code it is often obscene) and the shrinkwrapped shipped product will be in C++.

    16. Re:Python/C++ Combo by serviscope_minor · · Score: 1

      But to answer his cry about people over-engineering things with silly STL uber inheritance type crap.

      STL uber inheritance? I have no idea what the hell you are doing, but it's far, far away from what competent professionals consider C++. The STL uses little or no inheritance. In fct what you're doing probably isn't even C++ since deriving from std:: classes is forbidden.

      It's also one of the best designed algorithmic libraries out there. But sure, if you have a fetish for rewriting (again!) your own resizable array class, then be my guest.

      --
      SJW n. One who posts facts.
    17. Re:Python/C++ Combo by EmperorOfCanada · · Score: 1

      I was actually talking about two concepts that annoying people use. They will template things that really do not need to be templated. I have seen people using pretty much strange template type code almost at the initializing a variable level. But these same people tend to put everything they can into an object. Very Java-like in that they will use an object with getters and setters where a struct(or simpler) would have been perfect.

      I am not joking when I have seen people create classes where they will ever only be one instance of the class. It has no member functions other than getters and setters. The getters and setters only set and get (no business logic) and there are only a tiny few member variables.

      The icing on the cake is when people will do the above with inheritance. Then when called on this lunacy will say, "It isn't proper OOP otherwise." The same people after they have finished wearing out the angle bracket keys making ridiculous templates will also use the term "Modern C++" to defend themselves.

      What I find it boils down to is that there are people who's goal is to make clean code that works, and other people who lose site of why they are programming and focus on how they are programming.

    18. Re:Python/C++ Combo by serviscope_minor · · Score: 1

      Why not just use C??

      Or, why not just use C++? The "syntactic sugar" of C++ makes the code shorter to write and easier to read. And for embedded stuff, compare a good templated fixed point library to what you'd write in C. In C++ the code looks much like it would with ints or doubles, with all they syntax you expect (e.g. + means add), but works in fixed point instead.

      What's not to like?

      --
      SJW n. One who posts facts.
    19. Re:Python/C++ Combo by Alioth · · Score: 1

      I joke that if PGP stands for "Pretty Good Privacy", PHP stands for "Pretty Hopeless Privacy". The language practically encourages people to write code that suffers from SQL injection exploits.

    20. Re:Python/C++ Combo by serviscope_minor · · Score: 1

      ... OOP ...

      Well, there's bad programmers in any language. Java has been plagued with people making truly henious class heirachies and factory factory factories where "everything" can be done by configuring a 30MB XML file which contains pretty much an interpreter for a poorly specified and buggy mini ADSL in XML. It doesn't mean Java is a bad language, it just means there's a lot of morons using it.

      Those same idiots used to infest the C++ community, but all jumped ship over to Java a while back. It's been good for the C++ community, and bad for Java one that those guys all found a home there. C++ is still recovering but hasn't fully shed the reputation yet. The Java community seems to be recovering too (there's new options like Scala and Clojure so on) but is about 10 years behind.

      Modern C++, Stroustrup style is basically using generics where you need generics (usually in library code for things like containers), avoiding raw pointes, constifying the crap out of everything where possible and generally using the language "sensibly", i.e. not piling on code with obscure features just for shits and giggles. Unfortunately you can't teach some people good taste.

      I still don't see what that's got to do with the STL being bad though.

      "modern" C++ is about using the language feature appropriately and avoiding C like constructs, instead preferring the C++ ones which are shorter, safer and clearer.

      --
      SJW n. One who posts facts.
    21. Re:Python/C++ Combo by david_thornley · · Score: 1

      I've noticed that most Language X is better than Language Y arguments, or Language Y sucks arguments, are firmly founded on ignorance of Language Y.

      I really don't understand what you mean by "STL uber inheritance type crap". The STL has nothing to do with inheritance, but rather uses templates to be general. The use of the STL I see is generally to keep code simpler-looking and more obviously correct.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    22. Re:Python/C++ Combo by shutdown+-p+now · · Score: 1

      When dealing with Python, having RAII in the language helps immensely, because otherwise you're condemned to writing myriads of PY_DECREF and PY_INCREF calls by hand (speaking of clutter!). It's bad enough that you typically end up having more lines of code managing object lifetime than those actually doing something useful...

      It's much easier when you can wrap it into a smart pointer class that takes care of it all automatically.

    23. Re:Python/C++ Combo by shutdown+-p+now · · Score: 1

      Out of curiosity, what do you use to glue Python and C++ together? SWIG, Boost.Python etc. I mean, obviously this can be done by hand, but that adds considerable coding overhead in form of all that boilerplate code...

      Also, how do you debug such mixed code?

    24. Re:Python/C++ Combo by EmperorOfCanada · · Score: 1

      Actually I tend to use the two separately but in concert. I will deploy an app that is pure C++ but the data that was created for the app was processed using Python and then when the app calls home it is talking to python and the data sent back will be python processed.

      One interesting place where I do blend the two (C to be specific) is with OpenCL. Python will load and prepare the data into a Numpy array, then send it off to OpenCL for some abuse, then it returns and is maybe fiddled a bit more, and then put into some pretty format using Qt for the interface. This will soon be C++ as well seeing that C++ is apparently coming to OpenCL.

      In the above development there is a tradeoff as debugging OpenCL is a monster pain in the ass. So often when I would develop something that would use OpenCL I would do it as a function in normal world and then when I had it working port it to OpenCL and send it off to the GPU for the massive speed boost.

    25. Re:Python/C++ Combo by vilanye · · Score: 1

      A good PHP programmer is still using a language with so many flaws, corner cases and security holes that the end result is going to be bad.

      I have yet to meet a truly skilled programmer that would even consider PHP for anything.

    26. Re:Python/C++ Combo by phantomfive · · Score: 1

      Doesn't matter. Good programmers will work around the flaws of the language. I would still rather work with skilled programmers in PHP than lousy programmers in (whatever your favorite language is). And we will be faster, produce better quality code, with fewer bugs than your team. It's the programmers that matter, not the language.

      --
      "First they came for the slanderers and i said nothing."
    27. Re:Python/C++ Combo by Anonymous Coward · · Score: 0

      I wouldn't because there are problems with PHP that can not be worked around.

      Take two teams, both are filled with great programmers. Make one team use PHP and the other use Python or Ruby.

      The PHP team will not produce better software simply because PHP is crap and will likely take longer to get it done because they are hacking around all the warts of the language and runtime.

      Quality of programmers matters but the quality of the language matter more.

      PHP was written by an amatuer who hates programmer and would "rather restart apache 10 times a day" than do it right. It also has "devs" that actually thought that int_val > MAX_INT was how you check for integer overflows and that snippet is still part of the check to this day.

      A good craftsman knows better than to use a rock as a hammer. Good programmers know better than to use PHP. If a programmer uses PHP by choice he/she/it is not a good programmer by definition.

  17. Yes, he was wrong... by RailGunner · · Score: 5, Insightful

    If you care about performance, the ability of C++ to "run on the iron" is a valuable tool to have in your arsenal. Add in inline assembler, and IF YOU KNOW WHAT YOU'RE DOING you can write blazing fast code in C++ and still provide a sensible code architecture.

    There's no sense in blaming the language for the abuses developers have written -- you might as well indict English for the horrible spelling and grammar of many Americans...

    If you know what you're doing, C++ is a terrific, powerful language suitable for a plethora of projects. On the other hand, if you don't know what you're doing, well, I guess there's Visual Basic or C#.

    1. Re:Yes, he was wrong... by Anonymous Coward · · Score: 0

      All languages can be abused. *ALL*.

      I have seen monstrosities written in MSDOS batch script/NT CMD script/Rexx, Python, VB, VBScript, bash, Java, Javascript, C#, PSQL, T-SQL, C, C++, Perl, Pascal, ASM (x86, ARM, MIPS, and VAX11). Having written in most of these I can safely say this. They all can be abused. All.

      All it takes is a bit of time and using the wrong thing for the wrong job. Then poof you have a big tangly mess. Every single one of my examples you can write good clean code with. It just takes a bit of time and thought. Anyone who bashes down on any particular language because it is not more Scottish than something else is a boring person.

    2. Re:Yes, he was wrong... by Anonymous Coward · · Score: 1

      in expert hands it is blazing fast, but that doesn't get around the fact that C++ library API is freakin hideous and ugly. The people who designed those API have no taste. There are better low level languages today that doesn't have the butt ugliness of C++.

    3. Re:Yes, he was wrong... by phantomfive · · Score: 1

      If you care about performance, the ability of C++ to "run on the iron" is a valuable tool to have in your arsenal.

      At least try to understand what he was trying to say before claiming he was wrong. Linus uses C. He's going to say that if anything, the performance of C++ is worse than C (and of course, that depends on how you use both languages).

      --
      "First they came for the slanderers and i said nothing."
    4. Re:Yes, he was wrong... by UnknownSoldier · · Score: 0

      > you can write blazing fast code in C++ and still provide a sensible code architecture.

      Not if it is OOP based.

      Pitfalls of Object Ooriented Programming

      Mirror:

      *http://www.slideshare.net/roycelu/pitfalls-of-objectorientedprogramminggcap09

      * http://www.google.com/url?q=ht...">

      Us console game devs use DOD (Data Orientated Design) for highest performance.

      * http://www.yosoygames.com.ar/w...

      Mike Acton is a respected programmer in the video game industry, and he's right. In fact, if you were paying attention I listed his famous "Typical C++ Bullshit" as reference in my Ogre 2.0 proposal.

      OgreNode.cpp was written 13 years ago when OO programming was all the rave (still is?) everyone had a single core, caches didn't matter and most efficient way to cull the world was to use an Octree or a BSP. The world believed that "if( dirty )" was a magical, no-cost expression that is immediately a performance improvement wherever used to avoid the execution of more than 3 instructions.

      13 years later, Moore's law kicked us in the butt and everyone is multicore. You probably know that story already.

      Mike Acton reviewed the 1.9 version. Perhaps it would've been more interesting to see a review of the 2.0 file which has been refactored to better fit Data Oriented Design principles (and I'm sure there are things I wrote to criticize). Many of the things he criticizes of 1.9 have been fixed. Nevertheless there are things we can learn. Note that if he weren't right, then it would be hard to explain why there was a 5x performance increase between 1.9 and 2.0.

      * http://www.bounceapp.com/11641...

    5. Re:Yes, he was wrong... by Anonymous Coward · · Score: 0

      C++ does many things but 'running on the iron' (WTF, don't you mean metal or hardware) is the absolute least of its attributes.

      C was originally a high level DEC assembler; dest = *(++src++)++; could be coded in one line of assembler code. Although, it would be best if we didn't use that complex a reference. But it *could* be done as pre and post increments were merely bits (IIRC). You could do it on the destination as well.

      C++ has nothing on C for fast. C++ is a complex, many layered beast that has bloated beyond its useful life. Such that Python is mentioned in these comments many times. It is very difficult to use correctly, it is not intuitive to know how to get fast code out of it and the only positive is there are many C++ programmers. Easily 80+% of the language is never used by most programmers. Why? Because to use it they have to read the book(s) to fully understand the current versions interpretation of a feature.

    6. Re:Yes, he was wrong... by bigdavex · · Score: 1

      As opposed to C? WTF?

      --
      -Dave
    7. Re:Yes, he was wrong... by Anonymous Coward · · Score: 0

      C++ is not supposed to be faster than C, as most subsets it is slower. Enable stuff like rtti, exceptions, late binding, etc and it is considerably slower.

      On the other hand, you get stuff like...rtti, exceptions, etc.

    8. Re:Yes, he was wrong... by Anonymous Coward · · Score: 0

      C++ performance really isn't so special anymore C, Obj-C, Rust, Nim, D, Fortran, Ada... they can all produce fast code. In at least some cases all of those languages can even beat C++ performance as you can see by browsing here: (http://benchmarksgame.alioth.debian.org/).

      C++ has to stand on it's own merits as a language -- not the fact that it has compilers that can produce fast code. Because as new languages like Rust demonstrate -- if you design for low-level systems programming from the start, and use modern compiler technology, you can produce something demonstrably safer/better with similar performance characterstics.

    9. Re:Yes, he was wrong... by david_thornley · · Score: 1

      The performance of C++ is going to be about the same as the performance of C unless you start using library functions*. At that point, you'll find that the STL libraries make C++ a little better.

      *Some compilers will introduce a slight delay in function calls and returns to make exception handling easier, but this isn't usually significant, and many compilers give you the option to disable exceptions.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    10. Re:Yes, he was wrong... by phantomfive · · Score: 1
      C++ and C can obviously be as fast as each other, but once you start taking advantage of the C++ features (smart pointers, lists instead of arrays, rtti, exceptions, objects), you lose efficiency. C++ ironically was not designed to be efficient. Effective use of cache (i.e., aligning objects correctly in memory), branch prediction, and loop hoisting are the main techniques of efficiency on modern processors, whereas C++ design decisions seem to be aimed at counting instructions, which is drastically misleading (as the section entitled "Performance optimization is achieved primarily by counting the cycles of the assembly code" in the previous link explains).

      At that point, you'll find that the STL libraries make C++ a little better.

      I wouldn't assert that without timing it (if you did time it, please let me know, I want to hear it). The exact implementation of the library function is what matters (i.e., Microsoft's C++ sort function could be slower than GCC's C function which could be slower than G++'s C function which could be slower than Microsoft's C function. Unless you time it, you don't know).

      Someone a couple months ago on Slashdot asserted that they had timed the C++ STL algorithms and they were slower than the Java algorithms. I haven't had time to test it, but it's not surprising. Yeah, it's cool that the STL can automatically generate code to sort an array of shorts, but there are many other considerations that make an an implementation of an algorithm quick or slow, as of course you know.

      --
      "First they came for the slanderers and i said nothing."
    11. Re:Yes, he was wrong... by david_thornley · · Score: 1

      C and C++ both have their roots in a time when you didn't worry about cache performance. Currently, it seems to me that the two main things to look for when optimizing are algorithms and locality, rather than reducing instruction count. (This is why I'd be dubious of using std::list rather than std::vector: std::vector is guaranteed to have contiguous data, and std::list definitely isn't.) If I know what CPU the program would be run on, and the architecture, I'm sure I could do somewhat better.

      At first glance, std::unique_ptr should have no performance disadvantage compared to raw pointers, although std::shared_ptr would. std::vector and std::array between them should have no performance disadvantage compared to C-style arrays. At this point, I need to know something about the problem being addressed. Exceptions will slow things down, but the usual C alternatives are usually ignoring error returns (faster than exceptions), or checking them with if statements all the time (very likely slower than exceptions). RTTI has no C counterpart either.

      My timing assertion was based on a past Slashdot comment, in which somebody had done the testing. I'm not going to get to the testing this week, but I'll try to remember to do it. Testing C functions vs. C++ template functions is likely testing the same thing from the same vendor, but testing C++ vs. Java looks a little iffy to me, as it would depend both on the C++ and the Java implementations.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    12. Re:Yes, he was wrong... by phantomfive · · Score: 1

      My timing assertion was based on a past Slashdot comment, in which somebody had done the testing. I'm not going to get to the testing this week, but I'll try to remember to do it. Testing C functions vs. C++ template functions is likely testing the same thing from the same vendor, but testing C++ vs. Java looks a little iffy to me, as it would depend both on the C++ and the Java implementations.

      If you get around to timing it, be sure to let me know how it goes. Maybe even write a slashdot journal entry on the topic or something, I'm sure people would be interested in your results.

      --
      "First they came for the slanderers and i said nothing."
  18. Headers are not real by Anonymous Coward · · Score: 1

    There are good features and there are bad features. If you don't like funky object features don't use them. Destructors are great for end of scope clean up. Having to rely on exceptions to catch constructor errors suck.

    The deal breaker for me is the poorly designed header system. I cannot write a class without truly hiding its inner working. I have to put all of my variables in the header even though they have nothing to do with the functionality i expose to the external callers.

    I add an irrelavant variable and everybody who includes my header needs to recompile.

    For me c++ and gets in the way of mental separation of functionality into modules and libraries. So i suspect they were not designed by people who actually worked on large projects. They look good on paper and in the classroom no doubt.

    1. Re:Headers are not real by chad.koehler · · Score: 1

      The deal breaker for me is the poorly designed header system. I cannot write a class without truly hiding its inner working. I have to put all of my variables in the header even though they have nothing to do with the functionality i expose to the external callers.

      No you don't. If you think you do, you don't know the language as well as you think.

    2. Re:Headers are not real by crunchygranola · · Score: 1

      There are good features and there are bad features. If you don't like funky object features don't use them...

      Because everyone writes code from scratch just for their own use?

      This lame excuse for a extremely over-complicated language laden with bad features is simply ludicrous in the real world where 80+% of programming is maintaining code that somebody else wrote. Any feature that makes that harder, is a "misfeature".

      --
      Second class citizen of the New Gilded Age
    3. Re:Headers are not real by david_thornley · · Score: 1

      Header files are a pain, but if there's no way to get the size of an object it will be necessary to allocate all class instances on the heap and use pointers for them, which has its own costs.

      If you want to hide the class internals, there's probably some version of the "pimpl" idiom that will do what you want.

      Header files were part of K&R C, and that was used for some pretty large projects. I really don't think Ritchie was thinking about the classroom when he designed C.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  19. Machine Beauty. by TechyImmigrant · · Score: 4, Interesting

    In 1998 David Gelernter wrote a book that effectively argues that elegance and beauty in engineering are essential features that lead to benefits beyond the merely aesthetic.

    He is still right.

    The 'elegant' and 'concrete' example in TFA is ugly and hard to follow, even with plenty of understanding of lambda expressions and languages that offer them. I have other, better high level language options and other, better low level language options. C++ fails the test. C++ is not for me.

    --
    I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    1. Re:Machine Beauty. by Anonymous Coward · · Score: 0

      Just sounds like you have problems that don't force you to stare at an ugly piece of code that you can barely read yet is required to get the job done.....

      Wish I had that luxury use expressive easy to read code to achieve my low level coding.....

      But that's why I'm on Wallstreet....

    2. Re:Machine Beauty. by Anonymous Coward · · Score: 0

      The problem is that too many people attempt to write clever code instead of elegant code. In fact, they mistake clever code for elegant code.

      Elegant code is clear, f*cking obvious when you read it, and self-documenting. Clever code is one line that magically makes something work and takes you a minute to see why it does it. It may be clever, but will ruin your project.

    3. Re:Machine Beauty. by TechyImmigrant · · Score: 1

      I design circuits you insensitive clod!

      --
      I should use this sig to advertise my book ISBN-13 : 978-1501515132.
  20. Re:Ugh by don.g · · Score: 0

    Yeah, great idea, let's take a language whose roots are in the 1970s and break backwards compatibility to increase its appeal to young people with six digit slashdot IDs.

    If C++ looks bloated to you, (a) define bloat and (b) name some languages you have used, that you consider not-bloated. Good answers are available to both questions; I want you know yours.

    --
    Pretend that something especially witty is here. Thanks.
  21. PHP welcomes you! by Anonymous Coward · · Score: 0

    All C++ developers shunned for writing in a language considered to be crappy and producing crappy programmers making crappy programs, feel free to drop by and spend some time with us PHP devs, we'll share tips on how to not feel so bad about all the mockery and abuse.

    1. Re:PHP welcomes you! by Anonymous Coward · · Score: 0

      Oh, people hurl insults at C++ programmers, but nobody shuns us because deep down they know we're better than them. C++ is rivalled only by Lisp in its support for condescension-oriented programming.

  22. Yes by tylersoze · · Score: 1

    Yes

  23. the advantage to C++ by woodworx · · Score: 1

    My professor at HPU once told us the advantage of the C Language was that it was loosely typed. and the biggest problem with C was that it was loosely typed. fun stuff... C++ just built on that... and from prior comments, I'd say there are as many lovers as haters of C++... but, I'm not a coder, just a lowly sys admin and my preferences really don't matter. (I learned top down programming in PASCAL... so...)

    1. Re: the advantage to C++ by Anonymous Coward · · Score: 0

      Talking about overengineering : the scala standard library...

  24. Over at Dice by Anonymous Coward · · Score: 0

    "Over at Dice"

    Excuse me, Dice owns Slashdot.

    Mandatory disclosure, please.

  25. Re:Ugh by RailGunner · · Score: 1

    Dude, the original poster who claimed that C++ is bloated probably loves him some Java or C#, both of which are arguably even more bloated that C++ is, since the "bloat" of C++ is the STL and Boost... which is comparably smaller than .NET, Swing, JavaFX, etc.

  26. so what language does Linus prefer? by Anonymous Coward · · Score: 0

    I agree that C++ sucks and all my coworkers who can't code worth a shit use it, but I wonder what he recommends

    1. Re:so what language does Linus prefer? by Anonymous Coward · · Score: 0

      He recommends plain old C. Because most programmers are able to learn the full language.
      Bjarne Stroustrup in a talk said that he doesn't even understand the finer details of template programming that the c++ library guys are doing now.

    2. Re:so what language does Linus prefer? by Newander · · Score: 1

      C. That's what the kernel is written in.

      --

      Jesus saves and takes half damage.

    3. Re:so what language does Linus prefer? by Anonymous Coward · · Score: 0

      Ugly C. Be specific.
      I haven't seen a worse coding style guid then the kernel style guide. It's actively hostile to good coding practices.

    4. Re:so what language does Linus prefer? by gatkinso · · Score: 1

      Which kernel would that be?

      --
      I am very small, utmostly microscopic.
  27. Re: Ugh by SLi · · Score: 1

    Modules are coming in C++1z (the next revision of the language) most likely. That should solve many of the (real) problems with #includes.

  28. If you write programs that you don't understand by Anonymous Coward · · Score: 0

    then you're going to write bad code in any language.

  29. What is C++ by Anonymous Coward · · Score: 0

    I've used many languages including C, C++, Java, Pascal so let me express that a language and the libraries that come with a language are so closely tied together in most programers minds that they don't actually know what is the language and what isn't. *grumble* Java project with three different XML parsers in it *grumble* My biggest problem with C++ is people don't use it right. Like in C people write allocators rather than use "new". Really? If you think you are smarter than the guys doing the language lib and compiler then go write your own language. They use STL until their code looks like the aftermath of a Blendtec video. And they have dozens of classes inside a single .cpp because #ifndef #include #define #endif is a horrible mess. So yes Linus is correct even today, bad programers use C++ and make a mess. Linus is wrong however that this is somehow limited to C++. What Linus should be saying is language designers trying to do elegant, need to know not to cross the line and throw in the every last buzzword. Generics are nice, functional programing can rarely be useful, ability to redefine operators probably goes too far, if you feel the need for more than a single String type then you are almost certainly wrong, pick one of: new/free, reference counted or garbage collected.

  30. linus was right by MagicMerlin · · Score: 2, Interesting

    Linus was right (I didn't agree with him when he wrote that but I do now). Jeff doesn't answer any of the major issues with c++: Lack of standard ABI (preventing interop with other languages), insanely complex grammar, years of paradigm shift, action at a difference, lack of abstraction away from computers, etc. Java/C# have completely displaced it in the business world and C still dominates system programming. C++ would be already obsolete except that it caught a big with the gaming industry...real-time games can't tolerate GC languages and C is considered too baroque to many developers.

    1. Re:linus was right by Anonymous Coward · · Score: 0

      There's more industries than that.

      We've got ~300 C/C++ developers across the planet (one of the top 20 companies on the planet) working on automotive, medical, and aviation electronics systems - primarily using C++ (not C).

      Most games companies don't have 300 staff, let alone 300 developers.

      The world is bigger than you realise, stop touting biased crap about what you think the world is, when you don't even know how large it is.

    2. Re:linus was right by Anonymous Coward · · Score: 0

      Jeff doesn't answer any of the major issues with c++: Lack of standard ABI (preventing interop with other languages),

      The python interpreter on Windows fails to load my cextension.so, clearly C also fails this. Hint there are comparable standard ABIs for C++, just MSVC does not use one, GCC uses an Intel specified ABI (afaik).

      real-time games can't tolerate GC languages

      its not only the GC, have you seen the amount of forced pointer indirection in Java and C#? cache locality is their enemy number one.

      C is considered too baroque to many developers.

      Including every major compiler developer, several OS developers, browser developers, c++ does not seem obsolete at all.

    3. Re:linus was right by Anonymous Coward · · Score: 0

      It has caught big time in all the industries...

        First user of C++ in the world ? in terms of Lines of Code : Google. C++ is also the system's Language for Windows, and basically a lot of what MS produces. Same goes Apple, even thought they'd like you to think they use Objective-C (haha not funny Apple..)

        All the banks in the world use it to write trading-apps for instance, and most of the backend of ALL their apps.

        Really ANY realtime system that needs a good abstraction layer is written in C++ basically.. Which is crazy when you think that that is what it was design to do : paraphrasing Bjarne, C++ is a 0-overheard abstraction building language

        All the complex, non-embedded real-time apps in Industry, Energy, etc.. and a lot of the embedded as well, because C is just too dangerous. It is impossible to write Type-safe code. It is almost impossible to make C usable for safety critical mission without DRASTICALLY reducing the feature set. It is also the case in C++, but 10% of C++ features >> 20% of C.

        In other words MISRA C SF++ (or even indeed MICRA C++) in terms of what I can do, and FOR THE SAME SAFETY GARANTEES.

    4. Re:linus was right by serviscope_minor · · Score: 1

      Lack of standard ABI (preventing interop with other languages),

      Because that hobbled every other language out there? No, wait, it didn't. Most languages have no standard at all, just one "reference implementation" and if you're lucky a bunch of others, too.

      C is about the only one with a standard ABI. A few things like Java specify interop via the C ABI, but guess what C++ does too.

      Except the C ABI isn't a single standard either, so I guess all languages fail.

      C++ would be already obsolete except that it caught a big with the gaming industry...real-time games can't tolerate GC languages and C is considered too baroque to many developers.

      Oh and web browsers too (all major ones written in C++), compilers (all major ones written in C++), HPC codes (steadily moving from FORTRAN to C++) and so on.

      --
      SJW n. One who posts facts.
  31. I only know of Dice from coming here... by seepho · · Score: 1

    And from what I've seen they specialize in beating dead horses for clicks.

  32. True across the board. by Frobnicator · · Score: 3, Insightful

    Linus is doing systems level work. At systems level work, there are a lot of mediocre and bad programmers who use the common language of C++. Those who know c well are unlikely to be the mediocre and bad programmers.

    That is really a truism across all fields and languages.

    In the business world with business logic, there are a lot of mediocre and bad programmers who use the common language of Java. You can filter out many of them by adding a skill requirement of some other less-used languages inside that realm of business software development.

    In a field where everyone is doing Ruby development and you don't want mediocre/bad Ruby programmers? Require them to also demonstrate proficiency in another language.

    In a field where everyone is using C#? Require them to also demonstrate proficiency in C++ or some other language.

    If you only require a single thing you can get unskilled individuals with only a single skill. If you require multiple skills you are more likely to get more talented individuals, since the talented, higher producers tend to pick up a wide range of skills.

    --
    //TODO: Think of witty sig statement
    1. Re:True across the board. by Anonymous Coward · · Score: 0

      smartest comment I've read in this whole thread.... nailed it... on... the... head.

    2. Re:True across the board. by TheRaven64 · · Score: 1

      Those who know c well are unlikely to be the mediocre and bad programmers.

      Clearly you have never visited GitHub.

      --
      I am TheRaven on Soylent News
  33. Mod parent up by amaurea · · Score: 5, Informative

    I just looked through Nerval's Lobster's last 15 contributions. All were article submissions, Nerval's Lobster doesn't appear to comment on anything. Here's the list:

    • Was Linus Torvalds Right About C++ Being So Wrong? [Dice]
    • Do Tech Companies Ask For Way Too Much From Job Candidates? [Dice] [Hiring]
    • 'Chappie': What It Takes to Render a Robot [Dice]
    • Demand for Linux Skills Rising This Year [Dice] [Hiring]
    • Who's Afraid of Android Fragmentation? [Dice]
    • H-1B Visas Proving Lucrative for Engineers, Dev Leads [Dice*] [Hiring]
    • In Space, a Laptop Doubles As a VR Headset [Dice*]
    • What Does It Mean to Be a Data Scientist? [Dice]
    • Which Freelance Developer Sites Are Worth Your Time? [Dice*] [Hiring]
    • JavaScript, PHP Top Most Popular Languages, With Apple's Swift Rising Fast [Dice*]
    • Building a Good Engineering Team In a Competitive Market [Dice*] [Hiring]
    • What Makes a Great Software Developer? [Dice*] [Hiring]
    • The Highest-Paying States for Technology Professionals [Dice] [Hiring]
    • What Will Google Glass 2.0 Need to Actually Succeed? [Dice*]

    Every single one of them is from dice, though only a few of them actually make that explicit (the non-explicit ones are marked [Dice*]. A large fraction of them are related to human resources and hiring people, which I've marked [Hiring]. So its like Nerval's Lobster is using Slashdot as advertising and recruitment channel for Dice.

    The average quality of these submissions was very low in my opinion - lots of vacuous pointy-haired-boss buzzword stuff. Very un-nerdy. How did these get through submission moderation? Were they even subjected to it?

    1. Re:Mod parent up by Anonymous Coward · · Score: 1

      If you were around long enough, you'd already know he's Nick Kolakowski, a known astroturfing employee.

    2. Re:Mod parent up by Kjella · · Score: 1

      On the bright side, this does make me feel better about not RTFA...

      --
      Live today, because you never know what tomorrow brings
    3. Re:Mod parent up by Mr.+Shotgun · · Score: 1

      How did these get through submission moderation? Were they even subjected to it?

      Dice owns slashdot so I am pretty sure they got fast tracked to the front page.

      --
      Of all tyrannies, a tyranny sincerely exercised for the (supposed) good of its victims may be the most oppressive
    4. Re:Mod parent up by captnjohnny1618 · · Score: 1

      It's definitely clear that there's some preferential dice treatment happening, which is kinda messed up, but I for one really enjoy reading the comments on posts like this one. As a C programmer (for science, not mainstream code) I always learn a ton about security and good practices from the other slashdotters. :-)

    5. Re:Mod parent up by Anonymous Coward · · Score: 1

      Well, when an article starts with "someone said something eight years ago", can we really expect anything decent inside?

      Dice is trying to monetize on slashdot. This is how these things pass through submission moderation. And I guess we're the suckers for still being around.

    6. Re:Mod parent up by phorm · · Score: 1

      "How did these get through submission moderation?"

      I'm fairly sure the "is for parent company article" filter passed those onward.

  34. This is dumb. articles like this force me away /. by Anonymous Coward · · Score: 0

    Linus makes the argument for SYSTEMS level code. Jeff even agrees in his article about systems level code. Why is it that every time linus opens his mouth everyone blows it way out of proportion. he is a systems level guy, someone who likes hacking away at that layer of code that most software developers are remotely aware that exists. So of course he is going to prefer a language, that allows him to write elegant code while minimalising foreign dependices and useless api calls that usually dont work like the doccumentation states.

    Who ever this Jeff guy is, go find something useful to do.... like CODE, rather than create a crevat from someone elses argument for the sake of proving a point (which you failed horribly at by failing to understand the standing point of the original author) and no you are not smarter than linus was in 2007, you are just an annoying journalist using a community new site to promote your self through company affiliations..

    Listen people from DICE, this is the stuff we hate. Its blatantly obvious and insults the intelegence of most people here because we know that this is corporate drivel and not a community submitted news story. maybe we could change the colour of all dice sponsored stories to a red banner as opposed to the normal /. green?

  35. ABOMINATION I SAY! by Anonymous Coward · · Score: 1

    "C++ is like those freakish experiments that only take place at the infancy of a new science. C++ is to computer science as Frankenstein's monster was to the field of anatomy. A monstrous abomination that surprisingly draws some love from a minority of strange people that swear they understand it." - Paymon Yamini Sharif

  36. C++ is hard by Prien715 · · Score: 4, Informative

    C++ was the first popular fast OO language. As such, there's a lot of confusing cruft left behind. Consider overloading the && operator or || operators. You should never do this*. But someone will come along and do it anyway. You can't get rid of the feature because of backwards compatibility and yet it's miserable. We can go down the list from polymorphic arrays to calling virtual functions during constructors. All things one should never do, but the language keeps them there for the sake of backwards compatibility.

    Languages like Java fix some of these problems by explicitly not allowing operator overloading (which is heavy-handed) but enforces some readability.

    As others have said, using good 3rd party libraries like Qt makes the language tolerable, but in the legacy applications I've supported, there's no shortage of programming faux pas made possible by the language (like assumptions about the order of static variable destructors -- which is compiler dependent). As a programmer, it can be fun and productive since simply using the better parts of the language can make programs easy to write and read. As a maintainer, it's a smorgasbord of bad programming practices which the language makes no attempt to prevent.

    That said, Linus really likes the new version of Subsurface based on Qt. So there;)

    * Scott Meyers More Effective C++ p.35

    --
    -- Political fascism requires a Fuhrer.
    1. Re:C++ is hard by spitzak · · Score: 1

      assumptions about the order of static variable destructors

      Yes this is a huge problem. Almost all of our code has static objects defined something like this:

          static Foo& theStaticFoo = new Foo(2);

      This is so the destructor is not run when the program exits, since it will usually crash because Foo relies on some other object that has already been destroyed.

      An annoyance of this is that a non-optimizing compiler will do an extra level of indirection, and call malloc at startup.

      It would be nice if C++ added some kind of syntax to make a static object that does not call the destructor without making construction or use less efficient. Possibly somehow sticking the much-overused "const" keyword in there somewhere?

    2. Re:C++ is hard by Pseudonym · · Score: 1

      But someone will come along and do it anyway.

      No they won't. Oh, they might try, but that code will never pass review. (Admittedly, it might end up in some crappy open source project that nobody will use...)

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    3. Re:C++ is hard by Anonymous Coward · · Score: 0

      >C++ was the first popular fast OO language. As such, there's a lot of confusing cruft left behind. Consider overloading the && operator or || operators.

      The only safe way to use C++ is not to use all of it. Advanced operator overloads, many advanced template features, the old std string libraries, etc. They all lead to problems managing and debugging the code. And in all cases you don't need them (ie. C is a proper subset).

    4. Re:C++ is hard by Anonymous Coward · · Score: 0

      You should never drive your car into a department store.. but people can still do it. Does that make cars something horrible and we should all go back to horses that could just refuse to obey our command?

      A hammer can kill a person, so we should not use hammers when building a table?

      Almsot all medicine can kill a person if you use it wrong... so ban all medicine?

      Linux is just a backwards blind guy that refuses to evolve because of his gigantic ego..

    5. Re:C++ is hard by Prien715 · · Score: 1

      You're a lucky person.

      While everywhere I've worked has code reviews, there's no "retroactive reviews" for code written in the 90's which is truly horrid and fragile. I think we're also both lucky to have someone on our teams who is a language expert at C++ rather than a Java guy who dabbles -- but I've seen shitty code get into a workplace that way too.

      Though the most depressing thing for me is doing a blame on good and bad code to find the author of the well-written code left the company and the terrible coder is in management.

      --
      -- Political fascism requires a Fuhrer.
    6. Re:C++ is hard by shutdown+-p+now · · Score: 1

      You can make your own smart pointer like wrapper that embeds aligned_storage, and uses placement new to initialize it (but doesn't invoke its destructor at any time).

      Another way to handle this is to force the ordering of static variable initialization (since destructors are guaranteed to run in reverse of that) by making them function locals, and calling that function whenever you need to access the variable. This way, a variable is only initialized when whoever needs it first accesses it, so the init order reflects the actual dependency graph. If that graph is a tree (as it normally should be), then you'll have clean init and shutdown with no broken dependencies.

    7. Re:C++ is hard by spitzak · · Score: 1

      I think you are right that placement_new could be used to get a block of memory filled with the object without using malloc and without double-indirection when using it. It looks like every method on that static object has to be copied to the dummy object, so I'm not sure if that is a good selling point for C++.

      What I was thinking of was some keyword added to the static that causes no change in any code except the destructor is not called. An idea I had was to use '&' without constructor args after it:

            static Foo&; // uses default constructor
            static Foo&(1,2,3); // uses some other constructor

      However I am rather worried that this may collide with some existing syntax.

      I never heard of a guarantee that statics are destroyed in the opposite order of creation. In fact this seems to be completely false in cases where a function containing a static variable is first run in a parallel thread. Wrapping statics in functions is useful to guarantee construction order, and I do it all the time, but never used it to control destruction order.

      Even if destruction order could be controlled, it does not fix the real problem where the static object obtains a pointer to an object that was constructed later, generally for caching. An example is an OpenGL resource, you want your destructor to release the resource but that will crash if the OpenGL context has been destroyed. Adding an if statement to the destructor that is only true when your program is exiting is pretty distasteful.

    8. Re:C++ is hard by shutdown+-p+now · · Score: 1

      It looks like every method on that static object has to be copied to the dummy object

      Nope, you'd just override operator->, like any other smart pointer class.

      I never heard of a guarantee that statics are destroyed in the opposite order of creation.

      It has guaranteed by the Standard since the very beginning. In C++14, this is in 3.6.3[basic.start.term]/1: "If the completion of the constructor or dynamic initialization of an object with static storage duration is sequenced before that of another, the completion of the destructor of the second is sequenced
      before the initiation of the destructor of the first. If an object is initialized statically, the object is destroyed in the same order as if the object was dynamically initialized."

      In fact this seems to be completely false in cases where a function containing a static variable is first run in a parallel thread.

      Why would threads make things any different? Threads or no threads, if you have a relative ordering between constructors of A and B, then you can expect the same ordering to hold between their destructors. What isn't guaranteed is that all static objects are ordered relative to each other - i.e. if you pick any two random statics, then they may not be well ordered (and the Standard even explicitly allows the implementation to run destructors concurrently in such cases). But when you use the static function wrapping trick, you essentially force such an ordering, and thereby guarantee destruction order, too.

      It used to be broken in practice because it didn't account for threads, but since C++11 local statics are required to be thread-safe to initialize. VC++ ignored that for a while, but they have finally given up in VS 2013, I think?

      Even if destruction order could be controlled, it does not fix the real problem where the static object obtains a pointer to an object that was constructed later, generally for caching. An example is an OpenGL resource, you want your destructor to release the resource but that will crash if the OpenGL context has been destroyed. Adding an if statement to the destructor that is only true when your program is exiting is pretty distasteful.

      I think it depends on the nature of that if statement. If it's specifically checking for the "I'm exiting" flag, then yeah, that's a hack. But if it's checking the "am I valid?" flag on the GL context (or if it doesn't have one, on a smart pointer like wrapper around it), that's okay. It also allows you to do things like shut down the context and recreate it if need be.

  37. Syntax and typo errors compile by goombah99 · · Score: 5, Informative

    C itself has so many pitfalls. For the best tour review the underhanded C contest. "features" like automatic concatenation of consecutive character strings means that if you leave out a comma in a list, the adjacent array element entries are concatenated rather than throwing a syntax error. That list will now not match the declared array size (one short, so there's a null or random pointer in the last element) but the compiler allows initialization listed mismatched to the array sizes. Character strings have to be declared one longer than the initialization string length (room for the unstated \0) but are accepted by the compiler if they don't giving an unbounded string length.

    it's mind boggling to realize that
    int (*int)[20];
    int *int[20];
    are different things.

    the number of different ways an array argument in a function can be written makes code hard to grasp: is it a pointer, an array, a reference? many work alike but then fail in different ways.

    The most common of all pitfalls and hard to read codes are the in-line initializations that pop up in function arguments and what not. this leads to classic blunder of writing = when you mean ==.

    Perhaps the most insane thing is that If you declare an external function with the wrong prototype then any mismatch in the argument count leaves or takes something off the stack. Holy cow..... I mean what the hell? Why would any language ever ever ever let you leave a orphan argument on the stack, or worse pop one off that was not yours? This is very useful for the underhanded C folks however.

    While I know there's little love for fortran, it's worth noting that none of those things is even possible in Fortran, so its an existence proof that there's not any necessity for those to exist and that it doesn't limit the power of the language to remove them. It's very fair to say that no simple typo will ever compile in fortran (yes very complicated offsetting typos can compile).

    --
    Some drink at the fountain of knowledge. Others just gargle.
    1. Re:Syntax and typo errors compile by goombah99 · · Score: 2

      gahh. I just typoed my example!!! oops.
      int (*foo)[20];
      int *foo[20];

      But I bet that error would even compile!

      --
      Some drink at the fountain of knowledge. Others just gargle.
    2. Re:Syntax and typo errors compile by tibit · · Score: 1

      It's not mind boggling if you understand the syntax of C. It so happens that many people program in C for years without having a solid understanding of what it is that they are doing. I'd almost say that if you consider yourself "the best" in C, you should be able to come up with a mostly standards-compliant parser for it in a couple of days, doing it mostly from memory, and certainly writing up a parser for a subpart of the language, like type expressions, should take a couple hours at most. Otherwise I'd find it a hard sell to consider someone a top-notch C person. Good - perhaps, but not top-notch.

      --
      A successful API design takes a mixture of software design and pedagogy.
    3. Re:Syntax and typo errors compile by slew · · Score: 2

      gahh. I just typoed my example!!! oops.
      int (*foo)[20];
      int *foo[20];

      But I bet that error would even compile!

      yeah but in principle that's not much different than

      t = x+y*z; different than
      t = (x+y)*z;

      Except that people mostly remember algebra precedence. Sure 'c' precedence rules and postfix syntax has its warts (consider the typedef function), but your example isn't one of them...

      For me the truly annoying things about C vs Fortran, is that C basically allowed to ignore your parenthesis from a equi-precedence, computational point of view where (x+y)+z != x+(y+z); Also, its definition of sequencing is kind of broken too (e.g., x = x++; is basically undefined as the evaluation order of x = f() + g()), but usually, you can find ways to code around these problem, but they are kind of ugly.

    4. Re:Syntax and typo errors compile by twistedcubic · · Score: 1

      But C has a small number of precisely-defined constructs like this, which are easily explained in a few pages of K&R. And they usually make sense and are consistent with all the other constructs. Understanding inheritance gotchas in C++ is way more difficult.

    5. Re:Syntax and typo errors compile by goombah99 · · Score: 1

      For me, the example I gave is an example that comes up when you read some one elses dialect of C-coding. I take great pains never to use one of those forms. I'll split it over two lines of type definition and array declaration if I need to. Running array declaration and two diffierent type declarations on a single line is confusing to anyone who has a different c- dialect. This also comes up when your just a little sleepy. A missed parens can mean hours of run time debugging.

      My larger issue however was the title of my post. It's not that these things can't be read correctly, it's that typos that convert one into the other both compile.

      this is where the inexpert C-programmer ends up writing crap code. It's not the experts I worry about. the subject of this is why Crap code proliferates. C is just a great way to do that.

      --
      Some drink at the fountain of knowledge. Others just gargle.
    6. Re:Syntax and typo errors compile by goombah99 · · Score: 1

      Sure but why the hell allow look alike syntaxes and allow simple typos to compile? Most other languages have avoided that so it's quite peculiar to C.

      --
      Some drink at the fountain of knowledge. Others just gargle.
    7. Re:Syntax and typo errors compile by wed128 · · Score: 1

      C is older then many other languages.

    8. Re:Syntax and typo errors compile by TapeCutter · · Score: 2

      (x+y)+z != x+(y+z); - correctly evaluates to false in C, the parentheses can safely be ignored because they are redundant and make no difference to the outcome.
      x = x++; is basically undefined - How so? The code increments x, the "x=" part is harmless, again you are using redundant code that any halfway competent C programmer would not write in the first place.
      I've been making a good living from C/C++ for 25yrs, I don't see your "problems", and I can't imagine the "workarounds" to be anything other than removing the redundant syntax.

      As for TFA - It's unsurprising that Linus rants about C++, sure he's a very smart guy, but he's also an arrogant and highly emotional attention whore who wants things done his way or not at all. When he can't support his opinion with a logical argument, he invariably resorts to personal insults. Actually he often resorts to personal insults even when he can support his opinion.

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
    9. Re:Syntax and typo errors compile by Anonymous Coward · · Score: 0

      Wow! So much wrong with your info. C++ performs constant string concatenation, too.
      Matter of fact, everything in your 1st paragraph applies to C++ as well.

      And the "external function" example has nothing to do with C; that's a function of the program ld,
      and C++ uses ld to build its executable as well.

      Also, see the Stroustrup interview -- a real eye-opener!

    10. Re:Syntax and typo errors compile by Anonymous Coward · · Score: 0

      mind boggling ?

    11. Re:Syntax and typo errors compile by luis_a_espinal · · Score: 1

      gahh. I just typoed my example!!! oops. int (*foo)[20]; int *foo[20];

      But I bet that error would even compile!

      Not mind boggling. A person that works in C *must* know the syntax and how that stuff gets parsed.

      First a pointer to an array of 20 ints (the parenthesis binds the '*' to the variable, making it a pointer). Second, an array of 20 pointers to int (the [20] binds to the variable, making it an array of 20 something, that something being determined by int * (pointer to int).

      Yes, the parsing is idiotic (go right till no more, then left till no more and non-sense like that), but the rules have existed forever. And to me, that is a prerequisite to work in C... and when in doubt, use cdecl.

    12. Re:Syntax and typo errors compile by TapeCutter · · Score: 1

      Understanding pointers is key to unlocking the power in C. There's nothing mind boggling about your buggy example, what you are trying to demonstrate is not a flaw, it's actually a very powerful feature. Having said that, I do agree that most people have trouble grasping the concept of pointers, I used to teach C to 2nd year engineering students, only about one in 10 students "got it" on the first try. If you want a better handle on pointers (bad pun intended), I highly recommend K&R's classic text "The C programming language".

      I also agree with TFA that STL and Boost are over engineered libraries that overwhelm even an experienced C++ programmer with indecipherable typedefs within typedefs, proving yet again, that just because it can be done doesn't mean it should be.

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
    13. Re:Syntax and typo errors compile by TapeCutter · · Score: 1

      Aside from effort and portability, it doesn't really matter what language(s) or framework(s) you use to get the job done. A basic understanding of the algorithms and concepts that have emerged from computer science and logistics over the last ~80yrs is the secret to being a "good" programmer, consistently knowing where, when, and how to apply them is the secret to being a "top-notch" programmer.

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
    14. Re: Syntax and typo errors compile by Anonymous Coward · · Score: 0

      Perhaps the most insane thing is that If you declare an external function with the wrong prototype then any mismatch in the argument count leaves or takes something off the stack. Holy cow..... I mean what the hell? Why would any language ever ever ever let you leave a orphan argument on the stack, or worse pop one off that was not yours?

      While this behaviour is certainly not desirable, the issue is that the compiler builds each file without knowledge of the other files in the system. It literally generates the assembler for the module relying on the extern declarations to generate the call behaviour for a function it knows nothing more about. Later the linker connects these calls up but it does not inspect the code to check parameter passing. There is no neat way for the compiler to really change this behaviour. In practice you almost always self include a module's header file and the compiler can pick up the discrepancy at this point before it propagates into other modules.

    15. Re: Syntax and typo errors compile by Anonymous Coward · · Score: 0

      If there's not a way to do it then how is that other languages manage to do it?

    16. Re:Syntax and typo errors compile by BitZtream · · Score: 1, Insightful

      So basically, you don't understand C, so its bad? Is that what you're saying? I'm asking because none of your examples are even mildly difficult concepts.

      You seem to have difficulty accepting the syntax for function pointers for one obvious one.

      You also don't seem to understand that a pointer and a reference are the same thing, and the array thing your referring to, is also your misunderstanding, its also passing a pointer ... because you don't pass an array ON THE STACK, you pass a reference/pointer to the array.

      Your comment about argument mismatches being a problem is easy to solve, don't use a retarded compiler, done. Now the compiler doesn't let you fuck it up. If you make a Java, C++, pascal, or .NET compiler retarded and let it ignore obviously bad code, it'll fuck up too.

      Everything in your post is just shear ignorance of the language and its syntax. You didn't even post anything about the actual difficult parts of C. You just made yourself look ... simple and uneducated, not C look bad.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    17. Re:Syntax and typo errors compile by Dozy+Lizard · · Score: 1

      Its been a while, but in the Fortran I recall, mismatching number (and type) of function/subroutine arguments was a fruitful source of errors.

    18. Re:Syntax and typo errors compile by Anonymous Coward · · Score: 0

      Most of the things you're talking about don't compile with modern C compilers if you turn on all the warnings.

      Use -Wall -Wextra -Werror, you'll be thankful. Just about any warning should be considered a bug. (You can use a #pragma diagnostic to disable some particular warning that's actually legit.)

    19. Re:Syntax and typo errors compile by jeremyp · · Score: 1

      (x+y)+z != x+(y+z); - correctly evaluates to false in C, the parentheses can safely be ignored because they are redundant and make no difference to the outcome.

      I think the parent was assuming that x, y, z could be function calls with side effects.

      x = x++; is basically undefined - How so?

      x is modified twice in the expression without a sequence point. There are two ways code could be generated:

      Set a temp variable to the value of x
      Increment x
      Assign the temp variable to x

      or

      Assign x to x
      Increment x.

      Both are legal. Actually, since the behaviour is formally "undefined behaviour", the compiler is free to generate code to do anything or nothing.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    20. Re:Syntax and typo errors compile by Anonymous Coward · · Score: 0

      Your ignorance is staggering. you must have limited experience.

    21. Re:Syntax and typo errors compile by goombah99 · · Score: 1

      Fortran Compilers I have worked with caught these at compile time not run time. C compilers, at least some of them miss this. In C including the headers.h files is what is supposed to catch this, but if you declare the header wrong, or don't use a header but instead use extern then this doesn't get caught.

      --
      Some drink at the fountain of knowledge. Others just gargle.
    22. Re:Syntax and typo errors compile by david_thornley · · Score: 1

      "x = x++" is undefined, and therefore can do anything (including what you expect) without violating the Standard. The reason is that it attempts to change the value of x twice without an intervening sequence point. There's two actions going on here; the assignment to x and the incrementing of x, and that makes the statement undefined.

      C (and C++) do have order of evaluation in expressions largely unspecified, so I'd suggest "x = f(); x += g();" if you want to control the order. Usually it doesn't matter.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    23. Re: Syntax and typo errors compile by Anonymous Coward · · Score: 0

      to be fair, most of those rants are directed at people who make mistakes they should not be making because they know better.

      it looks like you are falling into the same trap. you criticize a man for criticizing a man. good job.

    24. Re:Syntax and typo errors compile by friesofdoom · · Score: 1

      You also don't seem to understand that a pointer and a reference are the same thing

      THIS!
      Why do they still keep teaching us in CS that pointers and references are different things? Look at the compiled output, looks like the same thing to me.

    25. Re:Syntax and typo errors compile by shutdown+-p+now · · Score: 2

      C type declarator syntax is insane. I don't know any other language that prompted a creation of a separate utility for the sole purpose of deciphering its types.

      Array-to-pointer decay is also badly designed. Why exactly shouldn't I be able to pass arrays by value? Pascal lets you do that, for example. If I really want to pass it as a pointer, I'd just declare the argument as a pointer, and the language even has syntax for that. And this is especially damning when the language lets you write something like void foo(int a[42]) - i.e. using the array syntax - but then silently replaces it with int* a, and completely ignores the bound. That's bad bad. Throw in C99's static for array boundaries (which is still pass-by-ref, and still triggers decay, but requires the array bound to be respected or UB happens), and it gets into the hilariously bad territory.

      Granted, C++ has all of that, too. But then it also has std::array, which behaves in a sane way (no pointer decay, can pass by value, can easily query length etc).

    26. Re:Syntax and typo errors compile by trumpetplayer · · Score: 1

      Plain operator precedence is mind boggling? I mean, you may find the chosen preference intuitive or counterintuitive, but that's about it.

  38. What's he afraid of? by Marginal+Coward · · Score: 2

    "It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it."

    That seems like a strange statement coming from someone who is one of the best programmer's on the planet - and who works closely with some of the others.

    I don't disagree that C++ provides a lot of rope for substandard programmers to hang themselves with (and I've seen that done by someone who created layer upon layer of useless classes), but I assume Linus Torvalds doesn't hang out with too many "substandard programmers." So what's he afraid of?

    Although C++ may not be for everybody, and it's far from ideal, I think it's generally a pretty good solution for the problems it's trying to solve. And it's not just me: it's notable that it dominates its niche as the primary C-inspired, object-oriented, compiled language.

    1. Re:What's he afraid of? by Anonymous Coward · · Score: 0

      The statement isn't strange, by keeping C++ out of the kernel he keeps these substandard programmers out and keeps the bad code he actually has to deal with (from bad C programmers) in a language that he understands well .

    2. Re:What's he afraid of? by serviscope_minor · · Score: 1

      It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it."

      I mean, the sensible thing to do would have been to write his version control system so that it didn't have global write access from anyone at all. That way he would have been able to choose a better language (such as C++), and use permissions to stop bad people from committing code, rather than choosing a bad language and simply relying on obscurity to stop bad people from committing code.

      I wonder why he made that choice.

      --
      SJW n. One who posts facts.
    3. Re:What's he afraid of? by Bent+Spoke · · Score: 1

      It's a matter of scale. C provides 10 feet of rope. C++ provides 10 miles of rope.

  39. "FORTRAN in any language" by Todd+Knarr · · Score: 3, Interesting

    The major problem with C++ is that it's popularity means there's more crap code written in it by bad programmers than any other language. But, to borrow from a quote, a bad programmer can write bad C++ in any language. I've had plenty of experience with bad programmers and bad code, and the problems rarely stemmed from the language used. They usually stem from the programmer not understanding the language or the environment and from an all-too-common mule-headed desire to design their part of the software the way they want it to work rather than in a way that fits with the rest of the software. Languages where this isn't a problem are typically new enough that there's only been one "right way" to do things taught. C++ is old enough that there's a variety of approaches built up over time, leading to the problem.

    As for C++ being so popular, that's because well-written C++ can beat most other languages in performance. I've learned one thing over the decades: good engineering in software is a great priority as a developer, but from the business side it's irrelevant. Business cares that it gets the correct results and it runs fast enough. It could be the worst Rube-Goldbergesque contraption under the hood, but as long as it gave the right results and performed like a Formula 1 car they'd be ecstatic. C++ makes it easy to achieve that in the complex software common in commercial environments.

    1. Re:"FORTRAN in any language" by Anonymous Coward · · Score: 0

      And business frequently only cares about short-term gain. Over the long haul building huge Goldberg machines tends to limit staffing choices. You need better staff to work on bigger and more complex systems. Eventually if things get too bad then staff turnover becomes a problem and you realize that all the original engineers have left; the so called 'brain-drain'.

      Businesses that have really built the most insane structures tend to disappear quickly, and usually in a puff of smoke without much fanfare. I've seen orgs with critical functions essentially unstaffed on paper because everyone is on deck trying to keep everything held together for just another 15 minutes. The new thing seems to be for businesses to create their own programming languages (e.g. Swift for Apple, Go for Google). I'm not entirely sure this is helping the software industry at all, but it's creating a lot of brogrammers that only speak Klingon. Everything is still on fire but it's just burning a different color.

      FWIW I agree with Linus. C++ is a hell of a language if it's used incorrectly. C is a scalpel, C++ is a jackhammer. Don't get me wrong, you can build great things with a jackhammer, but you can also tear things up, knock down buildings and wake up the neighbors. It also hurts like a bitch when it goes through your own foot.

    2. Re:"FORTRAN in any language" by sunderland56 · · Score: 1

      The major problem with C++ is that it's popularity means there's more crap code written in it

      I think Linus' point was: C++ makes it extraordinarily easy to write crap code. Even otherwise intelligent people, who can produce solid functional code in other languages, produce unmaintainable garbage in C++. And, when they do, it's so much harder to clean up afterwards.

      As for C++ being so popular, that's because well-written C++ can beat most other languages in performance.

      Not C.

    3. Re:"FORTRAN in any language" by Anonymous Coward · · Score: 0

      Perhaps the most famous rant against C++ came from none other than Linus Torvalds in 2007

      Those who don't understand C++ are doomed to rant about it.
      (with apologies to George Santayana)

      The major problem with C++ is that it's popularity means there's more crap code written in it by bad programmers than any other language.

      You seem to be living in a world where Visual Basic and PHP don't exist...

      captcha: certify

  40. Re:Ugh by Pieroxy · · Score: 1

    .NET and Swing don't change the language, they add APIs. STL and Boost ... Well, let's not even get started. In C++ you can write your entire program with the C99 preprocessor, there is not even any need to write C++ to do things. The preprocessor itself is turing complete. Talk about over engineering.

  41. Aren't all (but one) popular languages like this? by Anonymous+Brave+Guy · · Score: 4, Insightful

    This is all true, but I'm not sure how it's any different to almost any other popular language.

    Java and C# have also evolved a lot of new language features in recent years. For many types of software, the way the code looks will also be heavily influenced by which libraries and frameworks are used in that project's stack.

    It's the same story for web development. We have different flavours of JavaScript (ES5 in most browsers today, but ES6 just around the corner and supporting a wider range of programming styles), Python (2 vs 3), and so on. And with these more dynamic languages, the style is often even more guided by a framework if you're using one.

    Even if you're not using pervasive third party frameworks or libraries, any project of non-trivial size is going to adopt its own conventions and build its own abstractions to suit its particular needs, and then the rest of its code will again become its own dialect written in terms of those conventions and abstractions.

    In fact, I can't think of any mainstream language except for C that doesn't suffer from the "dialect" problem to some extent. And that's because C is a 20th century language in a 21st century world, so lacking in expressive power that it can't support any of these modern, high-productivity development styles and abstraction tools. Its ubiquity, portability and simplicity are assets, but they are effectively its only redeeming features in 2015, and as time goes by it will be necessary for fewer and fewer projects to choose C for those reasons.

    "There are only two kinds of languages: the ones people complain about and the ones nobody uses." -- Bjarne Stroustrup

    "If you attack a tool based primarily on not liking the people who use it, you're still just a bigot, no matter how famous you are." -- Anonymous Slashdot poster

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  42. C++ = all the performance of assembly language ... by Anonymous Coward · · Score: 1

    C++ = all the performance of assembly language + all the ease of use of assembly language.

  43. It is horrible, but also wonderful by Anonymous Coward · · Score: 0

    C++ is very powerful. (Much like gasoline)

    You can write high performance systems code that is well structured and easy to read and maintain. (rare, but possible)
    You can write garbage that is bloated and fully ofuscated while still following perfect OO practices. (much more common)

    The problem is to have the good sense to restrain how clever you get when using it.

    C is less of a problem in this manner because is has less ways to get clever.
    One can still make quite a mess with it.
    Witness another example that is both horrible and wonderful.
    The Linux kernel.

  44. Yes. by Anonymous Coward · · Score: 0

    Python might be clean, but I can't build Android apps in it (yet, and not using a product officially supported by Google).

    I can write high-performance engines in C++ (which can out perform equivalent Java code), and then port that code to Android, Windows, Linux, or pretty much anything.

    C++ is really frustrating for developers who don't like working with low-level code. Those of us who do can make good use of object inheritance for code organization. Of course you don't need objects for that...you can do it all in straight C. But most (excluding Linus) of the people who hate C++ hate it because of how similar it is to C.

    And, of course, anything can be done wrong. The pain of mistakes is felt more poignantly in C++, producing a need for greater vigilance. That is a challenge that few are ready to accept.

    1. Re:Yes. by EmperorOfCanada · · Score: 1

      One of my favourites is cocos2d-x which uses C++ for mac, win, iOS, Linux, and android.

      There is an interesting project called Kivy which allows for android and iOS Python development. But while very cool needs a bit more ripening for primetime.

  45. Re: Ugh by neokushan · · Score: 1

    Have you got a source to that? I know it has been suggested numerous times, but I've yet to see anything to state that it's actually picked to go into the standard.

    --
    +1 IDisagreeSoHeMustBeATrollOrAnAstroturferOrAShill
  46. Re:Python/Fortran Combo by goombah99 · · Score: 4, Interesting

    I have discovered late in the game that Python + Fortran is almost magical. It's better than Python C++. when you are needing fast algorithms or code close the metal (SIMD or GPU) then fortran provides all the muscle that you need without all the baggage of c++. You offload complex class and memory allocation to the python.

    The amazing thing I really like about the fortran is that it compiles so damn fast compared to C++ that it's easy to write a python program that generates optimized fortran and then compile it at run time rather than simply pre-compile a C++ library to include. The fortran is cleaner looking and its hard to make typos. The limits and ugly bits of fortran are pretty much not a concern since those chores can be offloaded to the python.

    --
    Some drink at the fountain of knowledge. Others just gargle.
  47. Linus was full of it by Anonymous Coward · · Score: 2, Informative

    Languages run the gambit from script kiddie interpreted languages that were designed for children to cut and paste examples from the internet to esoteric languages meant to be used only by doctoral students doing research. C++ is a nice middle ground that requires some expertise to use correctly, but offers immense power if you take the time to develop that expertise. I've written 3d accelerated GUIs with it, I've written mathematical algorithms with it, I've written real-time embedded applications with it. All to great success. Of all the languages I've encountered in my 14+ years as a software engineer, C++ by far covers the broadest spectrum of possible applications.

  48. Any Popular Language Attracts Dolts. by Anonymous Coward · · Score: 0

    Any Popular Language Attracts Dolts.

    Just look at Java, Php, BASIC, ... and now, Python.

    Was Linus wrong? Maybe not. Does it only apply to C++ - definitely not.

  49. It's not the code features by Anonymous Coward · · Score: 0

    It's not operator overloading, not class inheritances (per se), not any of the features "only language experts understand", but that an entry into a program code segment can do a vast amount of work that is absolutely not coded in that program, that understanding the code requires far more than the code in front of you.

    Default constructors. And, yes, this is down to class inheritances, but only if they do something with the constructors that isn't going to be obvious, hence my point. You need to know what other code does too now.

    EVERY higher level language has this problem.

    Hell, if you have a language that all it does is make pointers safe, but otherwise no higher than C, you may not know what it is *actually* doing. Which is not necessary when the code works, but when it doesn't, can be harder to work out why than the dangliest C pointer corruption.

  50. C++ Downfalls, Compiler and Internationalization? by chaim79 · · Score: 3, Interesting

    This must be prefaced by mentioning that I have little experience with C++ code, the industry that I am in (Safety Critical Avionics software) absolutely refuses to use the language. In fact, the only thing I can really comment on are the reasons given to me as to why it is not used in this industry.

    Compiling repeatability
    Part of Safety Critical Avionics is that the binary must be perfectly re-creatable. At any time if an issue comes up someone must be able to rebuild the configuration used for compiling (versions, software packages, patches, etc.) and get a perfect match to the released binary, bit-for-bit perfect. Somehow most C++ compilers and libraries are unable to achieve this, using the same exact machine (no patches or changes) and compiling at a different time gives a different result. This has been demonstrated on several different compilers, using nothing other than standard libraries.

    Code-to-binary and structural coverage analysis
    For DO-178B Level-A software (paraphrase: "If this software fails, people die.") there is an analysis performed matching every line of code to a block of assembly, verifying that the compiler didn't add anything in that will cause issues. This prevents using some optimization options in C as that makes things too unreadable. However that also excludes C++ STLs and Boost libraries, as once you get into those libraries the traceability breaks down into impossibility very quickly.

    Internationalization
    On the side our company works on non-safety-critical software projects as companies need our help and we are looking for work. One of those side jobs is taking an application written over several years for a research facility and making it ready to be sold internationally. The project uses C++ and is converting X11 and Motif to QT, at the same time updating it to go from hard-coded English to strings that can be translated to multiple languages. The amount of cursing I hear from those engineers dealing with the internationalization of C++ far outweighs everyone else in the company on all other projects, apparently the design of the C++ language made many decisions that make such efforts very difficult.

    So, mostly hear-say but from trustworthy and knowledgeable people, which is why I rarely touch the language.

    --
    DEMETRIUS: Villain, what hast thou done?
    AARON: Villain, I have done thy mother.
    Shakespeare invents 'your mom'
  51. Austin Lounge Lizards say it best by MerlynEmrys67 · · Score: 1
    --
    I have mod points and I am not afraid to use them
  52. C++ by Anonymous Coward · · Score: 0

    I have noticed (in myself, as well ) that when learning a new area of C++ the tendency
    is to use the new hammer on everything that looks like a nail - in other words, EVERYTHING...
    I have had to become rather self-critical about what tool ( C++ has many ) to use for a specific task...
    I submit that the same applies to ALL programmers enthused about a new tool... in ANY language...
    So the programmers are at least half of it.

    The other half is half-ass completed or poorly designed APIs ( MS, SUN), compilers that are not quite implemented (MS, SUN),
    and the incoherence of volunteers developing modules and add-ons to languages ( Python, maybe PHP, RUBY )
    that are not competely tested, or have quirks that are not documented ( work-arounds ).
    Most of this part comes from the 'GET IT OUT THE DOOR" mentality that has produces OSs that need >500 MByte updates,
    versions that fill in the 2.xx with xx being from 01 to 99, and worse than the MS 'DLL HELL", where things require different
    versions to operate properly, or at all...

    Bah - this is not engineering, where methodology/planning/foresight/completion/testing/documentation is a standard.
    This is software, where the latest and greatest of anything might not be complete, but is so new and shiny that the
    young software people expose their inner blondes. Or the old software people skoff and try to keep the thing they spent
    years learning...
    XML is just structured text, DOM is just structured text, stylesheets are just more text that acts like
    program directives, MS wants to back away from .NET - just like VB6.
    STL is just a new way to do what can be done through inheritance, with many more caveats...
    and Adobe Flash, Macromedia SW, and all the Intertubez Tuulz are just ways to make proprietary
    things workable, and esy to use...

    Looks like I just might be cynical - or maybe dead-on.

  53. Which pays more to use? by LordZardoz · · Score: 2

    Set aside for a moment about which programming language you like to use the most, and how much it upsets you that "People you Do Not Know also Do Not Like what You Like". Many of us are employed to work on projects we did not start. In most cases, you are not going to start a job and tell people 'Henceforth, all code shall now be implemented in the One True Language'.

    Assuming that, which language is going to get you paid the most and make you most employable?

    I am a game developer, and I have worked on consoles and currently on mobile games. I have used mostly C++. But I have had to work with pure C and C#. Being able to write good code in C++ is primarily responsible for me being employed.

    END COMMUNICATION

  54. Mod parent up by Prune · · Score: 1

    Good to see a decent post in a deluge of trolls trolling trolls under a troll article posted by Dice Co. shill er I mean Nerval's Lobster.

    --
    "Politicians and diapers must be changed often, and for the same reason."
  55. Read the Scott Meyers Effective C++ books by quietwalker · · Score: 0

    I see lots of responses from folks attacking the flippant parts of Linus's comments like they were deciding factors. This tells me that you're not getting it. Maybe you've never used C++ for significant projects, or really only relied on the C-like portions of C++ and eschewed the other stuff.

    The fact is, he barely even touched upon the real problems with C++, only mocked and ridiculed people who favor it. This wasn't an argument, this was just an insult.

    However, if you want reasons, you can get them from one of the best sources possible. Find or purchase a copy of Effective C++ and More Effective C++ and while you're reading them, keep track of all the 'gotchas' that will tank your programs. From accidentally instantiating a dozen copies of an object to double-freeing it, you should swiftly realize that most of the code you wrote was a time bomb, hidden away in a layer or two of abstraction. That 98% of the code you've ever seen that's larger than a handful of classes is like this.

    If that's not enough for you, look up the various ISO/IEC standards, and look for all the parts that are explicitly aimed at reducing ambiguity. From the start, C++ has undefined behaviors built right in, leaving it to the compiler to determine how syntactically correct code will perform. They're still trying to fix them; I hear c++17 is on the horizon, but in 2007, it was just a field of landmines if you started using the advanced features like templating or multiple inheritance.

    The short version is that it was not a very good language. In the race to produce "C with classes," delivery was prioritized over quality, new features rather than stability, and the standards committee, partly in an attempt to maintain backwards compatibility, has produced a fair mess with overly complex syntax.

    I've written a lot of c++ code, and I can't believe anyone who also has would prefer it to C, or something newer like Java, C#, or even scripting languages. I really have to assume that if you really vehemently stick to it, you're either a C++ guru with a few books and a decade of conference presentations, or you're a novice who hasn't done enough to understand the limitations.

    1. Re:Read the Scott Meyers Effective C++ books by jejones · · Score: 1

      And especially watch Mr. Meyers's talk "The Last Thing D Needs" (https://www.youtube.com/watch?v=48kP_Ssg2eY). tl;dw version: The last thing D needs is to require someone like Scott Meyers; don't make D so perversely convoluted that one can make a living explaining it to people.

    2. Re:Read the Scott Meyers Effective C++ books by serviscope_minor · · Score: 1

      OK, so given the argument from Linus was C in favour of C++, I assume this is things where C++ falls down compared to C++.

      From accidentally instantiating a dozen copies of an object to double-freeing it,

      lolwot?

      Those are classic problems, especially the double free in C. C code is littered with that crap. I write C++ and I haven't had a memory leak or double free in probably 8 years now. And truse me, it's not because I'm so super-awesome. It's because I use the tools C++ provides as intended.

      std::vector, other STL containers, shared_ptr, auto_ptr (and now unique_ptr). And never ever ever delete in user code.

      If you have problems with double free in C++ in this decade, the problem lies with you or your codebase, not C++.

      From the start, C++ has undefined behaviors built right in,

      Uh yeah? Given the whole linus rant was C versus C++, almost all of C++'s undefined behaviour is inherited directly from C.

      --
      SJW n. One who posts facts.
    3. Re:Read the Scott Meyers Effective C++ books by Bent+Spoke · · Score: 1

      My favourite: an uncaught exception (like from map.at()) causes the program to exit with no trace of where the problem originated.

  56. So what's the better option? by wonkey_monkey · · Score: 1

    A lot of developers dislike how much C++ can do "behind the scenes" with STL and Boost, leading to potential instability and inefficiency.

    What does that even mean? Isn't the same true of any library in any language? And can't they also lead to greater stability and greater efficiency?

    --
    systemd is Roko's Basilisk.
    1. Re:So what's the better option? by loufoque · · Score: 1

      Linus is referring to Monotone, a distributed versioning system a bit similar to Git that was written in C++.
      It uses the STL extensively, and it was slow because the STL is built on a paradigm where copies can easily happen without you being able to easily keep track of them.

      Since C++11, work has been done to alleviate those problems with move semantics and in-place insertion.

  57. Weaklings go home! by Anonymous Coward · · Score: 0

    One can achieve amazing things with C++. But doing it well requires that one be a genius. Not everyone is a genius. Non-geniuses need to use simpler tools like VB.NET to get useful things done. Naturally, non-geniuses will find C++ hard and hence will hate it. The reason they attack it, however, is because they recognize the great things that have been done with it.

    If C++ was some obscure language that nobody used, nobody would care how horrible it is. But precisely because many geniuses have made such profitable use of C++, the non-geniuses are confronted by it and are unable to compete. So, they attack.

    Attack away. Meanwhile, I will stay busy writing engines that scream!

    1. Re: Weaklings go home! by Anonymous Coward · · Score: 0

      im guessing mommy and daddy never showed you any love.

      anybody can be a c++ expert if given the amount of coding time required. times may vary of course.

      you write engines that scream? ummm thats not a good thing. if your compiler is screaming errors and warnings, well thats obvious.

      once again you put down people who dont know the language because they did not put the time in.

      if writing c++ code that screams makes you a genius, i am glad i am average ;)

      BTW, lets see some
      of this screaming code you are talking about. i call bullshit.

  58. Re:Aren't all (but one) popular languages like thi by Wootery · · Score: 3, Insightful

    I can't think of any mainstream language except for C that doesn't suffer from the "dialect" problem to some extent

    What about GObject?

    As you say, C is a very bare-bones language, so it's not uncommon to see the object-oriented wheel reinvented as a C library, incompatible with the other such reinventions.

  59. Casting by ziggystarsky · · Score: 3, Insightful

    Casting is telling the compiler to do what you want. It's like saying "Shut up! I know what I'm doing, this thing is a XY pointer, even if you can't figure it out yourself."

    In every language (which supports casting) you can make an error while casting by claiming something that isn't correct. Surprise!

    1. Re:Casting by ziggystarsky · · Score: 2

      What I really wanted to say: Just allowing casting does not mean loosing type safety. If you use casting and crash it's your fault.

      The language is just not very type safe if you need to cast often during regular programming.

    2. Re:Casting by sjames · · Score: 1

      Exactly, so why the claims that C++ is so much safer?

    3. Re:Casting by Dutch+Gun · · Score: 5, Insightful

      Modern, properly designed C++ code is absolutely safer than C code. However, because C++ is a superset of C, you can obviously write code that's just as unsafe as C, simply by ignoring the best practices and writing "C with classes" (which many do). A lot of what you can do in C++ exists solely to provide backward compatibility, both with earlier versions of itself as well as with C.

      C++ gives you the ability to create new types using objects, which you can operate on both through member functions as well as logical operator overloading (where it makes sense to do so). For instance, you could create a class for handling file paths (as opposed to using raw character pointers or arrays, or even C++ strings), and when that class is properly developed and debugged, you can then be confident that you no longer have to worry about accidentally creating a security vulnerability or introducing a crashing bug. Moreover, it can handle path-specific things, such as ensuring proper form when paths are concatenated. Even better, when compiled down, it's really no different than code written in C, since C++ still adheres to the "zero-overhead" principle for most features.

      When people talk about C++'s "dangerous casts", they're almost universally taking about "C-style casts", which are discouraged in modern C++. Instead, you should use the more explicit casts, which either use static compile-time checking or even run-time checking as appropriate. Whenever you have to resort to a C-style cast in C++, you had better have a *very* good reasons (in many cases it's just a design failure). Nowadays, that also includes managing raw memory or raw pointers thanks to the addition of standardized smart pointers.

      This is why C++ is almost universally used in the videogame industry (I work as a videogame programmer), because is strikes a reasonable balance between safety, advanced language features, and performance. It's also nicely compatible with C libraries, with which we often have to interface at the OS level, or when using 3rd party libraries. And finally, while "better" alternatives arguably do exist, C++ is also well supported and extremely ubiquitous across the industry. As the saying goes, "quantity can have a quality all it's own". This is important when trying to hire experienced developers, or looking on the web for solutions to a problem.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    4. Re: Casting by BlueTrin · · Score: 1

      But mot of people will not be the C style cast and other casts such as dynamic_cast are a bit safer.

      --
      Don't you know it is now both immoral and criminal to think beyond the next quarterly report?
    5. Re:Casting by ChunderDownunder · · Score: 1

      We had such typing in Java once. Then programs started failing at runtime with a ClassCastException. So the burden moved to the compiler in the form of generics. This sporned a new category of NullPointerException, when referencing primitive int and double variables (autoboxing). So people switched to Scala, where null pointers where eliminated at compile time via the Option type.

      Casting is a bad smell in a sufficiently evolved statically typed language.

    6. Re:Casting by Anonymous Coward · · Score: 0

      C++ is a superset of C

    7. Re:Casting by ziggystarsky · · Score: 1

      I was able to avoid casting completely for over two years while working in Scala. Certainly, the kind of work I did somehow supported this.

      Only lately I had to resort to casting sometimes. But this happened only when dealing with rather complex types that abstract over nearly arbitrary computations. At one point you reach the ceiling of what is achievable with some fixed type system—and then you need casting.

      I am now using shapeless for meta-programming, but I think this is the point where you yearn for more a expressive (dependently typed) type system than the one offered by Scala (or even Haskell). I hope the next generation of programming languages will make this practical.

    8. Re:Casting by Anonymous Coward · · Score: 0

      C++ is not a superset of C. There are various areas where they are entirely incompatible, such as their treatment of array initializers.

    9. Re:Casting by Bent+Spoke · · Score: 1

      C casts are a necessary evil! While "C++ cast operators are nothing but a major annoyance":

          https://www.informit.com/guide...

    10. Re:Casting by serviscope_minor · · Score: 1

      Wow, that guy is misinformed.

      The whole "pointer to function to integer cast" "should" work on "most modern platforms". Except where your platforms are small embedded ones, for example. The reinterpret_cast makes it 100% explicit that the code is actually NOT portable and might break on some platforms.

      And the person who wrote that article rags on C++ for making it explicit because he happens to not realise there are platforms on which it breaks. I'm glad the C++ is staffed with people including embedded experts rather than listening to know-it-alls with serious knowledge gaps.

      --
      SJW n. One who posts facts.
    11. Re:Casting by shutdown+-p+now · · Score: 1

      Because it doesn't implicitly downcast void* to anything else, for example?

  60. Complex systems? by Anonymous Coward · · Score: 0

    I have programmed in C for 30+ years and C++ for 20+ years. For complex systems, I like C++. Unfortunately, starting with C++11, the language standards committee has forgotten the KISS principal, and that is probably what irritates Linus more than anything (not sure, just reading between the lines), as well as myself. I have written "object-oriented" code in C, but some of my projects could not have been written effectively in C, but C++ let us do some amazing things, and much simpler and quicker than doing them in C.

    I personally don't think there are idiots who can write "decent" code in C++, and there are plenty who can write horrible code in C. Some parts of the Linux kernel make me shake my head in despair! Writing decent code in any programming language is not for idiots, but for people who are thinking about what they are doing, modeling it rationally, and then committing that model to code. I like to start with UML - it allows me to look at the data structures, relationships, behaviors, and then understand what I have missed. I spend 80-90% of my time modeling, and 10-20% writing code. That has allowed me to create reliable systems in 1/2 or less time than other approaches.

    1. Re:Complex systems? by anonymous_echidna · · Score: 1

      I agree (and I have a similar number of years coding experience, but not with C and C++). Diving straight into writing code might feel productive, but is a recipe for disaster.

      --
      In most times, most places, by most people, liars are considered contemptible. - Ursula Le Guin
  61. Re:C++ is fine for applications and frameworks by Wootery · · Score: 1

    C++ is a disaster for kernel development.

    I honestly have no idea, so: why?

  62. Bjarne Stroustrup is clueless by Anonymous Coward · · Score: 0

    It's obvious to me Bjarne Stroustrup doesn't have a clue regarding C++ and programming for that matter.

  63. Paradox by Anonymous Coward · · Score: 0

    Can we please apply Betteridge's law of headlines both to the story title and the question at the end of the summary?

  64. Re:Python/Fortran Combo by mvdw · · Score: 1

    Interesting. Do you have a web reference with a how to or example? I like the idea of using python to generate code; I have done it in the past to generate a multi-thousand line shell script (actually an xjobs script, but whatever) to generate animated movie frames.

  65. Bjarne Stroustrup is clueless by Anonymous Coward · · Score: 0

    You said a lot to say this. It's obvious to me Bjarne Stroustrup doesn't have a clue regarding C++ and programming for that matter.

  66. Horrible compared to what? by hey! · · Score: 4, Insightful

    Compared to C, sure. C was conceived in a spirit of pragmatic minimalism that's easy to love. I remember learning C from the K&R book back around 1980. That book was so thin it was practically a pamphlet next to books that taught you other languages. Everything about C was so neat, and trim, and cogent -- even the book everyone learned it from. That plus The Unix Programming Environment and perhaps Software Tools and you were cooking with gas.

    It's natural to compare C++ to C; the very name encourages you to do so. It was to conceived to dovetail and build upon C. But it was conceived with an almost diametrically opposite kind of philosophy. C chucked out all the precious features that designers were putting into languages in the late 60s and early 70s and went with a tiny set of proven useful features. C++ implemented every bell and whistle anyone had ever dreamed up for object oriented programming, which was largely an academic topic that was full of clever but impractical notions. Well, it turned out that a lot of those things like operator overloading and multiple inheritance weren't all that useful in the judgment of later language designers, but you can hardly blame Bjarne Stroustrup from knowing that in advance.

    It's practically impossible to overstate the practical success of C++. It took what was for most practicioners a theoretical idea (object oriented programming) and made it the way everyone programs by default. But you can't expect someone who loves C to love C++, which has almost none of the virtues that people admire in C.

    --
    Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    1. Re:Horrible compared to what? by loufoque · · Score: 1

      C++ is not about object-oriented programming. It's a multi-paradigm language, and OOP is one that tends to be shunned by its users.

    2. Re:Horrible compared to what? by serviscope_minor · · Score: 1

      a lot of those things like operator overloading and multiple inheritance weren't all that useful in the judgment of later language designers,

      Can you name a language without overloaded operators (not user defined overloading, but ANY overloaded operators)?

      You know, things like + working on both ints and floats AND doubles and maybe even strings! operator[] works on arrays of well, everything! Just about every language has that, and it breaks the "0 1 many" rule: as in operator overloading is allowed for an arbitrary number of cases that is fixed.

      Why those types? Why not others?

      Without user defined operator overloading, only a few types (and those arbitrarily selected by the language designer) feel natural and easy, the others are accessed through a mess of function calls.

      --
      SJW n. One who posts facts.
    3. Re:Horrible compared to what? by hey! · · Score: 1

      Oh, for pete's sake. Pedantic much?

      --
      Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    4. Re:Horrible compared to what? by serviscope_minor · · Score: 1

      No, not "pedantic much".

      I feel it's actually the central point. With non userdefined operator overloading languages, you're *still* accepting operator overloading, you're just restricting it to the subset the language designers happened to think of.

      Which, of course, implies that the language designers got it perfectly right first time, for all time.

      So you are *already* accepting overloaded operators, so why not a few of your own?

      Of course you can try to argue rationally, or you can try and dismiss a whole line of reasoning with a glib phrase. But that's the thing about anti-C++ people is they try to dismiss everything about C++ with glib phrases and emotion rather than anything rational.

      --
      SJW n. One who posts facts.
    5. Re:Horrible compared to what? by hey! · · Score: 1

      No, not "pedantic much".

      I feel it's actually the central point.

      I take it irony isn't your strong suit. I'm old enough to have programmed in assembly, so yes I understand arithmetic operators in C are indeed overloaded. But there is no feature in the language for the *user* to overload operators, which of course you know.

      --
      Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    6. Re:Horrible compared to what? by serviscope_minor · · Score: 1

      I'm old enough to have programmed in assembly

      So am I. Now, can we put away our dicks and actually talk about the point at hand.

      so yes I understand arithmetic operators in C are indeed overloaded. But there is no feature in the language for the *user* to overload operators, which of course you know.

      OK, so you've just written out the exact point I was trying to make. Um, well done?

      Yes all languages have overloaded operators. Not allowing user defined ones breaks the "0 1 many" rule of good design. So why stop at that particular, arbitrary subset?

      --
      SJW n. One who posts facts.
    7. Re:Horrible compared to what? by david_thornley · · Score: 1

      Actually, if you read Stroustrup's "Design and Evolution" book, you'll notice that he was pretty strict about allowing new features in. The one he wished he could get in and couldn't was Common Lisp's multiple dispatch (selecting a method based on the type of more than one argument). Every feature is in there for a reason, and Stroustup wanted a usable rather than a classroom language.

      Operator overloading is very useful, but when it's done right it won't be immediately obvious that it's happening. It allows complex numbers to be in the C++ library, for example, and other arithmetic objects like matrices and the like to be used intuitively. It's horribly abusable, but Stroustrup didn't consider that a reason to keep a feature out.

      All modern O-O languages I'm familiar with have multiple inheritance, although most of them allow inheriting implementation from only one parent. Most of the ones that use multiple inheritance in the C++ fashion have little problem with it. C++ multiple inheritance does have problems, which are generally avoidable by experienced programmers.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    8. Re:Horrible compared to what? by shutdown+-p+now · · Score: 1

      I think what he's trying to say is that the perils of having user-overloaded operators are vastly overstated, because the languages themselves overload them, quite often in less than obvious ways (e.g. overloading + for strings).

    9. Re:Horrible compared to what? by hey! · · Score: 1

      Because it's not particularly essential and so you wouldn't include it if your goal is a minimalist language like C. Which is *my* point. C++ has different design goals from C, and you have to take that into account.

      No doubt some if the dislike of user operator overloading comes from ignorance of how much type promotion goes on in all high level languages, but I'm not in that camp. I recognize it's a useful feature particularly if you are dealing with algebraic fields beyond the built-in types. It can be a sound decision either to include the feature or leave it out depending on your goals. For most C++ programs I've seen you wouldn't miss it much or at all if it were missing, and so I think it's a sound choice for languages targeted at those kinds of applications.

      --
      Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    10. Re:Horrible compared to what? by hey! · · Score: 1

      I don't think there's any validity to the view that user overloading of operators is hazardous, except to the degree any language feature can be abused. I'm saying it's not something you'd put in an OO language if you wanted to appeal to people who find C appealing.

      --
      Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
  67. Sure, but he's not wrong. by jcr · · Score: 2

    C++ is indeed a horrible language, and it attracts people who develop great pride in their memorization of needless complexity.

    -jcr

    --
    The only title of honor that a tyrant can grant is "Enemy of the State."
  68. Re:C++ Downfalls, Compiler and Internationalizatio by Anonymous Coward · · Score: 1

    Yet from what I've read, the Joint Strike Fighter project used large quantities of C++ in their systems.

  69. Some code was bad, therefore C++ is bad? by Anonymous Coward · · Score: 0

    That's like saying words are bad because we've read some bad poems written with words.

    I think all things that come from Linus are bad because he's said a few stupid things.

  70. STL by SoftwareArtist · · Score: 5, Informative

    You can argue about whether C++ is a horrible language (I lean toward "yes") in itself, but the libraries are what really push it over the edge. STL is hands down the worst collections framework I've ever encountered. Consider just a few examples of how you do some common operations with it, compared to doing the same things in Java and Python.

    1. Check whether a string s ends with a suffix t.

    Java: s.endsWith(t)
    Python: s.endswith(t)
    C++: s.rfind(t) == s.size()-t.size()

    2. Check whether a collection c contains an element e.

    Java: c.contains(e)
    Python: e in c
    C++: c.find(e) != c.end()

    3. Split a string s into tokens based on whitespace.

    Java: s.split()
    Python: s.split()
    C++: ... do you really want to know? Ok, check out http://stackoverflow.com/quest.... There you will find dozens of proposed solutions (many of them quite indecipherable), along with lots of debate about which one is best. The top voted solution has a comment on it (with several hundred votes) saying that it's a bad solution and you shouldn't use it.

    Doing even really basic, common operations with STL requires way too much work and produces absurd, hard to read code.

    --
    "I'm too busy to research this and form an educated opinion, but I do have time to tell everyone my uninformed opinion."
    1. Re:STL by Arkh89 · · Score: 1

      1. Check whether a string s ends with a suffix t.

      What about :
      !s.empty() && s.back()=='t'
      Or, before C++11 :
      !s.empty() && (*s.rbegin())=='t'

      2. Check whether a collection c contains an element e.

      For this one, the C++ implementation makes more sense than the other too : you can immediately store, test and work on the iterator and not wasting your time checking if the element is in the container, then find it again to work on it. If you don't need to use it, you can use std::count (because your container might contain it multiple times) as :
      std::count(myContainer.begin(), myContainer.end(), theValue)>0
      Or if you know that the element can only be present once, you should be using a std::set as container which already has a count function which only returns 0 or 1.
      mySet.count()>0

      Split a string s into tokens based on whitespace.

      std::string is still not very high level. Good parsing almost requires regexp methods which C++ did not have until recently (in the standard).
      Otherwise, the first solution given in your link is verbose but does the job.

      Do you have any other good examples?

    2. Re:STL by SoftwareArtist · · Score: 1

      Thank you, you just illustrated my point beautifully. :) You're right, instead of "s.rfind(t) == s.size()-t.size()" you could write "!s.empty() && (*s.rbegin())==t". And instead of "c.find(e) != c.end()" you could write "std::count(c.begin(), c.end(), e)>0". That's just so much clearer than "s.endsWith(t)" or "c.contains(e)". STL gives you lots of convoluted, hard to read ways of solving trivial problems. That makes your code even harder to read. Because not only is it obfuscated to begin with, but there isn't even a single "standard" way to do anything, so every person's code looks different.

      --
      "I'm too busy to research this and form an educated opinion, but I do have time to tell everyone my uninformed opinion."
    3. Re:STL by jejones · · Score: 1

      My favorite is how you append a value to a vector. push_back?!

    4. Re:STL by ncmathsadist · · Score: 1

      Precisely! Aren't the C++ arabesques tortured, opaque and disgusting??

    5. Re:STL by spitzak · · Score: 1

      1. Check whether a string s ends with a suffix t.

      What about :
      !s.empty() && s.back()=='t'
      Or, before C++11 :
      !s.empty() && (*s.rbegin())=='t'

      I think the gp was assuming t was another string, not a byte.

    6. Re:STL by ChrisMaple · · Score: 1

      1. s[strlen(s)]=='t' ______ This uses the standard C library string.h, which C++ inherits

      How 3 is done depends on whether you want to allow corruption of the original string.

      Why use the STL when more fundamental stuff is easier?

      --
      Contribute to civilization: ari.aynrand.org/donate
    7. Re:STL by SoftwareArtist · · Score: 1

      That won't work, for a few reasons. First, strlen() expects a char* as its argument, not a std::string. You need to write strlen(s.c_str()). But what are you gaining from using strlen? It's simpler to write s.size(). Second, you're dereferencing the null at the end of the string. You really wanted to write s[s.size()-t.size()] == t. Oops, but that's still not correct! It contains a very subtle error. If t happens to be longer than s, you'll be trying to access s with a negative index, which could lead to a (nondeterministic, of course!) segfault.

      Wouldn't it be nice if you could just write s.endsWith(t)? Why the @#$% do the C++ designers refuse to add methods for all these standard functions that every other language provides?

      --
      "I'm too busy to research this and form an educated opinion, but I do have time to tell everyone my uninformed opinion."
    8. Re:STL by russotto · · Score: 1

      push_back is the old way. It's now emplace_back, to construct the value directly in the vector rather than constructing it and then copying it.

    9. Re:STL by SchroedingersCat · · Score: 1

      Not everyone wants to install 50MB runtime package to split strings.

    10. Re:STL by serviscope_minor · · Score: 1

      My favorite is how you append a value to a vector. push_back

      What's wrong with that? A vector is very much like a stack in that you can efficiently push and pop from the back of it, but not anywhere else.

      --
      SJW n. One who posts facts.
    11. Re:STL by serviscope_minor · · Score: 1

      Not only that but strlen() is O(N) whereas the others are O(1), so not only is it hard to get right it's also slow!

      Wouldn't it be nice if you could just write s.endsWith(t)? Why the @#$% do the C++ designers refuse to add methods for all these standard functions that every other language provides?

      Look: I'm a fan of C++ and I think the STL is one of the best standard libraries out there. But holy fuck std::string is like a running joke which went sour 20 years ago and is now told by aging, overweight, bigoted and washed-up standup comedians.

      It's such a powerful language, but so why do I get a strong desier to gnaw my own arm off whenever string processing comes up?

      Basically, I love AWK. If your processing fits within the paradigm of that language (especially gawk-4 which blows the others out of the water), it is one of the simplest, most beautiful and elegant ways for processing text. C++ and string processing makes me sad :(

      --
      SJW n. One who posts facts.
    12. Re:STL by TVmisGuided · · Score: 1

      John Barnes, author of several Ada programming texts, sums it up:

      If software is safe, it cannot harm the world. If software is secure, the world cannot harm it.

      I have yet to see a non-trivial application written in C++ which is both safe and secure.

      And that's as far as I go.

      --
      All the world's an analog stage, and digital circuits play only bit parts.
    13. Re:STL by Anonymous Coward · · Score: 0

      Let's look at those "C++ examples"

      Example 1: std::string::rfind() - Guess what, that's not an STL function. Obvious from the fact that it doesn't return an iterator. It's a string method.

      Example 2: c.find() - That's not even valid C++. Containers do not have `find` methods.

      Example 3: Plenty of solutions, yes.

      You're failing to realize that the STL was primarily a container library. A typical STL class was vector. It just doesn't make sense to split a vector of ints by "whitespace". And how do you compose ints to form a "token" ? Now you can treat a string as a container of chars, so the string library was made STL-compatible. That didn't magically turn the STL into a string library.

      In short, you're criticizing the STL mostly because of your lack of knowledge.

    14. Re:STL by david_thornley · · Score: 1

      If you want "endsWith" or "contains", write them as templated functions. The C++ libraries sometimes just give you building blocks that you can use to make your own things. "find" is a lot more versatile than "endsWith" or "contains".

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    15. Re:STL by shutdown+-p+now · · Score: 1

      2. Check whether a collection c contains an element e.

      Java: c.contains(e)
      Python: e in c
      C++: c.find(e) != c.end()

      On the other hand, if you want to then read or update the element in the set after ensuring that it is there, you will need to make a second lookup in other languages, while in C++ you simply store the iterator returned by find(), and then dereference it. So it may be less convenient, but it's more flexible, and goads you into writing more efficient code.

    16. Re:STL by shutdown+-p+now · · Score: 1

      1. s[strlen(s)]=='t' ______ This uses the standard C library string.h, which C++ inherits

      You just went out of bounds due to 0-based indexing.

    17. Re:STL by SoftwareArtist · · Score: 1

      You can do the same thing in other languages too. Just about every collections framework includes something equivalent to find(). But very often you don't want to access the element, just check whether it's present. So for that common situation, they provide a concise, easily readable way to do it.

      --
      "I'm too busy to research this and form an educated opinion, but I do have time to tell everyone my uninformed opinion."
    18. Re:STL by SoftwareArtist · · Score: 1

      Exactly. It isn't really a full featured collections framework. It's more a set of low level primitives that you're expected to use to implement the higher level functions that every other collections framework provides out of the box. And of course, the functions you write will be different from the ones every other programmer writes: different names, different behavior.

      This is one of the common complaints about C++. It leads everyone to basically create their own personal language, and then it's hard to work on any other person's code because you first have to learn the non-standard language they've created.

      --
      "I'm too busy to research this and form an educated opinion, but I do have time to tell everyone my uninformed opinion."
    19. Re:STL by friesofdoom · · Score: 1

      Since this article is about C vs C++, can you give us C examples for the functionality you've sown? Aside from that, yours are not apples-to-apples comparisons, which is why they are different...

      Java: s.endsWith(t) => returns bool
      Python: s.endswith(t) => returns bool
      C++: s.rfind(t) == s.size()-t.size() => returns index
      Java: c.contains(e) => returns bool
      Python: e in c => returns bool
      C++: c.find(e) != c.end() => returns iterator/object

      So the C++ examples you have shown give you double the functionality, its not unexpected that they look more complex to use, but you also have to learn less library functions... Its a much of a muchness, and more of a library issue than a language issue.

    20. Re:STL by friesofdoom · · Score: 1

      How do you do these things in C, the language of relevance (since we are comparing c to c++)?

    21. Re:STL by shutdown+-p+now · · Score: 1

      You can do the same thing in other languages too. Just about every collections framework includes something equivalent to find().

      Not really. Try doing that in Python. Or hell, even in Java (with a Set).

      But very often you don't want to access the element, just check whether it's present. So for that common situation, they provide a concise, easily readable way to do it.

      For std::set, there's a similarly concise way of doing that in C++ - xs.count(c) (and for maps, there's the same for keys). For other collections, there's no such thing, but then a lookup there is O(n), so you don't want to make it too easy.

    22. Re:STL by Anonymous Coward · · Score: 0

      Two examples from std::string, one of the oldest classes in c++ with a lot of known design warts. Just follow the example set by tr1 and c++11 and use boost to solve these problems or depending on your project use Qt - both cover a lot of ground with Qt being a bit more Java like in style and boost following c++ as it should be since the first standard (long after std::string was written).

      Your second point is just a complaint that c++ containers do not implement a one liner, here it is

                    template bool contains(T const& cont, T::value_type const& val){ return cont.find(val) != cont.end();}

      This follows the concept of encapsulation, contains does not need any access to private members of the container class, so it can be implemented as a free standing method ( of course string also violates this ).

  71. C++ is nothing... by Anonymous Coward · · Score: 0

    ... compared to KCML! Kvetching heard of it? Try and keep it that way lol!

  72. Re:Aren't all (but one) popular languages like thi by Rei · · Score: 5, Interesting

    Honestly, I find a random program written in C to be on average FAR less maintainable than one written in C++, usually because they end up reinventing the wheel about 50 times, usually poorly. The C program that I work on at work is one gigantic mass of poor wheel reinvention over and over again. Its impersonation of objects and inheritance (for sending message) is terrible, utterly terrible, it's almost impossible to build and send a message without messing up in some way due to all of the interconnected pointers. The macros they use to try to "simplify" it only make it worse. Some parts of the code have macros nested literally dozens of levels deep.

    --
    "Are you hungry? I haven't eaten since later this afternoon." -- Primer
  73. C++ by Anonymous Coward · · Score: 0

    Torvalds: C++, your father made you /wrong/!!
    C++: Nooooo, baw

  74. YMMV by Anonymous Coward · · Score: 0

    Linus is often right, but opinions are just that, they can not be proven one way or the other.

    While C is my "native" language (having programmed in it since the mid 80s), C++ is definitely my "favorite" language -- and that includes the STL. Yes, people can fuck it up, but if you have fucked up enough code in the past, and have learned which end of the sword to grasp, C++ can be a very, very precise and very effective weapon.

  75. So, just write C code in it? by jonr · · Score: 1

    I was a total n00b when studying C++ in college, having only dabbled with BASIC, Pascal, C and ARM assembly before. But C++ surely felt way over the top.

  76. Seriously... by luis_a_espinal · · Score: 1
    Seriously, if we are going to complain about crazy parsing, pointer to array of ints is not a good example. This is a good (and thank goodness, relatively obscure) example:

    void (*signal(int, void (*)(int)))(int)

    with signal as a function that takes one int and one pointer to function that takes one int and returns void, and which in turn returns a pointer to function which takes an int and returns void. Thankfully, this shit is seldom seen in most applications of C, except in very specialized cases.

    The rest of cases it's nothing mind-warping if you know the rules.

    1. Re:Seriously... by david_thornley · · Score: 1

      That's what "typedef" is for. Put "typdef" in front, replace signal with signal_handler, and it's only really ugly in one place.

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

      That's what "typedef" is for. Put "typdef" in front, replace signal with signal_handler, and it's only really ugly in one place.

      Or cdecl...

      Of course. IRL we would use typedef to manage that kind of ugliness. But one will always encounter definitions like that - signal will never be defined with a typedef in any form of POSIX documentation.

      Thus working at certain levels, it is important to understand such declarations (if not fully, at least partially to ask the right questions.)

  77. Re:Aren't all (but one) popular languages like thi by Anonymous+Brave+Guy · · Score: 1

    True enough. It's always mildly amusing when someone criticizes a programming language for having features that let a programmer hide behaviour... and then advocates using macros in C instead.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  78. I must be new here by Anonymous Coward · · Score: 0

    But who is Nerval's Lobster and why is it his job to post submissions with links to Dice.com?

  79. WHAT HAPPENED TO SLASHDOT!? by Jeremiah+Cornelius · · Score: 1, Funny

    You're all talking about C++ and not LINUS TORVALDS! Have you all LOST your MINDS!? ;-)

    --
    "Flyin' in just a sweet place,
    Never been known to fail..."
    1. Re:WHAT HAPPENED TO SLASHDOT!? by FatdogHaiku · · Score: 4, Funny

      You're all talking about C++ and not LINUS TORVALDS! Have you all LOST your MINDS!? ;-)

      Hey! He didn't even pick up a chair!
      It's not a rant 'till someone has to place a furniture order with Staple's...

      --
      You have the right to remain sentient. If you give up the right to remain sentient, you will be elected to public office
    2. Re:WHAT HAPPENED TO SLASHDOT!? by Carewolf · · Score: 2

      You're all talking about C++ and not LINUS TORVALDS! Have you all LOST your MINDS!? ;-)

      I guess C++ is more controversial :D

  80. Yes. by Anonymous Coward · · Score: 0

    It is mind-bending to see so much people who call themselves C programmers, and judge c++ based on what terrible things you can do with it...

      News flash : you can write horrible, horrible code in C. Actually much much worse code than you could ever dream of in C++. At least C++ provides type safety unless you explicitly try to work around it.

      But the fact remains that idiomatic, good C++11 or even C++14 code is much more readable, much more safe and much faster / easy to write than C11 for anything non-trivial.

      I really don't understand Linus' argument about horrible programmers of C++. From my experience, bad C++ programmers write "C style" C++, so basically, bad C++ programmers are C programmers that were told to use classes, i.e. people who don't know C++.

  81. Re:C++ Downfalls, Compiler and Internationalizatio by Anonymous Coward · · Score: 0

    The amount of cursing I hear from those engineers dealing with the internationalization of C++ far outweighs everyone else in the company on all other projects

    To be honest you'll hear anyone writing C making almost definitely the same complaints if they need to internationalize and localise software. Internationalization is easy if someone has already put the messages into message catalogs (but usually ugly) localisation is the hard part if you also need to add support for multi-byte languages. Dealing with character strings that can be a series potentially multiple byte sequences breaks a heap of crappy optimisations that people write for the C and other single byte locales (I hate EILSEQ).

  82. Re:Ugh by Anonymous Coward · · Score: 0

    STL and Boost are (collections of) LIBRARIES (most of which are excellent 0-overhead, and type-safe). Are you trying to tell me there doesn't exist one single bad C library ?

  83. Re:C++ Downfalls, Compiler and Internationalizatio by Anonymous Coward · · Score: 0

    I write DO-178B Level-A software for a living in C++. This is exactly the kind of rhetoric that I hear from a regular basis from people that refuse to change from how things were done 20 years ago in avionics. There is guidance from the FAA on how to handle object oriented technology but you probably haven't read it because refuse to touch the language. We don't use templates period (no STL obviously), no multiple inheritance, no operator overloading, on and on... That said there is an advantage to using the language and I'm just so tired of hearing avionics people saying things like the language is not certifiable and digging into a bunch of uninformed assumptions. Grats on being the grumpy old man at your company.

  84. C++ is shit by russotto · · Score: 1

    and I say this as a professional C++ programmer. Nothing is straightforward. There are many ways to do anything, and every one of them has edge cases which don't do what you expect. It's got classes, templates, and functional stuff, all of which has bad syntax and works poorly together. It's got two things going for it, inertia from existing codebases and lack of any better on-the-metal language (unless you're willing to restrict yourself to C, which seems like a good idea much of the time).

    Ask a C++ compiler implementor about it sometime.

    1. Re:C++ is shit by serviscope_minor · · Score: 1

      It's got classes, templates, and functional stuff, all of which has bad syntax and works poorly together

      Work poorly together how? They're all orthogonal concepts and work together without any adverse side effects.

      Ask a C++ compiler implementor about it sometime.

      Well, all the major C++ compiler implementors seem to prefer to use C++ over any other languages that their toolchain supports. So, I guess it can't be all that bad. I mean sure, it's a total bastard to parse, but once you've done that it's generally very nice to write in.

      --
      SJW n. One who posts facts.
  85. Re:C++ Downfalls, Compiler and Internationalizatio by Anonymous Coward · · Score: 1

    This must be prefaced by mentioning that I have little experience with C++ code, the industry that I am in (Safety Critical Avionics software) absolutely refuses to use the language. In fact, the only thing I can really comment on are the reasons given to me as to why it is not used in this industry.

    Compiling repeatability

    This is plain wrong. I mean it is not even wrong, if you do work in this industry then this is a lie.

      Lots of software in lockheed martin's plane is in C++ for instance. Hell some technical chief officer of Lockheed even gave a talk about the SF++ coding guidelines they use @ cppcon14.

      On your other points : I design software for safety critical components in Nuclear power plants, and C++ has replaced Ada in most devices in the last 5-10 years.

      The last 2 years we wrote a complete full scale numerical simulation of the Command room of the powerplant, in C++/ QT / QML. Internationalization was done using QT mechanism and it works great... You had you wrap all your strings in "tr()". BOOM. Done.

      Last but not the least : C++ != (Boost || STL)

      C++ is a language specification. Boost is a collection of libraries, most excellent, some terrible. YOU DO NOT HAVE TO USE IT. The std c++ library (STL died 10 years ago, way to be a la page...) is as you could have guess a library. You don't have to use it either.

      ANd BY THE WAY : most of the C std library sucks too, and is prohibited to use by MISRA C. So stop reading or hearing FUD. Read the std specification if you want, or better yet read a good recent book about C++14 like the one from Bjarne S. You'll see.

      I agree with you on the compiler thing though. that is quite true.

  86. Re:Ugh by ChrisMaple · · Score: 1

    and support ^ as exponentiation

    What's stopping you? Define your own classes for numbers. Or write a preprocessor.

    --
    Contribute to civilization: ari.aynrand.org/donate
  87. c++ without classes by Anonymous Coward · · Score: 0

    > writing "C with classes" (which many do)

    Is it only me that are interested in writing "C++ without classes"?

  88. Unit testing by Anonymous Coward · · Score: 0

    We have a couple systems at our company. One, fairly straightforward OO host system, the other a truly embedded legacy pure C system. When it comes to writing unit tests, polymorphism wins hands down. We have to "re-invent" this in the C-only system to get unit testing working. PIA.

  89. Re:C++ Downfalls, Compiler and Internationalizatio by Anonymous Coward · · Score: 0

    Yet, we don't use C++ in planes, but it's used on the Mars Rover. There's no life at stake, but there are still billions invested in it, it's not risk-free and yet it makes sense and was successful.

    I suggest you watch the talk from the CppCon 2014 conference where they explain how they did it: https://www.youtube.com/watch?v=3SdSKZFoUa8

    I'm not trying to say that you should definitely switch to C++, but maybe some requirements are over protective and could be reevaluated. Also, compilers change a lot over time and could very certainly achieve what you need if your industry was working with them.

    As for your concerns about internationalization, a lot of those can be solved with some tooling. I don't believe it's the role of the language to do anything about that, but one of an external library (which you could change if you want) and the related tools. You're not internationalizing C++, you're internationalizing some strings in your app, which you can do in so many good, but also horrible ways, depending on your requirements.

  90. No, he was wrong by Pseudonym · · Score: 1

    C++ has many, many problems, but almost exactly none of the significant problems with the language were identified or enunciated by Linus Torvalds. All of his rants on the subject read like "Al Capone is a horrible person, because he cheated on his taxes".

    The STL is a case in point. It is, by far, one of the best parts of C++. The word "virtual" doesn't appear anywhere in its source code. Yes, the error messages are verbose; that's a compiler issue. Its only significant weakness is the allocator abstraction.

    --
    sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    1. Re:No, he was wrong by Anonymous Coward · · Score: 0

      Try compiling this C++ program (it crashes the compiler). // from: http://www.fefe.de/c++/c%2b%2b-talk.pdf
      template struct Loop { Loop operator->(); };
      int main() { Loop i, j = i->hooray; }

    2. Re:No, he was wrong by Anonymous Coward · · Score: 0

      This program crashes the compiler, because C++ is "too powerful": /* from: www.fefe.de/c++/c%2b%2b-talk.pdf */
      template struct Loop { Loop operator->(); };
      int main() { Loop i, j = i->hooray; }

  91. Re:Python/Fortran Combo by goombah99 · · Score: 2

    google F2Py. You will find lots of tutorials. Most significantly you may notice that f2py is integral to scipy.

    as for compiling fortran on the fly, this can be done through scipy as well or you can use system calls. Exactly how you do it depends on what compiler your system used.

    --
    Some drink at the fountain of knowledge. Others just gargle.
  92. It's A Completely Different Mindset by Greyfox · · Score: 1
    A lot of early programmers did treat it like C with objects, which really is a mistake when you're dealing with C++. You didn't hear much about RAII, relying on the optimizer to figure out when to move or copy objects, or magic stuff like boost shared pointers much before the middle of the last decade. I'm pretty sure the first time I looked at the language in the early 90's, it didn't have templates or a standard template library. I'm pretty sure I remember the discussion about adding templates to the language and how they were going to change everything.

    You can write some damned ugly C++, it's true. You can write some very nice C++ as well, especially if the guy who writes your libraries puts some effort into making sure your code doesn't have to be hideous. The boost guys do a pretty good job of it. Sure occasionally there's some overengineered fuckery (Looking at YOU, boost::program_options) but once you wrap your head around it, it really isn't that hard to read. I wrote a similar library to bind environment variables to C++ variables with type conversion and without the lisp style syntax, and it really isn't that different.

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

  93. Ken Thompson Agrees! by Anonymous Coward · · Score: 0

    From Ken Thompson, inventor of Unix, in a 2009 interview:

    "I would try out the [C++] language [at AT&T] as it was being developed and make comments on it. It was part of the work atmosphere there. And you'd write something and then the next day it wouldn't work because the language changed. It was very unstable for a very long period of time. At some point, I said, no, no more. In an interview I said exactly that, that I didn't use it because it wouldn't stay still for two days in a row. When Stroustrup read the interview he came screaming into my room about how I was undermining him and what I said mattered and I said it was a bad language."

    "[C++] certainly has its good points. But by and large I think it's a bad language. It does a lot of things half well and it’s just a garbage heap of ideas that are mutually exclusive. Everybody I know, whether it’s personal or corporate, selects a subset and these subsets are different. So it’s not a good language to transport an algorithm—to say, "I wrote it; here, take it." It’s way too big, way too complex. And it’s obviously built by a committee. Stroustrup campaigned for years and years and years, way beyond any sort of technical contributions he made to the language, to get it adopted and used. And he sort of ran all the standards committees with a whip and a chair. And he said "no" to no one. He put every feature in that language that ever existed. It wasn't cleanly designed—it was just the union of everything that came along. And I think it suffered drastically from that.

    From a 2011 interview, after Ken Thompson, Rob Pike, and Robert Griesemer had created the Go language:

    "When the three of us [Thompson, Rob Pike, and Robert Griesemer] got started, it was pure research. The three of us got together and decided that we hated C++. [laughter] ... [Returning to Go,] we started off with the idea that all three of us had to be talked into every feature in the language, so there was no extraneous garbage put into the language for any reason."

    1. Re:Ken Thompson Agrees! by loufoque · · Score: 1

      C++ is a pragmatic language, not an idealistic one.
      It has everything yes, it's a strength not a weakness. All the tools are at your disposal, and you're still free to build your own style with them.

  94. Torvalds is a rant. by sciop101 · · Score: 1

    Nothing MORE. Nothing LESS

    --
    The only thing new in this world is the history that you don't know.[Harry Truman]
  95. I am with Torvalds by ncmathsadist · · Score: 1

    C++ is like a house that has gone through many additions. It has become grotesquely verbose. It is riddled with awful constructs like dynamic cast and "casting away constness." I still like C a lot. It is small, fast, smart and, sometmes, merciless. But that's OK. It's OO cousin has become a steatopygean monster.

    1. Re:I am with Torvalds by loufoque · · Score: 1

      C can cast away constness too.
      C++ added special constructs for this to make it more explicit you were doing something evil.

  96. Re:C++ Downfalls, Compiler and Internationalizatio by emh203 · · Score: 1, Interesting

    Yet from what I've read, the Joint Strike Fighter project used large quantities of C++ in their systems.

    You mean that fighter that is still over-budget, over schedule and the software systems still don't work?

  97. Re:C++ Downfalls, Compiler and Internationalizatio by emh203 · · Score: 1

    This is also true in safety critical automotive. I have never seen C++. It is just dumb to use it.

  98. Do as I say, not as I do by Anonymous Coward · · Score: 0

    "you are full of bs", but apparently doesn't apply to the "code of conduct"

    https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=b0bc65729070b9cbdbb53ff042984a3c545a0e34

  99. Obviously not familiar with HTML by RogueWarrior65 · · Score: 1

    And the huge volumes of crappy code upon which the entire shaky foundation of internet is built.

  100. C# is where I want to be by Anonymous Coward · · Score: 0

    Yes, good comment. I was a long-time C++ dev before I switched to C# in 2001, with the occasional forays back to C++/Boost and some Java in the intervening years.
    For me, C# wins hands down. You may not write an OS in it, or a FPS, but for LOB apps it wins for me hands down. They took Java and threw out the hairy bits, and added lots of nice things. LINQ for example.... pure magic. And a super-comprehensive API with a great IDE that's as comfortable to me as a pair of old jeans.

    I have never been able to write as much useful customer-oriented code in in any other language as I have for C#. And with the recent opening up of the .NET Core I hope for a long future with it!

  101. Re:Aren't all (but one) popular languages like thi by ChunderDownunder · · Score: 2

    Yep hence Vala, which transpiles to C-with-GObject.

  102. Re:Python/Fortran Combo by Anonymous Coward · · Score: 0

    Interesting! Do your comments apply to commercial Fortran compiler(s), open source, or both?

  103. C equivalent of STL by Anonymous Coward · · Score: 0

    Here's a question - is there any equivalent of STL in pure C? A robust container library is a huge,huge thing.

    I have been part of projects that specifically chose C++ because of Boost and STL - we would rather live with style guides and linting tools,rather than without STL.

  104. Re:Aren't all (but one) popular languages like thi by ceoyoyo · · Score: 1

    The only thing worse than macros in C is macros in C++. Because doing fancy shit with templates AND macros is more than the sum of it's parts.

  105. Troll Article by Anonymous Coward · · Score: 0

    "There are plenty of rebuttals to his attack, but I’ll just make two points. First, he obviously knows his stuff. Second, C does have its place if you’re writing systems-level code that you want as tight and portable as possible. That latter concern aside, though, this is the 21st century: Why write dozens of lines of code when a single line of code (as with C++) will do it?"

    This sums up the authors point of view well: completely fucking lazy.

    I swear, if I hear another person ask my why I don't just use Boost I will fucking stab them.

  106. Re: Ugh by don.g · · Score: 1

    You don't have to write your entire application in the C preprocessor. Or in templates. Although if you are coming from a language like Perl I can see how they might be attractive.

    --
    Pretend that something especially witty is here. Thanks.
  107. He's wrong. by Anonymous Coward · · Score: 0

    It's a great expressive language.

  108. History of programming languages by Anonymous Coward · · Score: 0

    Sorry C++. Sprinkles are for winners.

  109. Meh by Anonymous Coward · · Score: 0

    Loonix Toreballs is an egomaniac whose value is greatly overrated.

  110. The problem is C++ instead of C with classes by mlwmohawk · · Score: 1

    C++ is a VERY powerful system, but it is too much. The C language has 90% of what you need. Any non-trivial C application will end up re-implementing basic features in C++. The problem comes when C++ becomes, in the eyes of its developers, its own language. If used as "C with classes," many of the problematic issues are gone.

    All that being said, bad developers will find a way to write bad code.

    1. Re:The problem is C++ instead of C with classes by david_thornley · · Score: 1

      If you use C++ as its own language, and not as C with Classes, many of the problematic issues are also gone.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  111. Idiots. by Anonymous Coward · · Score: 0

    The real problem is that people are idiots. The vast majority of programmers I've seen are substandard. These so called "experts" write crappy software in any language. Including C. Or Python. Or Matlab. Or C++.

    Then there is the other problem of people being set in their ways. Sometimes superior technology (or approach) is ignored because people do not like to change or learn something new. Because people are comfortable in their bubble.

    And this is simply the human nature. People are idiots and you cannot cure stupid. And people are set in their ways.

    What does that add up to? People will attack anyone and anything that they do not understand, or are too stupid understand. It doesn't matter what that is really.

    C++ is one of the most powerful programming languages (if not the most powerful). It allows a skilled person to write very high level software rapidly, or write very low level software that is very efficient. Anyone that does not see that is either an idiot or they are set in their way.

    Obviously, with great power comes great responsibility. A crappy programmer will do bad things with it, just like any other language.

      But again, you cannot cure stupid.

  112. Linus was being too nice. by xx_chris · · Score: 1

    A fair comparison is Linux vs LLVM.

    Linux is written in clean fast readable maintable C with GCC extensions.
    LLVM is written in C++.

    Go ahead and look.

  113. Re: Ugh by Dutch+Gun · · Score: 1

    Here's a link I found that gives approximate timelines to various features. Nothing is set in stone of course, because it's difficult to predict what sort of issues may come up that would prevent timely adoption. The committee has a tendency to just drop a particular proposal rather than letting it slow down the whole process.

    --
    Irony: Agile development has too much intertia to be abandoned now.
  114. He's right by eighthdev · · Score: 0

    Linus was most definitely correct. I've been using C++ for decades; most of the time in most of the places I've worked, as a nicer version of C. Some of the places decided to go "template crazy" and ended up with unmaintainable code (and extremely difficult to debug as well). The very worst part of C++ is that missing something arcane (like forgetting to put "virtual" on a destructor) can lead to hours and hours of debugging fun. There shouldn't even *be* an option to forget something that screws you over like that.

    1. Re:He's right by loufoque · · Score: 2

      C++ is a language for experts, but so is C.

    2. Re:He's right by serviscope_minor · · Score: 2

      There shouldn't even *be* an option to forget something that screws you over like that.

      Every major compiler warns about that and has done for years.

      And there are also some good reasons for not wanting virtual destructors because they can introduce unacceptable performance penalties in high performance code.

      Check out any of the libraries that do fixed-length linear algebra stuff. They use (internally) quite complex systems of derivations to allow the resulting classes to have all the features you expect.

      The resulte is that something like Vec supports all the operations you expect from linear algebra, but has precisely the same overhead as double[3]. If you had to have virtual destructors then you'd have to write the code C-style to get good performance.

      The result would be code that is ultimately much less clear and therefore much harder to debug.

      --
      SJW n. One who posts facts.
    3. Re:He's right by serviscope_minor · · Score: 1

      Gah slashdot. That should be Vec<3>, not Vec.

      --
      SJW n. One who posts facts.
  115. Torvalds was RIGHT by emzee · · Score: 0

    There aren't enough bad words to fully describe how bad C++ is as a programming language. Take every single possible pitfall present in C - and there are may - and then magnify that by bolting a totally kludged class and inheritance structures on top of that.

    1. Re:Torvalds was RIGHT by loufoque · · Score: 2

      There are two bad ways to code in C++: the C way and the Java way.

      You're talking of inheritance, that's something you use in the Java way.

  116. Re:Ugh by Twinbee · · Score: 1

    "Bloated" as in so many different ways to do things that only the person who wrote the code can understand it. Too much redundancy basically.

    Decent languages? Try D. C# is bloated too, but at least it offers managed memory and you can fall back to non-managed code at any stage.

    --
    Why OpalCalc is the best Windows calc
  117. Re:Ugh by sunderland56 · · Score: 1

    The only problem with C++ is there are too many idiots out there who can only write software in dumbed down languages

    Isn't C++ just a dumbed-down version of C?

  118. It makes the simple complicated by Anonymous Coward · · Score: 0

    It makes the simple complicated. It takes a road over flat and level earth and adds steep curves and hairpin turns. What's not to like? You can easily write object oriented-like code in C. You don't need destructor functions unravelling a spinlock. Yet C++ will cheerfully do this for you. We have piled abstraction on top of abstraction. There are a lot of C++ programmers who 'just let the computer figure it out'. It can lead to inefficient programs and a loss of 'feel' for the hardware. I don't think Torvalds got it wrong. One of the real gems of C is that its a complete, compact language. You can get any piece of C to interact with any other piece. Its quite efficient. It takes the Strunk and White effect to language definition. The C language definition was made with pith in mind. C++ on the other hand, is like most other object oriented languages. The language definition doesn't quite fit the encyclopedia britannica, and new volumes have to be added every year to capture all the latest extensions and add-ons. You are required to keep up to date with all the depricated pieces too, and rip them out as needed. You will end up with more volumes in the set, but some of the books will have large chunks missing. What's not to like?

  119. here's the deal by Anonymous Coward · · Score: 0

    I find every criticism Torvalds points out about C++ is even more true about C.
    This is why I use Delphi.

  120. Re:C++ Downfalls, Compiler and Internationalizatio by Anonymous Coward · · Score: 0

    Compiling repeatability
    Part of Safety Critical Avionics is that the binary must be perfectly re-creatable. At any time if an issue comes up someone must be able to rebuild the configuration used for compiling (versions, software packages, patches, etc.) and get a perfect match to the released binary, bit-for-bit perfect. Somehow most C++ compilers and libraries are unable to achieve this, using the same exact machine (no patches or changes) and compiling at a different time gives a different result. This has been demonstrated on several different compilers, using nothing other than standard libraries.

    That is weird, we check some binaries into svn, there are exactly 3 out of twenty that change every commit since they contain the SVN revision number every other binary only changes when we actually modify some code.

  121. Compile times by Anonymous Coward · · Score: 0

    Compiling C++ is so much slower for such a large codebase. The savings from the compile time are already a strong enough argument.

  122. Re:Aren't all (but one) popular languages like thi by Half-pint+HAL · · Score: 1

    The thing is, there's a whole spectrum that you're dismissing with "reinventing the wheel". Sometimes you're not actually "reinventing", just building an appropriatel sized one for the task at hand, rather that grafting on an oversized wheel with unneccesary chrome alloy rims etc, just because it's already there. The line between these things is fuzzy, and people often get it wrong, but no system will ever be fool-proof.

    --
    Got them moderator blues I blieve I walk out the do', With these mod-points I been gettin', I 'most never post no mo'
  123. Methodology, not language by LostMyBeaver · · Score: 1

    A long time ago,I read a book about object oriented programming in x86 assembler. In fact, if I needed to code assembler today, I would use those methods.

    I code in C# these days because I'm too old to spend 2 years writing pretty C or C++ code to do what I can don in a month with a modern language and library.

    I code very similar in C, C++ Assembler and C#. I use the same algorithms and patterns. I just write much cleaner code much faster.

    I have little respect for people who talk about optimization and don't employ garbage collection to run structured cleanup during idle cycles.

  124. Not horrible by jandersen · · Score: 1

    Was Linus going overboard?

    Of course he was - much as I respect him for his eminent work, he is a primadonna, and he likes to be controversial.

    I suppose it will always be a matter of taste, what you think of a particular language. Personally, I like C++ a lot. The great strength of the language is that it allows you to express similar constructs in a similar way - take the concept of the iterator: it basically allows you to loop over any set of objects with a simple for() loop, by hiding away all the house keeping that goes into finding the initial object, getting to the next one and determing the end conditions. This means that you as a programmer are able to show the essential loop to whoever comes to read your code, instead of drowning them in details. Of course, it also means that there are more things to understand - C++ is a demanding language.

    I think what makes C++ code horrible isn't the language as much as the programmers, who don't quite understand the purpose of the powerful features and who insist on applying every damn thing in every program. Just because you can make complex class hierarchies with templates, multiple inheritance and overloading, it doesn't mean you have to do it all the time; a god programmer will always strive to write code that is easy to understand - if using advanced, object features help you do that, then it is right to do so, but very often more basic code will do the job.

    Well written C++ makes it easier to spot the way the program works; but you can't write well in any language unless you are a master of the language. It is in many ways unfortunate that it is called C++ because it makes you think that it is 'C and a bit'; but C is an extremely simpe language compared to C++, and if you come to C++ thinking that your good understanding of C means that you are obviously going to understand C++ just like that, then it is hardly a surprise that you end up writing horrible, showy code.

  125. Did I mention ... by ozzee · · Score: 1

    ... that I can write bad code in any language?

  126. This has me second-guessing my C++ ambitions ... by Qbertino · · Score: 1

    Never had heard of the Linus Torwalds rant on C++, but reading it has me second-guessing my C++ ambitions. Linus has strong opinions, no doubt, and he doesn't tiptoe around the issue, but more than once have I found myself agreeing with him and also seeing why I would call other people names - because often quite widespread ideas and notions about programming are notably stupid, and Linus doesn't stop short of pointing those out.

    What he has to say about C++ actually makes me weary about the PL. ... Gotta look into this.

    --
    We suffer more in our imagination than in reality. - Seneca
  127. Re:Aren't all (but one) popular languages like thi by sproketboy · · Score: 1

    >> I can't think of any mainstream language except for C that doesn't suffer from the "dialect" problem to some extent.

    Java because it doesn't have a pre-processor - which is a very good thing. People may style the language differently but everything is still just Java. I can't redefine the language semantics like C.

    Look at Objective C. It's just an API with a bunch of pre-processor directives to make the language look different. I can't think of another language except C++ which has such a severe "dialect" problem as C.

  128. Linus is a grumpy old dude! by Anonymous Coward · · Score: 0

    Linus is just a backwards and sttuborn dude that cannot grasp the factual superiority of C++ over other languages.

    He is just an arrogant guy that for already a considerable amount of time is backwards and outdated!

    I work developing high performance embedded operating systems, and we use C++ because we can do much better code, both on maintenance point of view and mainly better performance than C.

  129. Re:Aren't all (but one) popular languages like thi by Wootery · · Score: 3, Funny

    Vala is surely the most ironic language yet.

    GObject: because we don't want to use a whole new programming language just to add objects to C.

    Vala: because GObject is better approached using a whole new programming language.

  130. Re: Aren't all (but one) popular languages like th by steven.db.clark · · Score: 1

    People reinventing the wheel always say their approach is more efficient. They forget that all the extra features they don't use (or don't understand) are just left out at compile time. So what they do is just add code bloat.

  131. 10 years late to the party by loufoque · · Score: 1

    The rant from Linus is famous and old. I don't understand why people are still discovering it today and why they feel the need to discuss it.
    Linus doesn't like C++ as a systems programming language. He doesn't want any in his project. He never claimed that C++ was bad for everything, he just thinks it's bad for what he does (some people agree, some don't).

    And he pretty much hates most other programming languages much more than he hates C++. He thinks that Java is horrible for everything for example.

  132. UPVOTE PARENT by wed128 · · Score: 1

    Wish i could upvote this, but I already commented. It describes exactly my feelings about lisp.

  133. Re:C++ Downfalls, Compiler and Internationalizatio by loufoque · · Score: 1

    Point 2 pretty much means you just want a simple abstraction on top of assembly, and for that you need simple and stupid code with a minimalistic language.
    It's the only good point that you've made as to why you couldn't use C++ to match your requirements.

  134. Cython by Chozabu · · Score: 1

    Cython seems to connected these rather well.

  135. C is just lean and C++ is Multi-Paradigm by snake_case_hoschi · · Score: 2

    Linus is possibly right with one thing:

    > It's made more horrible by the fact that a lot of substandard programmers use it

    C is simple and lean. Doing complicated stuff which is not required is not easy and prevents system-level software messed up with unrequired abstraction layers and patterns, which you can ususally find in the typicall Java-Software. Because Java make it especially easy and popular to use abstractions and patterns by so called "Software Architects". Spring with Inversion-of-Control and Aspect-Orientiered-Programming (non-readable source-code!) and Hibernate make especially reading source-code a big pain (it not longer readable source, it's a lot of spaghetti XML and annotations with weird bugs).

    > In other words, the only way to do good, efficient, and system-level and
    > portable C++ ends up to limit yourself to all the things that are
    > basically available in C.

    C++ is a Multi-Paradigm, one of this paradigms is low-level/system-level programing with simple C-Like code.
    The offers a how lot of new features which make programming on high-level easier, faster and safer like RIAA and Smart-Pointers, Templates and STL-Containers, modern I/O-Stream and Strings and finally OOP.

    Personally I tend to say, that OOP is an important part of C++, but the biggest achivement so far are Templates* and the STL. They allow both creation of big software projects. If done right, this big software is not complex software.

    * Java doesn't offer the convenience of Templates, basically because Generics are just Autoboxing for Safety but nothing more.

  136. Re: Aren't all (but one) popular languages like th by Half-pint+HAL · · Score: 1

    People reinventing the wheel always say their approach is more efficient. They forget that all the extra features they don't use (or don't understand) are just left out at compile time. So what they do is just add code bloat.

    The problem with relying on compiler optimisations is that the compiler rarely knows the valid or most likely forms of input. This is why anyone concerned with performance will explicitly specify quicksort/bubblesort/whatever rather than just calling "sort" and letting the compiler choose.

    I agree that some people take this too far, and basically "micromanage" their code, but then people also go too far the other way at times.

    --
    Got them moderator blues I blieve I walk out the do', With these mod-points I been gettin', I 'most never post no mo'
  137. Be generic, be obvious by gatkinso · · Score: 1

    Follow those two rules and (usually) the code will turn out ok.

    --
    I am very small, utmostly microscopic.
  138. Re: Aren't all (but one) popular languages like th by serviscope_minor · · Score: 1

    No, anyone concerned with performance will write the code first, profile and then optimize. Given a more expressive language you can get to the correct-but-needs-optimization much faster and therefore spend more time on optimization.

    --
    SJW n. One who posts facts.
  139. No one's even mentioned C++'s biggest problem by Anonymous Coward · · Score: 0

    The biggest problem in C++ is they won't add anything new. They keep overloading what's already there, usually punctuation marks. The lambda syntax is terrible, for example, overloading the [ ] operator. Each time something new is added to C++, the same keywords and punctuation get more overloaded. The result is a mess. If you're going to add new stuff, add new keywords. Add new syntax. Make it look new. If it breaks something, then it's new, it's supposed to. The alternative is the mess you have now.

  140. Re:Another troll-FP? *Excellent*! by Anonymous Coward · · Score: 0

    / Grabs popcorn

    // Dons asbestos armor

    /// Swallows prednisone to partially alleviate the symptoms of terminal asbestosis.

  141. Re: Aren't all (but one) popular languages like th by Half-pint+HAL · · Score: 1

    Not Always Necessary. Sometimes you know from the very beginning that your list will be mostly ordered, and you choose your sorting and searching algorithms accordingly. In some cases it really is pretty trivial. In general, though, I do agree with the principle of "optimise late". We just have to remember that there are no absolutes.

    --
    Got them moderator blues I blieve I walk out the do', With these mod-points I been gettin', I 'most never post no mo'
  142. Re:C++ Downfalls, Compiler and Internationalizatio by Yunzil · · Score: 1

    This has been demonstrated on several different compilers, using nothing other than standard libraries.

    [citation needed]

  143. Re:Python/Fortran Combo by goombah99 · · Score: 1

    google f2py and you will find lots of tutorials. but it not complicated and after you customize the paths and options for your particular compiler then compiling from within python takes just a couple lines, and then you import the result.

    almost any compiler can work in principle. I used open source compilers because 1) I wanted to be able to share my work 2) numpy and scipy come distributed that way. but I know from the mail lists people used commerical compilers as well such as compaq visual fortran. I did once use a commercially curated distribution called enthought. Since I didn't want to have to maintain two compliers I made the choice to use the one I used to compile scipy or numpy, which is almost any, but on your specific computer you have probably installed numpy in either binary or source form using some package manager, or if its a mac the one that came with the computer. f2py is in most package managers. By using the package manager route this also simplified getting the paths to libraries set up correctly as well-- but that's just a general property of package managers not specific to f2py.

    I've done this now using different package managers and different compilers and the only problems I've had were in the package managers themselves when dependencies got broken, but again that's the packagemanager woe no specific to f2py.

    You can do all the sorcery right from scipy itself. since scipy and numpy can use fortran order arrays, you can pass things in and out directly without thinking about them as objects. they just show up as fortran arrays.

    --
    Some drink at the fountain of knowledge. Others just gargle.
  144. Re:C++ Downfalls, Compiler and Internationalizatio by chaim79 · · Score: 1

    As stated, these are the reasons others at my company have given me for why they don't use it. I don't have the direct experience to challenge this, nor do I have the authority to make a decision to use C++ on a project, I'm brought in after those decisions are made and the work is started.

    I would actually love to learn more about the language and use it, especially if it actually has application to the Avionics world.

    --
    DEMETRIUS: Villain, what hast thou done?
    AARON: Villain, I have done thy mother.
    Shakespeare invents 'your mom'
  145. Divide it into separate languages by fredrickleo · · Score: 1

    I've recently started to think that C++ should be broken into subsets of syntax and features that are enforced by the compiler rather than just coding standards and process.

    --
    Yay me! ^^
  146. pthreads vs. std::thread by Anonymous Coward · · Score: 0

    I thought that someone should point out that std:thread is part of the standard C++ 11 library but pthread_create is not part of the standard C library.

    std::thread is portable code, pthread_create is not.

  147. Re: Aren't all (but one) popular languages like th by Anonymous+Brave+Guy · · Score: 1

    No, anyone concerned with performance will write the code first, profile and then optimize.

    Absolutely. That's why any good C++ programmer writes

    void some_function(big_class data)

    first, and only uses

    void some_function(const big_class & data)

    after profiling confirms that their code is as slow as everyone knew it would be.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  148. Re:C++ Downfalls, Compiler and Internationalizatio by X · · Score: 1

    Regarding repeatability: the language is fully deterministic, and compilers have as much of an incentive to be consistent as they do otherwise. If you can't get repeatable builds, then the problem is with your build environment/process more than anything else. Aside from hardware entropy sources, computers are, by design, deterministic, so if you can't reproduce a build it is because you haven't constructed a proper build closure. Certainly there is nothing about C++ that makes builds any more non-deterministic than say, C. Debian actually has a project for this: https://wiki.debian.org/Reprod..., and you may find some helpful information there. You'll notice nothing they've run in to is specific to C++.

    Regarding code-to-binary structural coverage analysis. Certainly I can imagine the argument that as you get to higher and higher levels of abstraction, it becomes harder for humans to track all the transformations all the way through to assembly. One solution is to restrict the levels of abstraction you work with. I would argue that is still error prone and you are better off with using theorem prover type automated solutions (and in general, languages built around provability like ML or Coq) rather than manual verification. Even better would be to perform the verification on the compiler itself rather than the code it compiles. That said, C++ compilers do a pretty good job of tracking the origin of each bit of code they generate, which ought to make it easy to have the machine inform you of the origin of any particular code block, and C++ also does a great job of letting the programmer decide what level of abstraction they want to work with and only making the runtime pay for the abstractions they are using. Its stronger type safety also helps ensure that there aren't "hidden" code paths do to programmer error. Of course, optimizers really complicate this, so you may need to turn them off as you mentioned.

    Internationalization. That sounds like an old project... one that predates the C++ standard (which means a lot of bad C habits are involved). C++ is actually very well set up for internationalization, particularly because it is so agnostic about how stings are handled. Languages like Python, Perl & surprisingly Ruby have made all kinds of unfortunate decisions around internationalization that make it look like you are fine with internationalization, but it actually blows up in your face. As an example, ICU is probably one of the foremost libraries out there, and its primary language targets are C++ & Java. The C++ target has the virtue that you can pretty much just drop in ICU strings in to a well structured C++ program and all is well in the world, where as the Java one is a bit of a pain to take advantage of (fortunately, Oracle periodically syncs the ICU code in with the JDK, but that means you have to wait for a JDK update to get the latest ICU solution).

    --
    sigs are a waste of space
  149. Re:C++ Downfalls, Compiler and Internationalizatio by X · · Score: 1

    Perhaps not the best example of a successful software project. ;-)

    --
    sigs are a waste of space
  150. Re:This has me second-guessing my C++ ambitions .. by Anonymous Coward · · Score: 1

    Don't listen to him. With all due respect for Torvalds accomplishments, he's not always right. Half the people here bashing C++ don't know the language. C++ right now is irreplaceable for its strength to provide C level performance with high level language structs, and better yet, directly compatible with C so you can use the mass of C libraries without jumping hoops. For people who bash operator overloading, try to write matrix and vector computation without it, it's painful. And those who avoid STL miss out big time. STL though syntactically not pretty, is very mature and rock solid high performance generic container. As a programmer who has mainly been using C++ for 15 years, I will say it's not a pretty language and easy to shoot yourself in the foot. But it provides a wealth of language features that allow you to do pretty much anything. I do hope something nicer comes along to replace C++ while preserving its strength, but so far none is on the horizon.

  151. A hammer is a weapon in the hands of a toddler. by duck_rifted · · Score: 1

    Both perspective are right, and the usefulness of C++ increases with experience. Look at your old code. Does it make you cringe? If not, then Linus' quote applies to you.

  152. 10x Logic Lapse by pfg23 · · Score: 2

    We need to acknowledge the fact Linux Torvalz (tee-hee) is being utterly illogical (odd for a 10x programmer) when he utters that a language is bad because there are so many bad programmers using it. There are bad programmers in any language. If there's a preponderance of bad programmers using C++, it's not because the language is bad, but because it has been so popular (and powerful) for so long.

  153. Re: C++ = all the performance of assembly language by Anonymous Coward · · Score: 0

    LOLOLOL i hope you are joking and trolling. if not, wow.

  154. Re:C++ Downfalls, Compiler and Internationalizatio by david_thornley · · Score: 1

    Compiling repeatability: this complaint is news to me. I'd like to see something I can check.

    Code-to-binary coverage: this is an excellent reason not to use C++, and to be careful in how you use C.

    Internationalization: I haven't noticed it being harder in C++ than in other languages. It's a pain no matter what language is used, and it can be made worse by programming decisions made early on. Fortunately, all the internationalization projects I've been on were of small programs. I'd be interested in learning why it would be harder in C++ than in C, for example.

    In short, C++ is not for every use, and your is one it isn't suited for.

    --
    "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  155. Objective C is the way by aglider · · Score: 1

    C++ fails in separating interface and implementation. Then you need to exactly know the interfaces by including the header. So you lock yourself to it. Objective C solves this with messages.

    --
    Sent as ripples into the electromagnetic field. No single photon has been harmed in the process.
  156. Re:C++ Downfalls, Compiler and Internationalizatio by shutdown+-p+now · · Score: 1

    Somehow most C++ compilers and libraries are unable to achieve this, using the same exact machine (no patches or changes) and compiling at a different time gives a different result. This has been demonstrated on several different compilers, using nothing other than standard libraries.

    That's because some compilers (I know VC++ does that, probably others, too) embed a timestamp in the image. Nothing else actually changes, and the timestamp is not used by the image itself.

    This does break some other binary verification scenarios, so, IIRC, there was a compiler switch added at some point that prevents this and allow bit-identical output given bit-identical input.

  157. Re:Ugh by david_thornley · · Score: 1

    You can so stupid things in any language if you like.

    In Common Lisp, it's common to use code generation using Lisp macros (much more similar to C++ templates than the C/C++ preprocessor). It's elegant, powerful, and I've never seen it considered overengineering.

    --
    "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  158. Re:C++ Downfalls, Compiler and Internationalizatio by friesofdoom · · Score: 1

    Compiling repeatability - Are you sure? I have not checked recently, but last time I did, this was no the case

    Code-to-binary and structural coverage analysis - If you don't like STL and Boost, don't use them (I don't) and instead, roll your own. BUT, what standard libraries does C provide if you don't want to roll your own? None? Really? Wow, so you HAVE to roll your own? Using macros instead of templates? LOL, how is the STL in C++ a bad thing when compared to NOTHING in C ??

    Internationalization - C++ is not the problem... "X11 and Motif to QT" That's the problem. "updating it to go from hard-coded English to strings" that's the problem. Starting with what sounds like a crappy code base, that's the problem. This would be akin to converting a Winforms application to WPF, in other words, practically impossible, you might as well re-write it, or the front end at least. I'm actually in the process of converting an application from winforms to WPF, and I've not done anything other than re-write all the front end code from scratch so far.

  159. Re:C++ is fine for applications and frameworks by david_thornley · · Score: 1

    C++ is fine for kernel development. Some C++ features are seriously unsuited to kernel development. It's at least arguable that enough features of C++ are unsuitable that you may as well use C.

    --
    "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  160. Whatever happened to logic by Anonymous Coward · · Score: 0

    Sub-title: Is Linus really a programmer

    Illogical statement: "C++ is a horrible language," he wrote, for starters. "It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it.""

    Unnatural extension of logic: "Automobiles are a horrible invention," he wrote, for starters. "It's made more horrible by the fact that a lot of substandard drivers use them, to the point where it's much much safer to stay off the road and just park them."

    Or, my favorite: "English is a horrible language," he wrote, for starters. "It's made more horrible by the fact that a lot of substandard humans use it, to the point where it's much much easier to generate total and utter crap with it."

  161. Alex Stephanov also hates C++ code by Anonymous Coward · · Score: 0

    Listen to Alex Stephanov talks (=the original author of STL) He mentions on several occasions that he pulls his hair off when he sees how people use STL.

  162. So many features, so little time by tjbutt58 · · Score: 1

    From a C background, I still struggle to understand modern C++ code, in part because the complexity level of the code is not being added to, but multiplied. Templates (for instance) took something I could generally understand, and multiplied the complexity. Keywords relating to templates and generic programming seem to get added every iteration, and most recently we seem to have lambda functions (why?). As a oprevious poster said, there are now many ways to solve a particular problem in C++. While that is true in most languages, the intent of most programmers is generally directly visible from scanning the code, and (I hope) comments. Not always so with C++. I still like the language, but it seems to be going the way of PL/1 - too many features. It's always possible to add a feature to a language, very hard to remove it.

  163. Re: Ugh by Pieroxy · · Score: 1

    You don't have to but other people might. And when it's your turn to maintain their code, then, oh shit... But it shouldn't since it's C++, you're supposed to be fluent with it.

  164. C++ is an excellent language by spkay31 · · Score: 1

    Just that it's the wrong language for most modern programming tasks. Virtualized runtime environments w/ dynamic garbage collection and scores of other great features like Java, .NET, Python, Ruby make C++ totally obsolete for *most* programming tasks. Still there are many areas where C++ is the right tool such as drivers, os internals, network development, debugging tools, etc. Saying that languages that execute in a virtual runtime environment are much better is like saying that C++ is a much better language than ASM86 or IBM 360 BAL.

  165. I admire C++ devs by cerkit · · Score: 1

    I admire C++ developers for what they can do. I am a C# developer and I've started to learn C++ a few times over the past 15 years. Every time I try to learn C++, I just decide that there's nothing that I can use it for in my daily job (I'm a web developer), so the effort to learn it correctly is too great for the return I'd get from learning it. Sure, I could hack my way through it, but something tells me it's a language that needs to be written elegantly or it could wind up being a mess. I learned C in school, but I've never used it on the job. I'm glad there are people out there that have the chops to code in C++, even if they are creating some messes. I still can't get my head around the more advanced memory management topics, so I take the lazy man's approach and depend on the garbage collector and the IDisposable interface.

    --
    Michael Earls http://cerkit.com/
  166. C++ def. was a very bad language by YoungManKlaus · · Score: 1

    Consider that in 2007, neither C++1 nor C++14 were out.

  167. Old News by Anonymous Coward · · Score: 0

    Cool lets look for more articles from 2007 and post them as new stories......

  168. It's all in the context. by Anonymous Coward · · Score: 0

    Both languages have their place. If your primary job is system level programming - C makes a great deal more sense. If you are doing applications then C++ might be a better trade off.

  169. Thre is one by Anonymous Coward · · Score: 0

    There is one DO-178B C++ compiler for safety critical avionics. The Greenhills C++ compiler is certified. That is also why there is a JSF C++ coding standard. There are many parts of the language that would produce non compliant code if you were to use those features. I don't know anything about internationalization, but I wholeheartedly agree with the optimizer settings. When you have to inspect assembler optimizers are just cruel and inhumane. And that is when they are working. I once had a DO-178B compiler (not c++) optimize out a statement with side effects, that took me a while to spot.

  170. Re:Aren't all (but one) popular languages like thi by Anonymous Coward · · Score: 0

    This isn't a problem with C, it's a problem with your developers and review process. I maintain dozens of interconnected C applications, libraries, and SQL code for a popular line of consumer electronics products (15 million installations)... Our code does have some sticky points, but that's due more to a few bone-headed developers than language. Either way it's far from the disaster you describe.

  171. Re:Aren't all (but one) popular languages like thi by Anonymous Coward · · Score: 0

    All systems are fool-proof if you get to define what a fool is :-)

  172. Re: Aren't all (but one) popular languages like th by serviscope_minor · · Score: 1

    Well played :D

    Actually, back before move semantics, I had a function along the lines of:

    void foo(blah, vector& return_value);

    It was being called repeatedly, hundreds of times a second. On a whim during optimizing, I made the return value a proper return value. It increased the runtime by about 0.1%, so I left the "slow" version in since it looked better.

    But yes, you're right, no simple saying ever covers a complex world.

    For example if you know code needs to be fast, you better pick an architecture up front which is optimizable, otherwise you know 100% you're going to be screwed later on.

    --
    SJW n. One who posts facts.
  173. Not understanding by Anonymous Coward · · Score: 0

    The ABI *to the kernel* is not standard. That isn't what the thread is talking about, it's talking about the ABI standard when coding TO THE COMPILER. IOW, do you have to have a lot of conditional compiles or even different libraries and calls to solve the same problem? If you do, you don't have a kernel that can be compiled on multiple platforms, you have multiple kernels.

    Think of a game using DX vs a game using OGL. The code won't be the same for almost all of the graphics calls. That would not be the same program.

    Think of a game using Windows 7 with DX10 or with DX11. They would be the same program.

    I realise this would not let you complain about Linux, because you've heard people complain that they can't release binary drivers for Linux because the "ABI is not stable", but have understood nothing about it, and therefore have misapplied it just so you can whine.

    Sorry.

  174. c++ sucky sucky.. by Anonymous Coward · · Score: 0

    as an old k&R type strousup and c++ sucky,sucky!!

  175. Formal education in C++ by lems1 · · Score: 1

    As someone who was taught C++ as a way to introduce one to programming in college, I have to agree.
    Later, many years later in fact, when I discovered C, I was a much happier person. Everything is so much simpler in C starting with the syntax and ending with compiler optimization and debugging.
    By comparison, one could say the same about using ECMA^Wjavascript versus CoffeeScript. JavaScript has many features most of which are good, however the syntax gets in the way. CoffeeScript "fixes" that by making code simpler without sacrificing on features.

    --
    This sig can be distributed under the LGPL license
  176. Re:C++ Downfalls, Compiler and Internationalizatio by Chrisq · · Score: 1

    As a matter of interest, what do you use?

  177. Re:C++ Downfalls, Compiler and Internationalizatio by chaim79 · · Score: 1

    C and ADA are the two languages I've run into for actual safety-critical projects

    For Non-safety-critical, non-flying software, mostly C.

    For testing environments (runs tests on the software/hardware and collects the results) C# and Python seem to be the popular choices. However very few of them have been "Tool Qualified" (i.e. proven to be 100% accurate in their assessment of if a test passed or failed), mostly out of laziness and managers being scared of the toolqual process.

    --
    DEMETRIUS: Villain, what hast thou done?
    AARON: Villain, I have done thy mother.
    Shakespeare invents 'your mom'
  178. reverso-perception by FalseModesty · · Score: 1

    No, that's when Emacs WON that argument. Emacs is what you want, no matter what you want or how often you change your mind.

    Vi is only what you want if you want vi.