Slashdot Mirror


Knowing C++ Beyond a Beginner Level

Nerval's Lobster writes: C++ is not an easy language to master, but many people are able to work in it just fine without being a 'guru' or anything along those lines. That being said, what separates C++ beginners from those with 'intermediate' skills, or even masters? According to this Dice article, it comes down to knowledge of several things, including copy constructors, virtual functions, how to handle memory leaks, the intricacies of casting, Lambda functions for C++11, (safe) exception handling and much more. All that being said, is there one particular thing or point that separates learners from masters?

345 comments

  1. Knowing when not to by perpenso · · Score: 5, Insightful

    What separates C++ beginners from those with 'intermediate' skills, or even masters?

    Knowing when not to use templates, virtualization, [insert favorite c++ function here], etc.

    Basically knowing enough about programming and problem solving with a particular language to tell a need from a want. Needing to use some language feature vs wanting to use some language feature. And being mature enough to stick to needs rather than indulge wants.

    Or to state things differently ... all the features have a time and place, and its probably not all the time and in every place.

    1. Re:Knowing when not to by Ihlosi · · Score: 2
      Knowing when not to use templates, virtualization, [insert favorite c++ function here], etc.

      Basically, only use a language feature if it provides a tangible benefit (making the code easier to understand and maintain almost always qualifies; making the code run faster qualifies if it's not running fast enough yet; "This is cool, let's try using it!" only ever qualifies in your own private projects).

    2. Re:Knowing when not to by PolygamousRanchKid+ · · Score: 4, Insightful

      I agree with your comment entirely. I would only like to add that a true C++ Master writes code that a C++ Novice can understand.

      Time to get philosophical. Tomorrow, you could get run over by a bus. Take a wander around your Cubical Town. Are there enough folks there who could take over ownership of your code?

      You can do some really cool things with C++. But if other folks cannot understand them, well it's best not to do it. Cool C++ features are like nuclear weapons: very powerful, but think about the consequences of using them . . .

      --
      Schroedinger's Brexit: The UK is both in and out of the EU at the same time!
    3. Re: Knowing when not to by Anonymous Coward · · Score: 0

      no need to cater for rookies. dumbing down things also destroys wages.

    4. Re:Knowing when not to by AmiMoJo · · Score: 2, Insightful

      These days it's questionable if any large projects that use those kinds of features extensively should even be started in C++. There are better languages for such things.

      C has applications in OS, low level and embedded development. C#, Java, Objective-C and many other languages are better for applications. Somewhere in the middle you have C++, which is okay in moderation but wouldn't be your first choice for anything new.

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
    5. Re:Knowing when not to by eulernet · · Score: 4, Insightful

      You are thinking like a manager.
      As a programmer, I don't want to be replaced easily, and I don't care about my work when I'll die, or even when I quit my company.
      I have no problem to share my knowledge with my co-workers, but why should I write code for somebody who'll replace me ?

      Also, unless you write frameworks, I doubt very much that your code will be reused.
      It will probably be rewritten.

    6. Re:Knowing when not to by Rei · · Score: 1

      Quite true, with a caveat. Each feature in every language provides a balance of power to the developer versus a learning curve and potential gotchas. Different programmers will have different balance of opinions on where each feature lies on this spectrum. Each must decide in each case, "is this worth it to me for any potential difficulties I may encounter, and what about any others who work on this in the future?" (each alternative option will also bear such decision-making). There is rarely a single hard, fast rule to determine "use this, don't use that". Consequently I personally recommend to each coder that as they learn of a new feature, they try it out (in a personal project or little task, not some big critical system) and see what role it has on the development process and the maintainability of the code. Some may be overwhelmingly positive. Others may turn out to be overwhelmingly negative. Only experience with the feature can help one determine that.

      In my case, I've had good enough experiences with most C++ features that unless I know that a project is also going to be worked on by people who are C++-phobes, I find that they're well worth using. But even in my case I've come across features that I wouldn't even use in personal projects. For example, once several years back I tried out std::transform extensively in a hobby program I was writing - by the end I was convinced that, at least in the sort of use cases I was encountering, it only serves to complicate code, increase development time and decrease legibility. I went back in and modified all of the code to use "for (auto i : list)" loops, and contrarily was very pleased with the result - it led to something that even a C++ novice could understand while simultaneously reducing code size and improving code clarity. So guess which I avoid today and which I use extensively? ;)

      But there are no hard, fast rules, and reasonable coders will of course differ.

      --
      What about the Ant People? They owe us money.
    7. Re: Knowing when not to by Anonymous Coward · · Score: 5, Insightful

      but why should I write code for somebody who'll replace me ?

      Because future you will replace present you. If you need to revisit code years later to fix a bug or add a feature, you want to be able to pick it up straight away, rather than try to figure out the mess you left behind.

    8. Re:Knowing when not to by hsa · · Score: 1

      Just make sure, you know how to use the advanced features, should the need arise.

      I mean, I know a guy, who teaches physics and basic programming in a public school.  He thinks he writes great C++ code. He doesn't use  templates, virtualization, [insert favorite c++ function here] . He doesn't even use use classes. He just uses a C++ compiler to compile his code. Total coding mastermind, if we look at the things he does not do..

    9. Re: Knowing when not to by Anonymous Coward · · Score: 0

      Unless you're in HPC or game development, where managed runtimes just aren't suitable a lot of the time.

    10. Re:Knowing when not to by TheRaven64 · · Score: 4, Insightful

      making the code run faster qualifies if it's not running fast enough yet

      And then only if backed up by realistic macrobenchmarks. There are a lot of things in C++ that have interesting performance characteristics (templates allow more inlining, so make microbenchmarks faster but can cause you to run out of i-cache and make the whole program slower, virtual functions prevent inlining unless the compiler can do devirtualisation, but are actually slightly faster to call than cross-library calls via a PLT if they're not inlined). Generally, algorithmic improvements will make a bigger difference than any language feature. The main reason for using templates should be to eliminate copy-and-paste coding, not to improve performance.

      --
      I am TheRaven on Soylent News
    11. Re:Knowing when not to by TheRaven64 · · Score: 4, Interesting

      If you can't be replaced, then you can't be promoted. Do you really want to be maintaining the same program for the rest of your life? And do you want to have a reference that says 'no one can understand this guy's code' when you leave for the next job?

      --
      I am TheRaven on Soylent News
    12. Re:Knowing when not to by 91degrees · · Score: 2

      As a programmer, I don't want to be replaced easily, and I don't care about my work when I'll die, or even when I quit my company.

      As a programmer, I make sure I remain employable by doing the best job I can do. Partly this is about basic ethics, but I know that even if I write ideal code, with perfect documentation, I'm still the best person to understand that. I don't want to work for any company I work for that doesn't realise this.

    13. Re:Knowing when not to by serviscope_minor · · Score: 4, Insightful

      This is complete and utter tosh.

      No one I know who does high performance code (such as numerics, real time computer vision, that sort of thing) uses anything but C++, especially for new projects. There is nothing out there that combines the speed and expressivity of C++, and when you know performance is going to be a factor at some point, C++ is the only choice.

      Frankly for a lot of scientific and numerics style coding, I often reach for C++ initially even when performance isn't required since it often maps on to those problem domains better than any other languages I've used.

      Oh and then there's the embedded world, where your choices are C and C++. Plenty of people use C++, since it like C scales all the way down to the 8 bitters like Atmel.

      --
      SJW n. One who posts facts.
    14. Re:Knowing when not to by Anonymous Coward · · Score: 0

      but are actually slightly faster to call than cross-library calls via a PLT if they're not inlined

      That depends a great deal on which C++ compiler you're using.

    15. Re:Knowing when not to by AmiMoJo · · Score: 0, Flamebait

      If you need really high performance you don't use most of the C++ features anyway, and end up basically writing straight C. In fact a lot of C++ code is like that, using OO to allocate memory and logically arrange the code.

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
    16. Re:Knowing when not to by serviscope_minor · · Score: 4, Insightful

      If you need really high performance you don't use most of the C++ features anyway, and end up basically writing straight C.

      Nope nope nope nope nope nope nope nope nope.

      That is far, far, far away from correct.

      Check out something like Eigen or TooN (a somewhat more obscure library which is used in the vision world for things like PTAM). They are very far from C++. The code written down in an editor reads more like maths. There's no explict loops, no explicit memory allocation. They're both high performance libraries used in challenging applications (seriously download and run PTAM, it's amazing).

      They're also fully templated so you can stick in an AD type instead of a normal number and get derivatives out automatically with no extra effort.

      Writing high performance C++ is nothing like writing high performance C. It's much better. All the messy C details of allocation and etc simply vanish, leaving clean, nice looking code which is straightforward to read, write and debug.

      Or another example from today for me. I need to find the best N (lowest cost) elements during some wort of complex search. It's easy. Just create a priority_queue<pair<double, int>> where the double is the cost and the int is the index of the object.

      Then about 3 lines of logic keeps the pqueue updated with the best N so far.

      All the irrelevant logic of how a queue works is witten and debugged by someone else and hidden from me without ever losing either performance or type safety. For bonus points, if I find I'm searching very small things and memory allocation becomes a penalty, I can switch the entire thing to stack allocation with almost no effort at all!

      --
      SJW n. One who posts facts.
    17. Re:Knowing when not to by Anonymous Coward · · Score: 0

      IOW, knowing when not to use C++. For example, if someone asks you. Choose emacs. Hell, choose vi. Whatever you do, don't start a project with a high level language you know nothing about.
      Unless it's java, pretty much everyone can regurgitate a couple of thousand lines of java before break time. Let quality control sort it out.

    18. Re:Knowing when not to by eulernet · · Score: 4, Insightful

      If you can't be replaced, then you can't be promoted.

      It depends on the kind of promotion.
      Not everybody dreams to become a project manager.

      Do you really want to be maintaining the same program for the rest of your life?

      Not really, but if the pay is good and the job is nice, why not ?
      Personally, I have a life outside of my work, so I don't really mind.

      And do you want to have a reference that says 'no one can understand this guy's code' when you leave for the next job?

      That's the least of my worries !
      Do you think that the guy who will take your place won't hate you, even if your code is beautiful ?
      Do you believe that your company will not fire you if there are problems ?
      If the company doesn't care about me, why should I be faithful ?

      Finally, I have a personal question: why do you work ?
      Is it to receive aknowledgment, money, fame, self-esteem, or something else ?

    19. Re:Knowing when not to by rioki · · Score: 1

      I commonly formulate it in the opposite. A master of C++ knows when to use the simpler function. For example, is it more sensible to use 2 overloads than a template, when is a free function a better idea than methods or functor, when is a struct (a real struct w/o methods) a better idea than a fully fledged class. The point is that you should not use the most powerful tool for the job, but the weakest that will get the job done.

      Novice programmers write code they don't understand, advanced programmers write code they understand and master programmers write code even the novice understands. (I don't know where this quote comes from.)

    20. Re:Knowing when not to by eulernet · · Score: 1

      While I agree with your point of view, but I will give you an example where it fails.

      Let's suppose that the program you are working on leads to the death of a person.
      After analysis, you discover that the bug is due to your carelessness ("it happens").
      Your self-esteem of "I'm doing the best job I can do" is shattered.
      Will you hide the fact that the bug comes from your incompetence ?
      Or will you take responsibility, even though you'll probably be fired ?

    21. Re: Knowing when not to by eulernet · · Score: 3, Insightful

      I have 30 years of coding experience.
      Even though I believe I'm quite a good coder, when I read code from 5 years ago, I'm always surprised to realize that I can do better and simpler.

      Whatever the state of your code is today, it will be a mess in a few years.

    22. Re:Knowing when not to by 91degrees · · Score: 1

      I'm not quite sure how a glitch in an online music app might kill someone.

      If my software kills someone I will be so distraught that I will confess immediately, and cooperate fully with any enquiry. Although I can't see anyone hiring me to work on safety critical systems.

    23. Re: Knowing when not to by O('_')O_Bush · · Score: 1

      Also depends on the company. Not all companies only have one product. For me, a promotion would mean working on a very different project. If I can't hand off my work, I can't be promoted.

      --
      while(1) attack(People.Sandy);
    24. Re: Knowing when not to by Anonymous Coward · · Score: 1

      Engineering should be simple. Only arrogant a-holes write functions that are difficult to maintain. When the a-hole comes back to their overly stupid complex obfuscated garbage 6 months later it takes them days to figure out their own mess.

    25. Re:Knowing when not to by Anonymous Coward · · Score: 0

      So someone doesn't have a budget to ask for proven software or to have multiple eyeballs look at the code they buy? The industry standards that let them get anywhere close to life-critical systems is criminally careless, not the guy who did their job of best effort to write correct code.

    26. Re:Knowing when not to by gbjbaanb · · Score: 1

      to be fair, the same applies to all languages - I recall the C# yield stuff someone wrote once (probably because it was cool, and even he couldn't understand what he had done sometime later).

      And then I think of my colleague who writes the simplest of C# code, but writes it in layers behind layers that its a maze.

      Language features do not necessarily make for confusion, like most things, its the way you do it that matters.

    27. Re:Knowing when not to by Anonymous Coward · · Score: 0

      I would only like to add that a true C++ Master writes code that a C++ Novice can understand.

      I disagree. A top C++ programmer writes code so that it can be easily read and modified by other proficient C++ programmers.

    28. Re: Knowing when not to by Anonymous Coward · · Score: 0

      I only have 10 years experience and while I also many times find I could have done better, I am finding more and more than I did "good enough". When I come back to code 2-3 years later and I can quickly look at it and understand it, job well done. Still room for improvement. Very rarely do I look at old code and marvel at its simplicity and flexibility, but I do have a few gems.

    29. Re:Knowing when not to by Anonymous Coward · · Score: 0

      Just to be clear, Eigen is great if you do not need much math. The Classic Fortran implementation (dsyevr from LAPACK) for calculating Eigen values is actually about 3x faster. Admittedly both Eigen and LAPACK do much more than this, but the C++ implementations found in Eigen generally underperform the LAPACK implementations even though the C++ Eigen implementations know the sizes of the vectors and matrices at compile time.

    30. Re: Knowing when not to by Anonymous Coward · · Score: 0

      I honestly could not give a flying proverbial what happens to my code when I leave, be it bus related or other. Really, really could not care less.

    31. Re:Knowing when not to by serviscope_minor · · Score: 1

      You are not 100% correct.

      LAPACK and BLAS outperform Eigen for large decompositions. For work like computer vision, you often have huge heaps of small, fixed sized matrices. In such cases, the overhead of function calls and blocking which makes LAPACK fast makes it much, much slower than naive algoithms. I'm not sure where the crossover point is, but it's somewere in the mid to high tens in size.

      Anyway, other C++ numerics libraries wrap BLAS and LAPACK for large sized objects.

      --
      SJW n. One who posts facts.
    32. Re: Knowing when not to by evenmoreconfused · · Score: 3, Interesting

      Even though I believe I'm quite a good coder, when I read code from 5 years ago, I'm always surprised to realize that I can do better and simpler.

      Whatever the state of your code is today, it will be a mess in a few years.

      Yes. I find this to be the case too (I was a programmer in the seventies and eighties, and have been in programming management ever since).

      So it begs the question "can one write code that one won't think is sub-optimal five years from now?". I've begun to suspect that one can't -- so just learn to accept it and move on.

      What I try to get programmers to do is write code that is A) clear and simple and B) balanced in terms of development vs. maintenance time. I don't want programmers wasting time perfecting code that's not going even be looked at for years to come, nor do I want code that takes days to get into when attempting small fixes.

      It's like building a house: if you follow the building standards, it's quick, safe, and any plumber or other trade can walk in later and quickly fix or modify things. If you do a bodge job it all has to be torn out and redone properly, or, if you create custom installations, it gets very expensive to create and especially to maintain.

      --
      No. Well...maybe. Actually, yes. It really just depends.
    33. Re:Knowing when not to by Drethon · · Score: 2

      If you can't be replaced, then you can't be promoted. Do you really want to be maintaining the same program for the rest of your life? And do you want to have a reference that says 'no one can understand this guy's code' when you leave for the next job?

      Or for people who don't care about being promoted above coder level... If you don't write good code that other people can work with, you will never be moved to new projects. If you want to live in maintenance mode that is one thing but personally I want my code to reflect my skills so I can work on bigger and better projects.

    34. Re:Knowing when not to by Anonymous Coward · · Score: 1

      . . . you can't be promoted . . .

      Have you been asleep for the past 20 years Rip Van Winkle?

      The only "promotion" you're ever going to get is by leaving the company you work for now for a different one.

    35. Re: Knowing when not to by Xenna · · Score: 2

      "Whatever the state of your code is today, it will be a mess in a few years."

      Funny, I just said that to a colleague tow hours ago. It's the fate of all software development.

    36. Re:Knowing when not to by Actually,+I+do+RTFA · · Score: 4, Insightful

      You are thinking like a manager...I don't care about my work when I'll die, or even when I quit my company.

      I'm both a programmer and a manager, so I can probably weigh in. I do care about what happens to your work when you leave the company. And part of my job is to make sure that your code is usable.

      why should I write code for somebody who'll replace me ?

      Because code is an asset that you are being paid to create. And if your code is not maintainable, it's not much of an asset; it's worth far less to me. So, if I notice our code is a fuck storm of uncommented overly complex verbiage, I'm not letting you work on anything important. So, maybe you get to work on small one-offs (really career enhancing), maybe I just fire you. But certainly I don't expect to allow you to keep extending your tentacles..

      The reason you say "most of your code will be rewritten" is because it sounds like your code is poor. Why would I pay asset-level prices for stuff with a shelf-life of a year?

      --
      Your ad here. Ask me how!
    37. Re:Knowing when not to by TheRaven64 · · Score: 1

      No it doesn't. It depends on the ABI and the CPU that you're using, but the compiler makes no difference at all.

      --
      I am TheRaven on Soylent News
    38. Re: Knowing when not to by gfxguy · · Score: 2

      I'm like that. I actually wouldn't mind rewriting most of the stuff I've written, but it all works and I can understand what things I wrote 10 years ago are supposed to be doing. But like the GP, even while I'm writing I often feel like I could have done it a better way - not the nitty gritty coding, but the approach I took to begin with. I think the overall sentiment is there's always room for improvement, even if the code is good and works, but you can't keep changing or you won't finish (and I rarely get a chance at version 2 where I work).

      --
      Stupid sexy Flanders.
    39. Re:Knowing when not to by Anonymous Coward · · Score: 0

      I want my code to reflect my skills so I can work on bigger and better projects.

      Wow, it sounds like your management is competent enough to identify skill levels and promote accordingly!?
      What's that like?

    40. Re:Knowing when not to by v(*_*)vvvv · · Score: 1

      ...and a good metric is if the feature simplifies the code you are writing or if it makes it more complex.

      The more orderly a system is, the smoother and more functional it will behave with fewer unintended consequences. The easier it will be to maintain, and the less time it will take to understand. Simplicity truly is the essence of all that is good in a computer.

      What is easily overlooked is that order requires effort to maintain. At zero effort, complexity is going to increase, and looking at any system (or code) it becomes obvious where effort is lacking just by its complexity.

      Another key intuition that is easily overlooked is that this principle holds true at every level, from user interface to technical performance optimizations to language features. At any given moment if we find what we are doing is complicated, we must question if it can be done simpler. Windows 8 failed at the interface level to simplify the experience. HTML and CSS failed at the language level for most of their early versions with browser incompatibilities and quirks.

      A programmer's main job beyond implementation is to simplify the implementation. And anyone not actively maintaining order is inevitably going to be part of the problem.

    41. Re:Knowing when not to by SkepticalEmpiricist · · Score: 1

      The most dangerous bit of C++ to use is ... ... the entire subset of C++ that is C!

      With C++11, if you avoid pointers, and do everything with value semantics (along with a little std::shared_ptr when necessary), then you have a very powerful and predictable and easy-to-teach language.

      Don't learn C first, before learning C++. If anything, it should be reversed. If I was expected to teach C to complete programming beginners, I would teach modern C++ first. There's a nice subset of C++ which allows you to get on with getting algorithms implemented, without having to give any thought to memory leaks or memory layout. And without the magical "action at a distance" you get with Java pointers.

    42. Re:Knowing when not to by Hussman32 · · Score: 1

      You wrote 95% of what I was thinking. The only thing I would add is the only time the OP's philosophy is acceptable is when he is writing his own code that he pays for with his time and resources.

      --
      "Who are you?" "No one of consequence." "I must know." "Get used to disappointment."
    43. Re:Knowing when not to by rock_climbing_guy · · Score: 1

      There's a time and a place for everything, and it's called "College" :-)

      --
      Wh47 d1d j00 541, 31337 15n't t3h r0xor5 ne m0r3???
    44. Re: Knowing when not to by Anonymous Coward · · Score: 0

      Why use C++ then? In C very little happens behind your back, especially compared to C++.

    45. Re:Knowing when not to by NostalgiaForInfinity · · Score: 1

      There is nothing out there that combines the speed and expressivity of C++, and when you know performance is going to be a factor at some point, C++ is the only choice.

      That's the wrong question to ask. What people in the real world need to ask is: given a team of average programmers and N man years, what choice will produce the best tradeoff between features, correctness, and performance in our application. Usually, if language is the only consideration, C++ is not the best choice. The choice of C++ is usually driven by availability of libraries and tools, backwards compatibility, and what existing teams already know.

      No one I know who does high performance code (such as numerics, real time computer vision, that sort of thing) uses anything but C++

      That's because you exist in a subculture that happens to use C++ a lot. Other subcultures use Fortran, Matlab, and Python a lot.

    46. Re:Knowing when not to by DRMShill · · Score: 1

      Keeping a grip on your work like that is a little like keeping your wife chained in the basement. It technically prevents her from leaving you but it doesn't lead to a high quality relationship.

    47. Re:Knowing when not to by Anonymous Coward · · Score: 0

      templates allow more inlining, so make microbenchmarks faster but can cause you to run out of i-cache and make the whole program slower.

      A big part of template inlining is to remove code that is not needed for an instantiation. Maybe some code only runs if two pointers are different, or for certain structure sizes or type traits, or to check if a number is out of bounds or whatever, and inlining allows the optimizer to figure out that in this spot the function gets called with the same pointer, that this type doesn't have the trait so it doesn't need the extra code or that the loop guarantees things are in range, so inlining might completely delete a call with all its code.

      But yes, profiling should be required before any optimization effort, but that's a general programming policy, not C++ specific.

    48. Re:Knowing when not to by Anonymous Coward · · Score: 0

      FYI, if you only need to get the best N at the end, it's more efficient to stick everything in a vector and use partial_sort to get the first N. Or nth_element if you don't even need them sortedbut just split into less than Nth and greater than or equal

    49. Re:Knowing when not to by Drethon · · Score: 1

      I want my code to reflect my skills so I can work on bigger and better projects.

      Wow, it sounds like your management is competent enough to identify skill levels and promote accordingly!? What's that like?

      Well that is more my want. My management is better at dropping the hopeless cases as opposed to identifying the really good people.

    50. Re:Knowing when not to by m2943 · · Score: 1

      So, you agree then that, numerical performance of Eigen sucks for large matrices. For small, fixed size matrices it likely is no better than Fortran either. Syntactically, Eigen is pretty lousy as well: you can write some array expressions, but defining functions on matrices is messy, and slicing and similar operations also are restrictive. Eigen's error messages are impenetrable due to the use of template metaprogramming, and parallelization support in it is close to non-existent.

      Fortran these days has built in matrices that automatically use the best possible BLAS/LAPACK backends. You can write Matlab-like array expressions, get clear error messages, and can efficiently pass and return arrays, matrices, and slices. And it provides user-defined data types, operator overloading, virtual functions, and built-in parallel and distributed programming support.

      I do a lot of C++ programming (including Eigen) and use C++ because I need to interface with a lot of C and C++ code. But, objectively, C++ is not a very good language for numerical or high performance computing. You can sort of get the job done in it, but it takes a lot longer to write code and ends up much more complex than in a decent numerical language. And while anybody who knows Matlab can write high performance Fortran code almost instantly, becoming a sufficiently good C++ programmers to even get started writing good numerical code takes years.

      Large parts of the numerical and high performance computing community never touch C++ at all. C++ is mostly popular in computer vision, embedded systems, and some areas of machine learning.

    51. Re:Knowing when not to by serviscope_minor · · Score: 1

      FYI, if you only need to get the best N at the end, it's more efficient to stick everything in a vector and use partial_sort to get the first N. Or nth_element if you don't even need them sortedbut just split into less than Nth and greater than or equal

      Depends on the algorith. For a VP-tree or KD-tree, you need the N-th best at every test since you use that to bound the cost and avoid searching as many bins as possible. Without that, you wind up with a linear cost not a logarithmic one.

      --
      SJW n. One who posts facts.
    52. Re:Knowing when not to by david_thornley · · Score: 1

      A C++ master writes code that a C++ novice can use. There's all sorts of hard-to-understand technical wizardry possible in C++ that makes actual programming simpler. Templates are complicated, but using C++ standard containers, iterators, and algorithms is easy.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    53. Re:Knowing when not to by serviscope_minor · · Score: 1

      So, you agree then that, numerical performance of Eigen sucks for large matrices.

      Not explicitly, since I've not benchmarked it or read any benchmarks but I'm prepared to believe it. I know that BLAS people put a lot of effort into all sorts of cunning blocking stuff.

      For small, fixed size matrices it likely is no better than Fortran either.

      Depends on how much hand-coding you're prepared to do. C++ has the advantage that you can bake the type into the type, which aids the compiler.

      Syntactically, Eigen is pretty lousy as well: you can write some array expressions, but defining functions on matrices is messy, and slicing and similar operations also are restrictive.

      I agree there, which is why I don't use Eigen. I'm holding it up since it's for some reason the most popular library, rather then the best.

      and parallelization support in it is close to non-existent.

      I don't really care much for parallelisation at that level. For my stuff, large matrices are donw with LAPACK which seems to have it and large amounts of small matrices are solved with a #pragma parallel for

      Fortran these days has built in matrices that automatically use the best possible BLAS/LAPACK backends.

      Maybe, but a BLAS backend is never going to do anything but a wretchedly slow job on a 2x2, 3x3 or 4x4 matrix :) If you have a few billion of them, then the performance matters.

      Anyway, we were talking about the comparison to C, not FORTRAN originally. I don't know all that much about FORTRAN except that C++ does seem more expressive for the bits which aren't purely numerical.

      Large parts of the numerical and high performance computing community never touch C++ at all. C++ is mostly popular in computer vision, embedded systems, and some areas of machine learning

      It seems pretty popular with the supercomputer folks for new codes. But yes, it is popular for computer vision. I can't imagine something like PTAM being written in anything other then C++. Not only do you need high performance numerics, you need high performance book-keeping and other bits and bobs as well. C++ is the only one that gives you the good performance and expressivity across the board.

      Anyway, when it comes to array-banging as opposed to linear algebra, I rather prefer using explicit for-loops to array notation. I can do the array notation---I've spent enough time with MATLAB---but I find it clumsy and one often has to work rather hard to solve the problems compared to a for loop. That's personal preference.

      --
      SJW n. One who posts facts.
    54. Re: Knowing when not to by crgrace · · Score: 4, Funny

      Wow. You're right. It's only been four hours and your comment is already a mess.

    55. Re: Knowing when not to by Xenna · · Score: 1

      See, I swear it looked great when I previewed it ;-)

    56. Re:Knowing when not to by crgrace · · Score: 1

      You started out claiming that writing code only you can decipher is a good thing for a programmer (otherwise you're "thinking like a manager". Now you're backpedaling to the old "well I'm unique and it works for me" angle.

      For most people, doing competent work that can be understood and extended in your absence is not only a good idea, it is the very essence of professionalism.

    57. Re:Knowing when not to by perpenso · · Score: 1

      I agree with your comment entirely. I would only like to add that a true C++ Master writes code that a C++ Novice can understand.

      Absolutely. Maintainability is one of the motivations for sticking to "needs".

      Also its not just for the novices. It helps when I return to code after a multiyear absence for example. :-)

    58. Re:Knowing when not to by perpenso · · Score: 1

      You are thinking like a manager. As a programmer, I don't want to be replaced easily ...

      No, its thinking like an engineer who want to work on the next new project at the company and not be stuck maintaining the old project. Code that only you can work with tends to keep you where you are, limit your options inside the company.

    59. Re:Knowing when not to by gerddie · · Score: 1

      The main reason for using templates should be to eliminate copy-and-paste coding, not to improve performance.

      This depends on the task. Ever heard of expression templates or partial template specification ? Specifically, the latter is used in many std::copy implementations to do a fast memcopy when the data can be identified as POD or scalar that doesn't require the execution of a copy constructor.

    60. Re:Knowing when not to by Tough+Love · · Score: 1

      Knowing when not to use templates, virtualization, [insert favorite c++ function here], etc.

      +this.

      I observed someone employing a regex parser generator implemented in 80,000 lines of template code (no typo) to parse a simple lexical construct. I recoded the parser in 100 lines of ordinary C in about 1/2 an hour, to compile 10 times faster, run 100 times faster, be 1,000 times clearer, and accept/reject exactly the same input text. Using proper parsing technology of course, no hacks, and no parsers from the library. Somehow, I think they still didn't get the message.

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    61. Re: Knowing when not to by WWE-TicK · · Score: 1

      Your code must suck. When I look back in my code, the only improvements are generally API/language enhancements related. But I've always written clean fast code. Even in 6510A ASM... :)

      Either that or your skills haven't improved at all between the time you wrote the code and the time you came back to it, which is far more likely the case. After all, if you think you are already great then there's no reason to up your game.

    62. Re:Knowing when not to by Matt.Battey · · Score: 1

      I really like your point about the C++ Master writing for a C++ Novice. I've always had that as a goal, make statements that are easy to read, but at the same time powerful.

      One thing I've thought that is a most important feature of C++ are automatic variables, which leads to Acquisition is Initialization ( https://en.wikipedia.org/wiki/... ). In some ways C# (and .NET) has this ability, but Java definitely doesn't do so well. Resource allocation (pointers, mutexes, files, etc.) are some of the hardest things to keep track of in any language. Garbage collectors are fine, but even languages with these don't do so well with OS objects (files, semaphores, etc.). I think C++ shines when you can master this pattern and use it to make very readable and reliable programs.

    63. Re:Knowing when not to by Anonymous Coward · · Score: 0

      but why should I write code for somebody who'll replace me ?

      Because, to paraphrase an old song, "my name is somebody else's curse."

    64. Re:Knowing when not to by m2943 · · Score: 1

      You're shifting your claim.

      No one I know who does high performance code (such as numerics, real time computer vision, that sort of thing) uses anything but C++, especially for new projects. There is nothing out there that combines the speed and expressivity of C++, and when you know performance is going to be a factor at some point, C++ is the only choice.

      And:

      Check out something like Eigen or TooN (a somewhat more obscure library which is used in the vision world for things like PTAM). They are very far from C++. The code written down in an editor reads more like maths. There's no explict loops, no explicit memory allocation. They're both high performance libraries used in challenging applications (seriously download and run PTAM, it's amazing).

      PTAM is decent C++ code with probably pretty decent performance, but it isn't "high performance numerical code" or even high performance embedded code; it contains none of the performance tuning that such code usually should have.

      I think it is dishonest on your part to recommend Eigen, when you know (or ought to know) that it actually isn't high performance and is deeply mired in C++ idiosyncracies. Likewise, I think it is dishonest of you to portray C++ as the only high performance computing language in town, when you know full well that many people are using other languages, and you are simply not even familiar with those other languages.

      I do use C++ a lot in my work and I recommend it to other people. But unlike you, I don't feel any need to lie about what it is and isn't. There are many alternatives to C++, and I think people should keep an open mind about what they use.

    65. Re:Knowing when not to by Anonymous Coward · · Score: 0

      I love the rare moment of finding an actual insightful post on slashdot from someone who seems like they actually have a clue about technology.

    66. Re: Knowing when not to by Anonymous Coward · · Score: 0

      Spoken like a true junior code monkey.

      I want to write code that anyone who knows the language can pick up and run with it because I don't want to be the only person who can maintain said code and forever be stuck doing the same boring thing.

    67. Re:Knowing when not to by Anonymous Coward · · Score: 0

      When we notice programmers like you they're marked to be laid off at the first opportunity. Sometimes sooner if they're assholes, which they normally are.

    68. Re:Knowing when not to by Anonymous Coward · · Score: 0

      Discovery of a potentially deadly bug causes an audit of that person's code. If they're generally doing a good job and trying to do their best then we back the person up. If the person was writing poor code to stay valuable then we crucify them. Writing code like that makes you a risk to the company and everyone using the product. Bye bye. Mistakes happen, but they happen much more often when you're doing it on purpose.

    69. Re:Knowing when not to by Anonymous Coward · · Score: 0

      "HPC" "Matlab and Python"

      Lol. Fortran, yes, but Matlab or Python for HPC? Get real.

    70. Re: Knowing when not to by eulernet · · Score: 1

      It's not that my code sucks, it's just that my understanding improved.
      I also started coding in 6502, and was seeking perfection at that time. It was not as easy as you may believe.

      Recently, I took a look at my old code, and realized how much I was obsessed on performance (it's natural when you have 1 Mhz and 48Kb of RAM), but I was still able to find some tony improvements. At that time, I was so sure it was perfect !

    71. Re:Knowing when not to by eulernet · · Score: 1

      You cannot be perfect all the time.

      I'll give you an example from my own experience.

      At my company, we had a very good coder. Everybody recognized his competence, and thus he was tasked to write an email tracking system.
      2 or 3 years later, he quit the company since he found a better job elsewhere, so we inherited his code.
      Sure, it was written clearly, but his system was heavy on resources.
      At a given moment, the system stopped working, and I had to check what happened.
      As I said, it's not that the code was not clean, but the database design was quite poor, and it was unable to keep the load.
      Since the company doesn't want to pay for rewriting the system, the system has now a lot of external procedures to remove the old entries.

      This is to show you that however perfect your code is today, it'll be probably ugly in a near future, even if you believe you are a good coder.

      Also, about "career enhancement", I believe you have a lot of illusions.
      20 years ago, I experienced a massive burn-out (I was programming games at that time), which removed all my illusions about work (I did some psychoanalysis to understand what was happening).
      What is important is not your "career", or even "usable code", but what motivates you, and how much fun you have from your work.
      You can put the "I am a winner" attitude in front of me, but I really don't care, since I know that you are just faking who you are.

      In all my jobs, all the people around me were faking what they were. They want to appear competent, skilled and good at listening to others (this is what their company expects), but they are never themselves, and this requires much less effort than faking it.

    72. Re:Knowing when not to by Anonymous Coward · · Score: 0
      To add to that list...

      Knowing when a Dice article is just worthless clickbait.

    73. Re:Knowing when not to by lsatenstein · · Score: 1

      What separates C++ beginners from those with 'intermediate' skills, or even masters?

      Knowing when not to use templates, virtualization, [insert favorite c++ function here], etc.

      Basically knowing enough about programming and problem solving with a particular language to tell a need from a want. Needing to use some language feature vs wanting to use some language feature. And being mature enough to stick to needs rather than indulge wants.

      Or to state things differently ... all the features have a time and place, and its probably not all the time and in every place.

      Think as a C programmer, (the kiss principal) and recast your solution into C++. Its not hard to convert structure manipulation into manipulation of an object. In effect, think simple, think about the next programmer who will be pulling his hair out trying to understand what the templates, castings, and obtuse code is doing.

      --
      Leslie Satenstein Montreal Quebec Canada
    74. Re:Knowing when not to by Anonymous Coward · · Score: 0

      The whole point of code is for developers to clearly communicate the intent of the software to other developers.

      Otherwise, we might as well just all code in ASM.

    75. Re: Knowing when not to by Anonymous Coward · · Score: 0

      You cannot make a problem simpler than then problem itself. Some problems are above people's abilities.

    76. Re:Knowing when not to by serviscope_minor · · Score: 1

      You're shifting your claim.

      From what to what? You may wish tocheck what my claim actually was.

      PTAM is decent C++ code with probably pretty decent performance, but it isn't "high performance numerical code" or even high performance embedded code; it contains none of the performance tuning that such code usually should have.

      It's not pure numerics, as you're thinking of them. It's certainly not embedded code. It is certainly high performance however. It is a very CPU bound algorithm and it uses what was at the time state of the art algorithms for pretty much every step. Not only that but very fast implementations of them. It is a very, very well written piece of code.

      I think it is dishonest on your part to recommend Eigen, when you know (or ought to know) that it actually isn't high performance

      OK, you're determined to completely ignore a large facet of computing. For large amounts of small matrices the fixed sized numerics libraries won't be beaten. I've examined the output of the ASM code. For such things, the cache locality is good and the compiler knows about aliasing. So unless you provide benchmarks, I simply won't believe you.

      Also, the eigen benchmarks seem to show it matching BLAS and LAPACK for speed.

      and is deeply mired in C++ idiosyncracies.

      I think personally, that TooN has a nicer interface than Eigen. I suspect others don't agree because Eigen is more popular. In any case, the idosynchracies are in the function defintion, which frankly doesn't matter nearly as much.

      The actual maths code reads like maths. That's the important bit.

      Likewise, I think it is dishonest of you to portray C++ as the only high performance computing language in town,

      Except I didn't. I said I don't know anyone who uses anything else. I also asserted C++ has the best combination of performance and expressibility. Or course you could write in C or FORTRAN, they're both high performance and Turing complete.

      C++ is still more expressive though.

      You seem very angry though. I think you should go back and carefully re-read my posts and the context and sift out what I actually said and whatever random things you've hallucinated.

      --
      SJW n. One who posts facts.
    77. Re:Knowing when not to by Anonymous Coward · · Score: 0

      From what to what? You may wish tocheck what my claim actually was.

      Let's see:

      Check out something like Eigen or TooN (a somewhat more obscure library which is used in the vision world for things like PTAM). They are very far from C++.

      Wrong. Eigen code constantly forces people to deal with the complexities of C++.

      They're both high performance libraries

      Wrong. Eigen is not a "high performance library", given how much worse it performs than a good BLAS implementation.

      when you know performance is going to be a factor at some point, C++ is the only choice.

      Wrong. There are plenty of languages capable of delivering high performance code.

      The actual maths code reads like maths. That's the important bit.

      I think there are two operators in Eigen that "read like math": "+" and "-", and even they don't quite work like their mathematical equivalents. Languages like Fortran 2008, Matlab, R, Python, and Julia are much closer to mathematical notation.

      [PTAM] not pure numerics, as you're thinking of them.

      So, as I was saying: PTAM is not high performance numerical code. Glad you agree.

      I also asserted C++ has the best combination of performance and expressibility.

      Compared to what? You don't seem to know any of the alternative numerical languages.

      You seem very angry though.

      No, just pointing out that you're giving bad advice. Too many scientists, mathematicians, and engineers have wasted their time on C++ because of bad advice from people like you.

  2. "According to this dice article." by Anonymous Coward · · Score: 1

    Well, that really tells you all you really need to know.

  3. We're all learners... by vux984 · · Score: 2

    :eyerolls:

    We're all learners. But anyone with more than a passing familiarity with C++ already knows everything in that puff piece of a Dice article.

    1. Re:We're all learners... by Psychotria · · Score: 1

      The stuff in that article isn't really about C++; it's about knowing how to program when the abstractions of higher level languages are not available. In other words, if you can program masterfully in C and are mediocre in ASM then C++ really shouldn't be a big hurdle. But, I don't think people these days learn the fundamentals first.

    2. Re:We're all learners... by Anonymous Coward · · Score: 0

      While I certainly agree, one point that I find separates a firm understanding of fundamentals from a magic believe in "objects passing each other messages" as if they were spacecraft moving around the solar system, is when a programmer finally understand why his this-pointer can be null.

      I had a colleague who had a program that crashed whenever he attempted to access a member variable of a class. I told him his this pointer was null. He didn't believe me, because a this-pointer is inherent to an object and therefore must always be valid if you are executing code belonging to that object. I challenged him to print it. He did. It was null. He then was enlightened ;-)

    3. Re:We're all learners... by Anonymous Coward · · Score: 1

      There's not a lot to know about assembly language. Basically, it's the skill to download, read, and understand some CPU's documentation. Oh, and to apply that knowledge, of course. ;)

    4. Re:We're all learners... by Anonymous Coward · · Score: 0

      You are kinda right, programming in assembly isn't exactly hard. It's actually super easy because you don't have to guess what the computer does. It does EXACTLY what you tell it to do, no more, no less. Now, learning all the OP codes and what they do, even for a single processor architecture, not even mentioning all the systems a modern computer or embedded device has, is such a big pile of information there isn't a single person alive who knows more than his own tiny slice of it all. Programming in assembly is tedious work. But also very fun. At least on small systems, such as microcontrollers, where you can actually learn most of the system before going totally insane.

    5. Re:We're all learners... by Anonymous Coward · · Score: 0

      So how about you help people by saying how this can be null, rather than sitting there smugly stroking your neckbeard? Go ahead, enlighten us.

    6. Re:We're all learners... by Anonymous Coward · · Score: 0

      But, I don't think people these days learn the fundamentals first.

      Firstly, I must say that I'm ensconced in 'get off my lawn' territory, and my first inclination is to agree with you.. but with regard to learning fundamentals.. when does that really apply? Can we teach a truly decent programmer in a certain domain (e.g. business, bioinformatics, etc) without having a low-level knowledge of the machine? I think that kids should still take computer architecture and assembler, but does that really apply to MIS majors who write business code? They're about 'getting shit done' as opposed to getting philosophical about the whole situation (I say they because I consider myself to be in the CS/EE camp). Then again, the article is about C++ which has been subsumed by Java in the IS/IT space, but there was a time when MIS folks had to deal with Visual C++ instead of C# or Java.

      And we all know how optimization on business code goes nowadays: throw more hardware at it... but I digress.

      Again, I agree with you, but as a friend who is a comp sci prof said:

      We once taught our children how to kill a tiger with a spear.. now that we have bows and firearms, is it still relevant?

      This was in response to me going off about not requiring a real computer architecture class (it's an elective at many places); they get off the hook with a lightweight 'machine organization' class nowadays.

    7. Re:We're all learners... by Ihlosi · · Score: 1
      So how about you help people by saying how this can be null,

      I assume by something like this:

      ((my_class *) (0))->somemethod();

      As long as somemethod() doesn't try to access any class members, the code may even fail to show any obvious misbehavior.

    8. Re:We're all learners... by Psychotria · · Score: 0

      I guess I was looking at it more from the point of view of "how/why things are done" rather than the end effect (e.g. how linked lists -- yes, a very basic concept -- actually work rather than just knowing what it does; this, perhaps, provides insight into what algorithms are appropriate to use. Another example that came immediately to mind when reading the article was memory management: most students, for some reason, struggle with pointers; if they knew how things worked at a lower level [without even this shallow abstraction] perhaps they'd realise that they're not mysterious and it's simple indirection... maybe then handling memory would be easier... I'm not going to go on with examples of object oriented and other paradigms -- that can obviously be implemented in plain C -- because I hope that my point that understanding what happens underneath the abstraction is, maybe, valuable can be expressed by these simple examples given.)

      We once taught our children how to kill a tiger with a spear.. now that we have bows and firearms, is it still relevant?

      I think it is still relevant. Perhaps using a spear is the best way (I really don't know because I haven't ever had to kill one). Let's see, we have a) a spear; and b) a firearm. They both kill the poor cat (that's the abstraction... the cat will die). But understanding how the firearm kills and how the spear kills might help choose the correct or most appropriate weapon given the circumstances.

      A spear kills by piercing into the cat in an area that will lead to death (this needs further knowledge but I will assume that for a clean and quick kill that a firearm will require that same knowledge). A spear can be used two ways: a) you can throw it at the cat and hope for the best; or b) you can aim it at the cat as it attacks and let its momentum carry it onto the spear, driving the shaft deep into where you want it (can't do that with a gun). With the spear I guess you have to jump out of the way -- especially in the second case -- but the spear, hopefully, remains embedded in the cat further hampering its mobility (and who knows, maybe its aggression will refocus onto the spear instead of on the hunter).

      A firearm will kill by penetration into flesh as well. Depending on the firearm and characteristics of the projectile it might rely on transferred energy as well. The momentum of the kitty probably plays little part in the end result though -- except that its mobility is not restricted by something inside itself rather than a spear that's banging against the ground and the trees around it, hampering further attack). The kitty cat will probably respond in anger towards what it perceives as the source of the pain -- the shooter -- rather than the spear that is embedded in it and flapping around while the kitty is in its death throes.

      Also, depending on the firearm maybe it's not as nice as a spear for preserving the integrity of the cat's coat... perhaps a single entry wound and a mass of internal damage is better than blowing kitty's face off completely (again, depends on the actual weapon used but this still demonstrates the point that knowing the abstraction is worthwhile).

      Sigh. Poor cat.

      Anyway, I'm not disagreeing with you either. Not entirely. What I disagree with is that not knowing details is not important (and I get the feeling that you don't believe that either, so I'm not really responding to you but the wider audience).

    9. Re:We're all learners... by Drethon · · Score: 1

      To me the fundamentals we need to be teaching are how to first design a program independent of the language, then be able to use any language to implement it. People need to understand that programming isn't coding.

    10. Re:We're all learners... by Anonymous Coward · · Score: 0

      This is not a programming course, it is a discussion about skill level. But since you asked so nicely:

      someclass *obj = nullptr;
      obj->nonvirtualfunc ();

      As long as nonvirtualfunc does not (directly or indirectly) dereference the this pointer, it will work just fine. Understanding this separates a magic believe in member functions that somehow exist "inside" objects, and whose lifetime is controlled by that object, to a proper understanding of what a member function really is, and the role of 'this' as merely an implied parameter.

      Next time you might want to consider dropping the condescending tone when asking for otherwise irrelevant exposition.

    11. Re:We're all learners... by Anonymous Coward · · Score: 0

      Next time you might want to drop the condescension when responding to questions that call you out on your condenscension.

    12. Re:We're all learners... by Ihlosi · · Score: 1
      As long as nonvirtualfunc does not (directly or indirectly) dereference the this pointer, it will work just fine

      IIRC, doing this will have undefined behavior. It may work the way you describe, or it may do anything else.

    13. Re:We're all learners... by Anonymous Coward · · Score: 0

      I first read "... C++ already knows everything in it is a Duff's Device"...

  4. It's simple by Anonymous Coward · · Score: 0

    The main differentiating factor between C++ beginners and masters are SourceForge, Malware and Dice's self-advertising.

  5. Masters know their limitations. by Ihlosi · · Score: 0

    Masters know they don't know everything, and only use language features they know they can use without introducing bugs.

    1. Re:Masters know their limitations. by jonwil · · Score: 3, Insightful

      I thought I was a guru level C++ programmer (I have been programming C++ for around 2 decades) but even I am constantly finding out about new things I didn't know existed.

    2. Re:Masters know their limitations. by Anonymous Coward · · Score: 0

      Even Bjarne Stroustrup has said that he does not remember the full spec at any given moment.

    3. Re:Masters know their limitations. by Anonymous Coward · · Score: 0

      And, if you resist the temptations (except in private projects) to use them "just because you discovered them", that's fine. Generally, once you know C++ modestly well (your code doesn't just look like C), it's probably best not to use the new "feature" or "trick" you ran across until six months later. Some exceptions for new features (such as the new incarnation of auto - a great feature), but probably you knew about these for at least six months before you could risk using it if you cared about code portability.

    4. Re:Masters know their limitations. by DrXym · · Score: 0
      And that in a nutshell is what's wrong with C++. It has bloated and bloated over the years, never deprecated anything of note and now its this behemoth that few compilers implement in its entirety and few programmers now how to use including all the gotchas, weird semantics and vast complexity.

      It's unsurprising that most application development jumped ship to something higher level. It will be interesting to see if languages like rust eat into the systems programming aspect.

    5. Re:Masters know their limitations. by jellomizer · · Score: 1

      No... That is more like the arrogant closed minded jerk.
      A master will strive to learn more about such features and when they suffencly understand them they will implement when approproprate.
      I myself have been out of practice in C++ for about 15 years. I recently began working on a project where I needed better systems control and huger performance. So I choose to use C++. I know most of the concepts however I needed to research how to to do some things over again.
      My experience made it easy for me to search for the topic and relearn the language again.
      What else I found is the C++ comes with a new set of extra standard libraries that made many of the obnoxious aspect of C++ much less tedious to use.

      --
      If something is so important that you feel the need to post it on the internet... It probably isn't that important.
    6. Re:Masters know their limitations. by UnknownSoldier · · Score: 4, Informative

      This 100%. C++ has become a clusterfuck of over-engineering and I say that as someone who has worked on a C++ compiler.

      * /Oblg. Comedy: Hitler on C++

      When you have even committee members admit they only use a sub-set then you know the language is too big.

      The C++ committee recognizes there are many problems with C++ iostreams but nothing is being done towards performance and type safety.

      The committee would rather argue over the rare case of multi-dispatch / multi-methods then fix core issues.

      * http://www.stroustrup.com/mult...

      Crap like long long, "long double", etc. should have been deprecated in year X, and removed in year X+5. Are they going to add "long long long" someday?? Having types like "double" in 2015 is just retarded -- replace it with "float64_t", and the fore mentioned long double with the clear "float80_t". Bandaging the problem like int_fast32_t doesn't solve anything. How many fucking integers types does the compiler need to throw at us?? short, long, long long, int, long int, int_fast32_t, int_least32_t, etc. and I'm not even talking about MS's hacks of __int32, __int64, etc. Simplify the dam language already!!! Set year 2020 as the date when these barbaric types are deprecated, and year 2030 when they are removed.

      Modules have been in a constant state of on-again-off-again for over 10 years:

      * First mention N2073 (Sept.2006)
      * Revived N4047 (May 2014)
      * 2nd draft N4214 (Oct. 2014)
      * 3rd draft N4465 (April 2015)
      * Wording N4466 (April 2015)

      The pre-processor is STILL broken. One would expect #define token operation to work for ALL user-defined tokens. i.e. This isn't rocket science, just a basic Search-and-Replace:

      #define @(func) printf("%s\n",func)
       
      void foo()
      {
        @(__func__);
      }
       
      // Hell, even this should work
      #define @ printf("LOL. Your pre-processor is broken. HA-HA!\n" )

      There are no standard pre-processor macros for function names as a string. GCC has the excellent __func__ which Microsoft finally got around to implementing C99 N2340 in Visual Studio 2015!

      The C++ committee failed to learn the first lesson about design:

      * "Needlessly complexity is a symptom of bad design."

      Or paraphrased from Einstein:

      * "Things should be as simple as possible, but no simpler"

    7. Re:Masters know their limitations. by serviscope_minor · · Score: 3, Informative

      This 100%. C++ has become a clusterfuck of over-engineering

      Nope. It's mostly hampered by the need to be backwards compatible. The committee know full well if they make serious breaking changes, then the C++ world will split into two distinct languages. Many, many people won't adopt the new one and the vendors will continue to support them because there's money there.

      It's a blessing and a curse. The curse it it's hard to do anything but add features. The blessing is my code I debugged 13 years ago still works.

      The committee would rather argue over the rare case of multi-dispatch / multi-methods then fix core issues.

      You're basically being an arse. You're picking out one rather speculative paper designed to help C++ stay modern a ways in the future (and somehow labelling this as a bad thing) and yet knowingly ignoring the many papers on fixing core issues.

      Modules have been in a constant state of on-again-off-again for over 10 years:

      Yeah they should just slap in some module crap and if it's wrong, just rip it out and replace it. Who cares about getting things right and not breaking working code, eh? They learned their lesson very hard with export templates and are keen to not have to learn the same lesson again.

      There are no standard pre-processor macros for function names as a string. GCC has the excellent __func__ which Microsoft finally got around to implementing C99 N2340 in Visual Studio 2015!

      So you submitted a proposal, right? Or do you expect other people working for free to magically know your personal problems from your whining on slashdot?

      --
      SJW n. One who posts facts.
    8. Re:Masters know their limitations. by Anonymous Coward · · Score: 0

      Crap like long long [open-std.org], "long double", etc. should have been deprecated in year X, and removed in year X+5

      No no no, you wrote a C++ compiler and you don't even understand why C++ is successful? It's because it still compiles all the old code. You DO NOT deprecate types that are in use in working code. I'm not sure "long double" is in fact used in any working code, but "long long" is THE 64-BIT TYPE so you don't fucking deprecate it.

      Having types like "double" in 2015 is just retarded

      WTF? Now you want to retire "double" because you don't understand why C made the choice to name these types and NOT specify their sizes? Fuck sake.

      Seriously, if you want all this go write your own language. We're not breaking everybody's code bases just to preserve your idea of "purity" for its own sake.

      One would expect #define token operation to work for ALL user-defined tokens

      You wrote a C++ compiler and you don't even understand how the lexer works? You can't just extend #define to accept @, you have to have it reprogram the lexer. This is not something that well-designed compilers do, plus I don't want to see your fucking @ signs all over the code. We have conventions. Learn them.

    9. Re:Masters know their limitations. by Anonymous Coward · · Score: 0

      Bjorn Stromstrup himself at the latest C++ convention said he didn't understand the complete language (not the libraries) C++ it is to big now. This is a guy who lives and breaths C++ as he is 'the' designer of C++ and still is.

    10. Re:Masters know their limitations. by Anonymous Coward · · Score: 0

      replace it with "float64_t", and the fore mentioned long double with the clear "float80_t"

      Looks like "Everything's an x86" has replaced "Everything's a VAX".

      Hint: there are other CPUs in common use that have C compilers. Some still even have 16-bit int (MSP430). foonn_t types are aliases to actual types that let the programmer know that the type is the size expected, particularly for integer types. Those basic types still need to be in the compiler so that stdint.h has something to alias into the "standard" types.

      That being said, programmers unironically using types like long long and long double is indeed a Bad Thing.

      and I'm not even talking about MS's hacks of __int32, __int64

      You also forgot the BYTE, WORD, LONG, etc. types all over the Windows API. Sure, they're older than stdint.h, but they're yet another buttload of type aliases to keep track of.

    11. Re:Masters know their limitations. by Yunzil · · Score: 1

      Well, for starters '@' isn't a valid character in a token. Are you sure you worked on a compiler?

    12. Re:Masters know their limitations. by Jeremi · · Score: 1

      And that in a nutshell is what's wrong with C++. It has bloated and bloated over the years, never deprecated anything of note and now its this behemoth that few compilers implement in its entirety and few programmers now how to use including all the gotchas, weird semantics and vast complexity.

      Much like the English language, which is also quite useful and therefore widely used. Being useful over a wide variety of scenarios and being bloated-and-complex are often two sides of the same coin.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    13. Re:Masters know their limitations. by UnknownSoldier · · Score: 1

      And that explains why $ is accepted but not @ how again?

      #define $ printf("Works!\n")

      #define @ printf("Nope\n")

    14. Re:Masters know their limitations. by UnknownSoldier · · Score: 1

      You're comparing Apple and Oranges.

      The PDP had 36-bit address space. Are there any modern CPU's that don't use powers-of-2 for registers and address space?

      Instead of fixing the language and compiler, is a hack. We only need a few basic types built into the language.

      int; // signed, native
      int8_t, int16_t, int32_t, int64_t, int128_t
      uint8_t, uint16_t, uint32_t, uint64_t, uint128_t
       
      float; // native type
      float32_t; // C float
      float64_t; // C double
      float80_t; // C long double

      Deprecate and Remove this "short" and "long" stupidity. It isn't 1972 anymore.

    15. Re:Masters know their limitations. by cplusplus · · Score: 1

      Yeah... C++ is great that way. It's my favorite language :)

      --
      "False hope is why we'll never run out of natural resources!" - Lewis Black
    16. Re:Masters know their limitations. by Anonymous Coward · · Score: 0

      Obviously not a C++ compiler writer, as you're mixing C and C++. Real C++ compiler writers know the two are distinct. As you can read in N1811 when you read that, C++11 got `long long` because C99 had it, and C++ tries to avoid trivial incompatibilities like that. If you need `#define LONGLONG long long` and another #define for C++11, something would have gone badly wrong. Same thing for int_fast32_t : necessary for compatibility.

      BTW, `long double` isn't 80 bits. That's a x87 assumption. With x64, SSE is the FP unit of choice and it doesn't have 80 bits precision. Nor does ARM or MIPS. Again, that doesn't convince us you actually write C++ compilers.

      Modules is the real hard part, yes. It's clear from the different approaches that Linux and Windows take, to name just the two biggies. And Mac is different from both. Modules are supposed to provide a single, efficient abstraction, and nobody has yet come with a winning solution. If you think it's easy, show some running code for all major platforms.

      Remember: C++ is a language defined by backwards compatibility, going back to K&R 2 = ANSI C89. If you want C++ without backwards compatibility, there is D.

    17. Re:Masters know their limitations. by UnknownSoldier · · Score: 1

      > You also forgot the BYTE, WORD, LONG, etc. types all over the Windows API. Sure, they're older than stdint.h, but they're yet another buttload of type aliases to keep track of.

      I didn't mention it because that is a separate issue. Microsoft's stupidity is not part of C++, though they seem to have inherited some of it.

      I guess someone at Microsoft liked C's "double", and hated the inconsistency with "float" so they added an alias System.Single in C# !

      In contradistinction to System.Double

    18. Re:Masters know their limitations. by david_thornley · · Score: 1

      The explanation is that the Standard doesn't allow either of them. If your favorite compiler allows the former, it's as an extension. If you really want to know the reasons behind compiler-specific behavior, ask whoever wrote your compiler.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    19. Re:Masters know their limitations. by Dixie_Flatline · · Score: 1, Insightful

      I remember reading slashdot the day that there was news that the C++ grammar had officially been proven to NOT have a bad left recursion in it. That was around 12 or 13 years ago, if I remember right. Up until then, nobody was actually sure, and every compiler writer had to take a slightly different approach to the things they were going to leave out of the compiler.

      When you start with that as a foundation—20 years of having a language grammar that nobody is sure can be completely implemented—you're starting from a pretty bad place. The language was badly designed to begin with.

      Then you've got the issue of Templates. Powerful? Yeah, for sure. But that's because the template language is turing complete on its own, and nobody realized THAT at the time either. I'd reckon (wildly, I admit) that 95% of the functionality of templates and template meta-programming is discovered functionality. ANY language becomes hyper powerful when you bolt another entire language to the side of it. They were just supposed to solve a problem with generics, and instead created a couple new ropes to hang yourself with.

      C++ is a language that isn't so much as designed by committee as designed by falling down rabbit holes. What new, bizarre, unconfronted thing will we see next? Who knows?

    20. Re:Masters know their limitations. by Anonymous Coward · · Score: 0

      Dude, you're arguing with a Java developer. Was the effort really worth it?

    21. Re:Masters know their limitations. by Yunzil · · Score: 1

      Bzzt. Dollar sign is a gcc extension.

    22. Re:Masters know their limitations. by UnknownSoldier · · Score: 1

      And MSVC as well.

    23. Re:Masters know their limitations. by Yunzil · · Score: 1

      OK? The point is that it's not standard. Macro names must follow the same rules as variable names, ie, letters, numbers, and underscores only; and can only start with underscore or letter.

      I'm not sure why you're want a macro named '@' anyway. C++ already has punctuation strewn everywhere. The last thing we need is more funny characters. :-b

    24. Re:Masters know their limitations. by DrXym · · Score: 1

      The English language isn't defined by a committee which has the opportunity to fix longstanding issues with the language or deprecate redundant, arcane or dangerous functions and code. C++ does have this opportunity but never takes it. Instead it just heaps another layer of features on top of the old, we all sit around for years waiting for the compilers to implement this mess properly and by then another standard has come out.

    25. Re:Masters know their limitations. by DrXym · · Score: 1

      No no no, you wrote a C++ compiler and you don't even understand why C++ is successful? It's because it still compiles all the old code. You DO NOT deprecate types that are in use in working code. I'm not sure "long double" is in fact used in any working code, but "long long" is THE 64-BIT TYPE so you don't fucking deprecate it.

      This is a stupid justification. Gcc already has switches for different standards, -std=c++98, -std=c++11 etc. There is absolutely no reason whatsoever to stop certain functions, and language features from being deprecated or removed in new standards. If people still want to compile old code they can throw the switch in there and they get that functionality. If they don't, the compiler defaults to the latest version of the standard.

    26. Re:Masters know their limitations. by UnknownSoldier · · Score: 1

      So that it immediately sticks out instead of using an alphabetical character which would probably be lost as "noise."

      > The point is that it's not standard.

      That's not the entire picture.

      GCC Tokenization says this:

      Punctuators are all the usual bits of punctuation which are meaningful to C and C++. All but three of the punctuation characters in ASCII are C punctuators. The exceptions are â@â(TM), â$â(TM), and â`â(TM). In addition, all the two- and three-character operators are punctuators

        In ASCII, the only other characters are â@â(TM), â$â(TM), â`â(TM), and control characters other than NUL (all bits zero). (Note that â$â(TM) is normally considered a letter.)

      Why is $ even considered a letter in the first place? GCC gives this reason:

      As an extension, GCC treats â$â(TM) as a letter. This is for compatibility with some systems, such as VMS, where â$â(TM) is commonly used in system-defined function and object names.

      The more interesting question is why is Microsoft emulating this non-standard behavior?

      > Macro names must follow the same rules as variable names, ie, letters, numbers, and underscores only;

      That is an artificial rule; one would think that the preprocessor is supposed to be independent of the language. i.e. Why can I use C's preprocessor for a language like Perl ? The problem is that the pre-processor's definition of what constitutes a character token is too limited, it should only reject existing symbols that have are predefined operators (i.e. have a mathematical definition) and not blacklist other non-used symbols. If the preprocessor was properly written to do a search-and-replace then this wouldn't be an issue.

      This points to a bigger problem though. Why is my source code limited to sub-set of ASCII? Why can't I include Unicode in comments?

    27. Re:Masters know their limitations. by Jeremi · · Score: 1

      C++ does have this opportunity but never takes it. Instead it just heaps another layer of features on top of the old,

      Correct, and that's an excellent example of why C++ is both popular and messy. If the C++ committee started "cleaning up the language" by removing backwards compatibility with old features, the language would split into two languages ("old C++" and "new C++"), neither of which would have the compatibility or the marketshare of the current C++.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    28. Re:Masters know their limitations. by Anonymous Coward · · Score: 0

      Where's my "-1, Troll", when I need it ?

  6. no. by Anonymous Coward · · Score: 0

    any other questions?

  7. Error Handling by oggiejnr · · Score: 4, Insightful

    I've always considered error handling to be the most important thing when it comes to knowing a language beyond the beginner level. Every language has it's own idiomatic ways from RAII in C++, finally/using in Java to the myriad of ways of handling return codes in C. It is also frequently undertaught in most programming language courses.

    It is for this reason I despise seeing C/C++ on CVs. It implies that you don't have a strong foundation in either language as idiomatic code is so different between the two. By all means list them as two separate languages, but be willing to demonstrate sound knowledge of both, not the bastardised, resource leaking hybrid I see so often when the term C/C++ is invoked.

    1. Re:Error Handling by Ambassador+Kosh · · Score: 3, Interesting

      I may hate seeing it written that way also but that is also the current most common way to write it and that is what HR systems and their computer screening systems except. You are writing a resume for an HR person usually and if you want it t be seen by someone more important it has to get past them first. That means doing stuff that HR people understand.

      There are many fights to take on in this world and others that are just not worth the effort to fight since the costs are so high compared to the benefits and this is one of those fights.

      --
      Computer modeling for biotech drug manufacturing is HARD! :)
    2. Re:Error Handling by Anonymous Coward · · Score: 1

      English also has "it's" idiomatic ways...

    3. Re:Error Handling by Anonymous Coward · · Score: 0

      If you want to see instead "C, C++" you're reading a lot into a person's typography choices.

      Newsflash: C++ calls C, and C often calls C++ via extern "C" calls, so C++ coders are perfectly well aware of the different return code conventions that C uses. Also, RAII is a paradigm you can use in any language, including C (after a fashion). RAII prevents bugs, it's idiomatic in C++ because Stroustrup designed the language to support it well, that doesn't mean it's a bad choice in another language.

      Not sure what anecdotal evidence you're invoking for your position but you're heavily suffering from premature generalization here.

    4. Re:Error Handling by Anonymous Coward · · Score: 0

      "accept"

    5. Re:Error Handling by ranton · · Score: 1

      It is for this reason I despise seeing C/C++ on CVs. It implies that you don't have a strong foundation in either language as idiomatic code is so different between the two.

      I actually list C/C++ on my CV purely to imply I am not strong in either. It was my main language in college and I have used it sparingly in my career, but I don't consider myself a C or C++ developer. So if you are looking for a senior C or C++ developer, look somewhere else. But if you want someone who at least understands pointer arithmetic and/or may have to lead a project where some of the developers are working in C or C++, then I may be your guy. I always clarify if asked, and never apply for jobs where I know they need a C++ guru anyway.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
  8. Experts... by Anonymous Coward · · Score: 0, Flamebait

    know better than to use C++

    1. Re:Experts... by jones_supa · · Score: 1

      C++ gives a nice balance between high performance and relatively good safety.

    2. Re:Experts... by Anonymous Coward · · Score: 1

      I would rather say that about Ada.

    3. Re:Experts... by Anonymous Coward · · Score: 1

      Ada is a nice language. Too bad it's not used much.

    4. Re:Experts... by Rei · · Score: 3, Funny

      Memory objects that clean themselves up after they go out of scope are the devil's work. The devil, I say!

      --
      What about the Ant People? They owe us money.
    5. Re:Experts... by serviscope_minor · · Score: 1

      Memory objects that clean themselves up after they go out of scope are the devil's work. The devil, I say!

      Exactly. The devil creates work for idle hands, does he not? And what does not having to do vast amounts of error prone grunt work do if not leave hands idle?

      --
      SJW n. One who posts facts.
    6. Re:Experts... by Anonymous Coward · · Score: 0

      Totally true, if you need 3rd party libraries, there is often no way around C++. :(

    7. Re:Experts... by superwiz · · Score: 4, Insightful

      Just think about it! (TM) A function gets automatically executed just because you leave scope. Doesn't matter how you leave it. Forget that it's a destructor. It's a function which gets called automatically without anyone writing any code to call it. Show me how to do that in C. And that's the fundamental difference between the 2 languages. The rest is syntactic sugar.

      --
      Any guest worker system is indistinguishable from indentured servitude.
    8. Re:Experts... by Smerta · · Score: 5, Insightful

      I've made the exact same argument to co-workers at many firms... namespaces (e.g. Timer_Init()), virtual functions (tables of function pointers), etc. can be approximated / kludged together... but automatically invoking a function at the right place (destructor and, let's face it, the constructor is pretty handy too) is something that has to be baked into the language, and C++ has it. I work in safety-critical systems, and knowing that I can't leave a function with interrupts disabled, I can't forget to close this socket, etc. is incredibly comforting.

      I'll quote Bjarne Stroustrup here:

      "Just that closing brace. Here is where all the ‘magic’ happens in C++. Variables get destroyed, memory gets released, locks get freed, files get closed, names from outside the closed scope regain their meaning, etc. This is where C++ most significantly differs from other languages. It is interesting to see how destructors -- an invention (together with constructors) from the first week or so of C++ -- have increased in importance over the years. So many of the modern and most effective C++ techniques critically depend on them"

    9. Re:Experts... by Anonymous Coward · · Score: 0

      Haven't you heard of TDD and unit tests?

    10. Re:Experts... by Mike+McTernan · · Score: 2

      It's a function which gets called automatically without anyone writing any code to call it. Show me how to do that in C.

      Well, it's a compiler extension, but GCC supplies the __cleanup__ attribute which essentially allows arbitrary destructor functions in C.

      Mastery of the language is one thing, mastery of the tools another...

      --
      -- Mike
    11. Re:Experts... by Anonymous Coward · · Score: 0

      So, on the one hand, someone points out a feature of C++ he feels beats C.

      On the other, you point out a compiler-specific extension of C that was built to, ultimately, provide a feature that is present in the C++ standard (along with other languages).

      You then provide a pithy, and given that many of us, for various reasons, are not or are not solely using GCC, irrelevant, comment.

      *Slow handclap*

    12. Re:Experts... by KGIII · · Score: 1

      Why would you say this? This is not an attempt to argue but an attempt to see your point and to listen to it objectively. What would you recommend besides C++? I, personally, was a programmer for part of my job and wrote a lot of software specifically to do the tasks we needed to do to be successful. A lot of that was written in C++ and the vast majority of the rest was in C. Well, except for web-facing things...

      Seriously, why would you say that and what would you recommend besides this? I still like to play around, if I build something interesting then I just give it away, so I am very receptive to learning something new or spending some time with a language I have not used in a while.

      --
      "So long and thanks for all the fish."
    13. Re:Experts... by Foresto · · Score: 1

      C++ gives a nice balance between high performance and relatively good safety.

      Huh? Relative to what?

      C++ was my primary language for quite a few years. I was very good at using it effectively while introducing far fewer bugs than most coders I encountered, but I would never call that language anything near safe.

      Maybe you're talking about a subset of C++ that does not include things like pointers and arrays?

    14. Re:Experts... by jones_supa · · Score: 1

      Relative to C# or Java, for example.

      Raw pointers and arrays can be avoided when writing C++. Smart pointers and vector are the alternatives.

    15. Re:Experts... by Foresto · · Score: 1

      I see. You were indeed talking about a subset of C++. Thanks for clearing that up.

    16. Re:Experts... by jones_supa · · Score: 1

      Yep, technically you are correct.

  9. Given how C++ is taught. by serviscope_minor · · Score: 2

    You should certainly be familiar with the syntax.

    You should almost never see a new, and never a delete in normal code (rare exceptions for guru library writers only). If you do, you're almost certainly making life hard for yourself.

    Another thing is programming with concepts. These aren't part of the language yet, but are part of the culture, part of the design of the STL and hopefully will make it into the language. Things having the same "concept" are types where the operation of the semantics are the same.

    This is like a field in mathemetics: you have addition, multiplication, subtraction and division (well, really the additive and multiplicative inverses). If you get the proofs right, they'll work on any field. This is why you can muliply with a modular FFT.

    For example, ints, floats, std::complex all obey the same concept, that of a number. There are more, such as automatic differentiation types provided by expernal libraries.

    Another example is vectors in "metric spaces". A VP-tree is like binary search, but instead of working on an array of numbers, it works on a multidimensonal metric space of vectors. Normal 3D vectors in Euclidian space is a metric space (distances obey the triangle inequality), but interestingly so are bit vectors and hamming distance and even strings and edit distance. The underlying algorithm of a VP tree relies on several semantics. You need to be able to measure distances and update some lower and upper bounds. That is all.

    The art of concepts is writing the algorithm using the abstract interface of the concept upon which it operates. This has several nice properties. Firstly, you use nothing more than the concept. If you use an operation which isn't part of the concept, it's almost certainly a bug. Secondly the algorithms are much clearer because they don't mix in the implemtation of one specific instance of a concept (e.g. building edit distance right into your VP tree) with the underlying algorithm. And finally, once you've done that you get genericism for free. Stick a template around the class and you have a working, debugged algorithm which works on everything it could work on.

    This is how the STL works. For instance std::sort requires two concepts. The range spanned by the iterators passed to it must work with radom access and you must be able to compare the elements with <. Given that it can sort anything.

    A good stage to get to as a C++ programmer is to write code like that, not necessarily even because you need the genericism but it forces you to separate the underlying abstract algorithm from the concrete specific datatype it is operating on this time. Doing so has many benefits.

    --
    SJW n. One who posts facts.
    1. Re:Given how C++ is taught. by Ihlosi · · Score: 0
      You should almost never see a new, and never a delete in normal code

      If you're seeing any news, and no corresponding deletes, doesn't that mean the code leaks memory?

    2. Re:Given how C++ is taught. by Dutch+Gun · · Score: 1

      Not with smart pointers. Those will automatically call delete for you.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    3. Re:Given how C++ is taught. by Ihlosi · · Score: 0
      ...smart pointers...

      I don't like the sound of that. I'm sticking with C and occasionaly bits of assembly.

    4. Re:Given how C++ is taught. by serviscope_minor · · Score: 1

      I don't like the sound of that.

      Why not?

      --
      SJW n. One who posts facts.
    5. Re:Given how C++ is taught. by angel'o'sphere · · Score: 1

      You should almost never see a new, and never a delete in normal code (rare exceptions for guru library writers only). If you do, you're almost certainly making life hard for yourself.

      That is complete nonsense.
      At some point you have to allocate the objects/memory. And for that you need a "new".

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    6. Re:Given how C++ is taught. by Anonymous Coward · · Score: 0

      "Smart pointers" are great -- if you don't care about performance (in which case, why are you not using Java?). If the object is owned by one thread, it's just sloppy to put in the overhead of smart pointers to make your life easy. If the object is shared across threads, it's usually stupid NOT to use smart pointers.

      In a multi-threaded environment where objects may be shared, or not, the overhead as you scale to tens or hundreds of cores is unacceptable if used when not needed. Know your architecture. Know your requirements. Use RAII religiously -- and, in scalable systems level projects, you will see new and delete in constructors, destructors and (for new in particular) in a few other methods. Many of these can be eliminated by using the STL -- but if you are highly skilled and identify bottlenecks, you may do better than the STL because you know your data structures and their life cycles and the STL can't read your mind (yet, maybe the NSA is working on that though).

    7. Re:Given how C++ is taught. by Ihlosi · · Score: 0
      Why not?

      If I wanted the programming language to be smarter than myself, I'd pick an appropriate language (not C++).

      From a quick glance, smart pointers kind of look like local objects, but they're created on the heap instead of the stack, and whatever they point to automatically gets deleted when the smart pointer goes out of scope. Okay, that's not horribly smart. I could live with it.

    8. Re: Given how C++ is taught. by Anonymous Coward · · Score: 0

      notice almost

    9. Re:Given how C++ is taught. by DrVxD · · Score: 1

      see, for example, std::make_shared. http://en.cppreference.com/w/c...

      --
      Not everything that can be measured matters; Not everything that matters can be measured.
    10. Re:Given how C++ is taught. by angel'o'sphere · · Score: 2

      Smart pointers live where ever you declare them.
      Either heap or stack or even with limited usability in static allocated memory.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    11. Re:Given how C++ is taught. by serviscope_minor · · Score: 1

      A smart pointer has the same basic interface as a pointer, namely it supports * and ->, but not necessarily arithmetic. They're not supposed to be smarter than you, they're smarter than dumb pointers, because you can put logic into the various parts.

      But yes, the standard ones essentially do lifetime management for allocated stuff, for when your object lifetime doesn't match the stack. They're pretty good things :)

      --
      SJW n. One who posts facts.
    12. Re:Given how C++ is taught. by tp_xyzzy · · Score: 2

      > In a multi-threaded environment where objects may be shared, or not

      Isnt it bad sign, if you're forced to use unreliable multi-threaded abstractions... Good luck finding all race conditions...

    13. Re:Given how C++ is taught. by Rei · · Score: 4, Insightful

      "Smart pointers" are great -- if you don't care about performance (in which case, why are you not using Java?).

      Since when does Java's performance even come close to C++'s in benchmarks? C++ performance is generally very close to that of C's, and in some cases exceeds it (example: qsort vs. std::sort - C++'s use of templating allows for inlining of the sort function code)

      Smart pointers have very, very little overhead. The worst is std::shared_ptr, and it's still only adding a reference counter, and that's only used on pointer copy and deletion. And if you have a use case that requires std::shared pointer as your smart pointer of choice, then this is counting that you'd have to be doing anyway in some form or another.

        From the benchmarks I've seen, most people see about an additional 5%-ish overhead in debug mode with std::shared_ptr vs. raw pointers in pointer-heavy code. In a release build there's generally no measurable effect (the difference being, in debug mode it can't inline the dereferences).

      --
      What about the Ant People? They owe us money.
    14. Re:Given how C++ is taught. by serviscope_minor · · Score: 1

      That can't be right!

      The guy you are replying to is the resident C++ ultraguru on slasdot. There is no one regularly here who knows more than him:

      http://slashdot.org/comments.p...

      So I don't see how it's possible that such a simple thing could possibly be right!

      --
      SJW n. One who posts facts.
    15. Re:Given how C++ is taught. by TheRaven64 · · Score: 3, Insightful

      "Smart pointers" are great -- if you don't care about performance (in which case, why are you not using Java?). If the object is owned by one thread, it's just sloppy to put in the overhead of smart pointers to make your life easy.

      If an object has a single unique owner, then std::unique_ptr has no run-time overhead and will ensure that the object is correctly deleted even in the presence of exceptions. I agree with the grandparent: any object that isn't allocated on the stack should be created with std::make_shared or std::make_unique.

      --
      I am TheRaven on Soylent News
    16. Re:Given how C++ is taught. by TheRaven64 · · Score: 1

      Not true. In C++11 you have std::make_shared, which allocates an object and the metadata block for a std::shared_ptr in a single block, giving you a lower-overhead mechanism for creating a std::shared_ptr. C++14 also introduced std::make_unique, which doesn't save anything over calling new and then casting to a std::unique_ptr, but make it possible to write code without any need to directly call new. In C++14, there is absolutely no reason to see a new or delete in the code outside of the standard library implementation. If you're writing one then you're doing it wrong.

      --
      I am TheRaven on Soylent News
    17. Re:Given how C++ is taught. by Anonymous Coward · · Score: 0

      Unless you want to hide the constructor to enforce holding by interface, at which point std::make_unique is unable to find the constructor, and you need to new the pointer instead. Even so, I'd say that should best be done in a Create method which returns the smart pointer.

    18. Re:Given how C++ is taught. by fnj · · Score: 1

      Succinctly put and to the point. And people who can't or don't understand this have no business using C++.

    19. Re:Given how C++ is taught. by rl117 · · Score: 2

      Well, rather than "not liking the sound of it", I would highly recommend you educate yourself about them. There's plenty of examples floating around. I've been using std::shared_ptr for well over a decade, first as boost::shared_ptr, later std::tr1::shared_ptr and today std::shared_ptr (they are all the same, just going to the final standard name with C++11). The number of memory leaks I've had in my released software over that period: zero, checked regularly with valgrind.

      Smart pointers aren't magic. They are just an instance of RAII to acquire a resource (memory) upon construction of an object and release it upon destruction. For std::unique_ptr, there's only ever one instance, though you can transfer it. For std::shared_ptr the object can be referenced multiple times, handled with reference counting, so destruction decrements the shared count by one, and deletes the memory once the reference count reaches zero. The smart pointer can be a variable in a function or class method, a class member, static member or global variable. It's the same in all cases.

      Think about how many bugs there are in C code due to malloc/free issues--double free, not freeing, and if using reference counting failure to increment or decrement where needed (just see how many times this crops up for GTK/GObject-based code). And no way to know who owns a pointer and who is responsible for freeing it--it's just a bare pointer. Smart pointers handle all of this for you, that is to say that the compiler does all the work automatically that you would have to do by hand *anyway*. And it's thread-safe and exception-safe. It makes it impossible to mess up memory management--if it's broken it won't compile. In terms of writing robust and reliable code, it's a world apart from plain C with malloc/free or old-style C++ with new/delete. It's vastly simpler for the programmer, too. There's little to dislike about this--IMO it's one of the most beneficial additions to best practices for C++ ever made.

    20. Re:Given how C++ is taught. by superwiz · · Score: 1

      Good luck with that in multi-threaded code.... which you (of course) don't need. But the library that you linked against 2 years ago is all-of-a-sudden using now. So that free() that you are sure will get reached in all code paths won't be reached anymore because the thread which called your function (your callback function) got interrupted. Congratulations! You just leaked code from a program which never leaked before.

      --
      Any guest worker system is indistinguishable from indentured servitude.
    21. Re:Given how C++ is taught. by superwiz · · Score: 1

      Why would reference counting effect performance? Oh, and beyond a certain program size, Java (not the theoretical exercise, but the actual written code) will perform better because it will make it more difficult to write use poorly performing algorithms. The actual slowdown of writing the same code in Java vs C++ is around a factor of .8, but if it means that even one tight loop will use O(log n) instead of O(n) (due to programmer's laziness), you win.

      --
      Any guest worker system is indistinguishable from indentured servitude.
    22. Re:Given how C++ is taught. by rl117 · · Score: 1

      Smart pointers, well shared_ptr, has an overhead on incrementing and decrementing the reference count due to the use of atomic inc/dec. It has no overhead for *use*, i.e. dereferencing.

      At least in my own code, shared_ptr passing/copying is a rare event; that all happens during some setup phase; the real high-performance parts don't perform any allocation/deallocation/refcount operations. So as with everything, there are tradeoffs and design constraints to consider before blindly using it everywhere. (I actually *do* use it everywhere. But I also think about *how* I use it to avoid creating performance problems.)

      And while I could use new and delete in constructors and destructors, why wouldn't I use unique_ptr here to have it done for me? For me, shared_ptr and unique_ptr are about *correctness* and *safety*, including exception-safety and thread-safety. The performance is a secondary concern which is also important, but which can be worked on in the knowledge that the logic is correct.

    23. Re:Given how C++ is taught. by Anonymous Coward · · Score: 0

      which doesn't save anything over calling new and then casting to a std::unique_ptr

      that is sadly wrong. the evaluation order of method arguments is afaik not completely specified and makes std::make_unique necessary if one of them can throw.

      foo(make_unique[A],make_unique[B]) is exception safe,

      foo(unique_ptr(new A), unique_ptr(new B)) is afaik not.

      Possible evaluation order were an exception causes leaks:

      1. new A
      2. new B //throws exception
      3. assign A to a unique_ptr //never happens A is leaked
      4. assign B to a unique_ptr //never happens B is however guaranteed to not exist anyway by new throwing an exception

      Note: used syntax only approximates c++

    24. Re:Given how C++ is taught. by david_thornley · · Score: 1

      The slowdown with shared_ptr (not unique_ptr) is that it has to maintain a reference count in a separate area of memory. With a raw pointer or unique_ptr, you've got the pointer and the memory pointed to. If you have a shared_ptr, you have a third area of memory you need to access. This can cause cache misses and similar slowdowns.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    25. Re:Given how C++ is taught. by david_thornley · · Score: 1

      Actually, there are reasons for using a naked "new", such as a custom deleter. See Scott Meyers, Effective Modern C++, end of item 21.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    26. Re:Given how C++ is taught. by IgnitusBoyone · · Score: 1

      I'll go review this, but based on your own words. I don't see how using make_unique does anything, but give me multiple strings to add to my search list for possible causes of leaks. I would rather people focus on proper heap tracking and weather they have an equivalent delete/free for each memory allocation then what method name they type to initiate an object.

      C++14 also introduced std::make_unique, which doesn't save anything over calling new and then casting to a std::unique_ptr,

      --
      Momento Mori
    27. Re:Given how C++ is taught. by rl117 · · Score: 2

      I think you missed an important concept here: std::make_unique can never, ever ever leak. It returns a std::unique_ptr<T> which will free the allocation and/or transfer ownership to another unique_ptr instance (or to a shared_ptr). At no point can it lose track of the memory it is managing for you.

      Forget about "focussing on things have an equivalent delete/free". Understand that unique_ptr does this for you. So does shared_ptr. Their whole point is to manage allocations for their whole lifetime. No more need for manual make-work or tedious checking; this ensures it's correct under every circumstance. If it's not correct it won't compile, end of story. Ownership transfer is explicit. Doing it by hand the old way is error prone because it's possible to forget; we see time and time again that programmers aren't perfect and do forget, or introduce leaks when refactoring, or misunderstand who is the owner. These smart pointers eliminate that entire class of bugs at a stroke. And they are not "new" by any means; they have been around for over 15 years in boost, in C++03 TR1 and in C++11.

      I would highly recommend taking a read of Meyers' new Effective Modern C++ book, which covers all this in detail with really good examples.

      // old
      {
          Foo *f = new Foo(); // bare pointer with no clear ownership
          f->bar(); // leak on throw
          delete f; // leak if omitted
      }

      // new
      {
          std::unique_ptr<Foo> f(std::make_unique<Foo>()); // managed unique pointer with defined ownership
          f->bar(); // cleanup on throw
      } // cleanup at scope exit

      These are equivalent. Except: I didn't need to delete f in the second case; it happened automatically when f went out of scope. And if the bar() method threw an exception, it would automatically free the memory when the stack was unwound. There are other corner cases it also protects against. And this is about as trivial an example you can get; you can do much, much more with them.

    28. Re:Given how C++ is taught. by rl117 · · Score: 1

      Also, note that the make_unique will reduce to a single new at construction and a delete at scope exit, same as if you'd done it by hand (and possibly an additional one on unwind depending upon the implementation, which the old way doesn't cater for unless you explicitly add a try/catch). If you care about exception safety at all times, they make your code massively cleaner, more readable and more robust. And it's removed the possibility for me to lose track of anything.

    29. Re:Given how C++ is taught. by angel'o'sphere · · Score: 1

      Perhaps you should explain what you want to say with this post?

      I have quite a lot variations of shared pointers implemented my self. There is nothing tricky about them actually.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    30. Re:Given how C++ is taught. by angel'o'sphere · · Score: 0

      That is incorrect: you called me an uberguru and now an ultra guru.

      Considering the fact that I have much more C++ experience than you, if I got you right you are just catching up slowly with my ~17 years in total experience, I feel flattered that you put me so far ahead of you ;D

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    31. Re:Given how C++ is taught. by angel'o'sphere · · Score: 1

      How does that work if you want to call any constructor besides the standard ctor?

      And keep in mind: shared_ptr and others of that family don't free memory in case of circular references.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    32. Re:Given how C++ is taught. by rl117 · · Score: 1

      Well, the arguments to make_unique or make_shared are passed directly to the constructor, so it will call the appropriate constructor in the class. You are not limited to the default constructor.

      And circular references aren't a big deal. In the rare event you have a data structure with cycles you can often use weak_ptr in place of shared_ptr (real example: an in-memory representation of an XML tree uses shared_ptr to implement a DAG of element objects and weak_ptr to implement arbitrary cross-references between elements, avoiding cycles of shared_ptr). If that's not possible, the worst case is that you have to manually reset() one or more of the pointers to break the cycles.

    33. Re:Given how C++ is taught. by angel'o'sphere · · Score: 1

      are passed directly to the constructor
      Then you have the corresponding "new" right there. so the claim you need no new when using shared_ptr etc. is simply wrong ;D

      Using weak_ptr together with shared_ptr to design your business model only shifts the burden from one point to the other. But I agree it might be a little bit more easy.

      Your XML tree example is a super simple one. Draw a random UML model an try to quickly decide where to use shared and where to use weak and where to use unique ptrs ... I doubt someone who has trouble crafting ctors/dtors etc. and can not decide properly where to new and delete objects has it so much easier with such ptrs.

      I used those templates mainly to express UML like relations, because I half think in UML when programming. If a ptr is unique it often makes sense to use a reference instead. But I believe they are out of fashion as well ;D

      The nice thing about Java and other languages is: I don't have to think about stuff like that.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    34. Re:Given how C++ is taught. by Anonymous Coward · · Score: 0

      I think he should explain, but he won't, because he's wrong - unless he thinks that "for that you need a 'new'" includes "for that, you need to look into the implementation of make_unique in your compiler's version of the STL and somewhere in there you'll find new! BOOYAKASHA! BOW DOWN!"

      Because he's a fucking bellend.

    35. Re:Given how C++ is taught. by DrVxD · · Score: 1

      G2P says:

      You should almost never see a new

      You claim:

      That is complete nonsense.
      At some point you have to allocate the objects/memory. And for that you need a "new".

      To demonstrate that you're wrong, I mention make_shared as an example of allocating objects without your having to see new.

      Was that really so hard to figure out?

      --
      Not everything that can be measured matters; Not everything that matters can be measured.
    36. Re:Given how C++ is taught. by DrVxD · · Score: 1

      I have explained; I'm not wrong.
      And I certainly wasn't suggesting you need to "look into the implementation of make_unique in your compiler's version of the STL".

      But hey, apart from the small detail of everything you wrote, you're completely right.

      --
      Not everything that can be measured matters; Not everything that matters can be measured.
    37. Re:Given how C++ is taught. by DrVxD · · Score: 1

      17 years? Talk about a newbie - I've been a member of WG21 for longer than that.

      --
      Not everything that can be measured matters; Not everything that matters can be measured.
    38. Re:Given how C++ is taught. by Anonymous Coward · · Score: 0

      Why "concepts"? Why not call it what it is: programming to the interface. That is already standard practice in Java and many dynamic languages do it by letting you pass in the comparison function or whatever test the algorithm needs to perform. Why the new term or am I misunderstanding it somehow?

    39. Re:Given how C++ is taught. by Dutch+Gun · · Score: 1

      If you use std::make_shared, there's a good chance the library allocates both the object and the extra block for the shared_ptr internal data in a single allocation. This not only improves allocation performance, but increases cache coherency as well. There's even ways to use custom block allocators to further improve small object allocation as well as data coherency.

      Honestly, though, if you're using a pointer, you're probably already causing cache misses (unless you're using highly specialized allocators), so just live with it and use *safe* pointers. The extra indirection won't make much a difference. It doesn't really matter if you make one jump or two - you're pretty much guaranteed to jump out of the cache anyhow. If you really need cache-friendly data structures, you need to stuff all your data into a continuous chunk of memory (i.e. std::vector) and avoid pointer indirection completely.

      The fact is, the majority of code is not performance-sensitive enough to be worrying about this. You're far better off focusing on broader algorithmic optimizations. Even in videogame programming, we don't typically worry about that sort of thing except for a very small percentage of code, typically fairly deep in the engine, such as graphics primitive processing, or in animation code... stuff like that. There's no reason shared pointers can't be used extensively throughout your codebase, and then just save the low-level optimizations for your hotspots.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    40. Re:Given how C++ is taught. by Anonymous Coward · · Score: 0

      So you're wrong. The only time I ever have to write new in my code is when the constructor has been declared private. Everywhere else, I allocate with make_unique or make_shared.

      Why is this so damned hard for you to understand? "new" is a massive red flag in our code reviews since there are next to no situations it's actually needed anymore.

    41. Re:Given how C++ is taught. by Dutch+Gun · · Score: 1

      Actually, I need to correct myself. At least in the VC implementation, the shared_ptr object itself has both a pointer to the allocated object as well as the ref-counted block (which has a counter plus a pointer to the allocated object). So that means it's zero overhead when you dereference it - that is, no more overhead than a raw pointer.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    42. Re:Given how C++ is taught. by DrVxD · · Score: 1

      Which is *exactly* the point I'm making... You very rarely (if ever) need to write 'new'.

      --
      Not everything that can be measured matters; Not everything that matters can be measured.
    43. Re:Given how C++ is taught. by Anonymous Coward · · Score: 0

      Every day must be a struggle for somebody with your lack of reading comprehension skills.

    44. Re:Given how C++ is taught. by Anonymous Coward · · Score: 0

      The point, which you fail to acknowledge here is not that there isn't keyword new being used within the make_shared statement but the fact that the make_shared takes ownership of the allocated memory block. This is the whole point-- which you seemed to have missed completely yet talk like everyone else here is stupid!

      Well done, you did show that you are ignorant and not afraid to show it!

    45. Re:Given how C++ is taught. by rl117 · · Score: 1

      I don't think anyone claimed that new and delete were no longer *used*; the point is that *you* don't use them; they are safely wrapped and managed. In the code I work on, any PR containing new or delete would be rejected unless there was a strong and valid reason for making an exception.

      And yes, my example was intentionally "super simple" because it was purely to illustrate how they can be used effectively. Creating complex stuff is obviously possible; and in fact easier than creating simple stuff. You can't create an intertwined spaghetti mess of cyclic references without having to manually cope with undoing the mess. So you need to factor that into your design; and let's be honest, it does in most cases constrain the developer to simpler acyclic structures, which is not a bad thing. If you were managing these structures manually with new and delete, the only change you'd need to make is putting a .reset() where you'd originally have the delete, so it's not like this is particularly burdensome. Also note that Java does also have weak references (WeakReference) and for largely the same reasons as weak_ptr.

    46. Re:Given how C++ is taught. by Anonymous Coward · · Score: 0

      You mean C++11, don't you? C++ existed prior to those functions being put into the STL, iirc.

    47. Re:Given how C++ is taught. by angel'o'sphere · · Score: 1

      Sorry,
      I don't see any advantage in using make_shared or make_unique over simply writing a new right there.

      Using shared pointers relieves you from the burden to know where exactly to put the 'delete' ... that is all.

      Complaining that C++ should not use new is just nonsense ... next sentence you come and proclaim all Java programmers are "mundane" because they don't know anything about memory management.

      As far as I can tell: someone who does not know how new/delete works and how to use it, does not know anything about memory management either.

      However I agree that getting away from news might lower the bar for C++ beginners. But bottom line I don't see the point. (However I don't program in C++11 or C++14)

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    48. Re:Given how C++ is taught. by angel'o'sphere · · Score: 1

      Also note that Java does also have weak references (WeakReference) and for largely the same reasons as weak_ptr.
      No, the reasons are quite different.

      A WeakReference is basically a way to be able to hold a reference in a kind of cache without disturbing the normal garbage collection.

      If an object "would" be collected but some cache somewhere still holds a reference, it won't be collected. So while the whole rest of the program assumes the object gone, it might still be found in the cache and be accessed via some "key". Putting only WeakReferences into caches prevents this problem.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    49. Re:Given how C++ is taught. by angel'o'sphere · · Score: 1

      If you would take care in reading, I stopped using C++ about 10 years ago.
      Well not really right, occasionally I d a project.

      So technically I could be a founding member ...

      Being a member is rather easy anyway, so what do you want to say with that? That you are now contributing to C++ standards.

      That is nice. Nevertheless it is unlikely that I come back to C++. It still is - and will be - mental masturbation. IMHO someone should take all good ideas of C++ and simply craft a new language. E.g. invent a keyword as replacement of C++ "static" that actually indicates what static means ;D just one idea ...

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    50. Re:Given how C++ is taught. by angel'o'sphere · · Score: 1

      Yes, that is hard to figure out.

      As I don't see why there would be any advantage using one over the other ... as far as I can tell, there is none.

      Especially if you are teacher. "new" makes clear you create a new instance. make_shared is just again something that has the wrong name and you have to read the documentation and memorize to grasp what it does ... and to really know why you should use it you have to comprehend dozens if not thousand things more in relation to a simple new.

      So: hiding news is simply a stupid idea. Hiding deletes on the other hand makes sense.

      The correct name fore make_shared btw would be either create_shared or allocate_shared, what ever you want to emphasize: creating new objects or allocating memory for them.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    51. Re:Given how C++ is taught. by rl117 · · Score: 1

      The burden of where to delete can be quite high, and in some cases intractable. It's easy in the simple case. But as soon as you start having to consider (in the context of allocation lifetime in a function or method) multiple return points and exceptions, this can become very difficult, without even considering thread safety. RAII means all these cases are handled by the language's destruction of smartptr instances on scope exit. Once you add multiple pointers with the same or differing lifetimes in nested scopes into the mix, the burden becomes even worse. This could be as simple as a continue statement in a for loop. All the try/catch blocks for every thrown exception and special cleanup for each return point add up to a huge amount of effort expended to do something which the compiler can do totally reliably, and with much more readable code. You only have to forget to handle one single exception and you have a leak. And outside the scope of a function where you need to consider ownership, ownership transfer, sharing and lifetime, there's a whole set of additional problems layered on top of what was already becoming a bit of a nightmare. And when you consider bugs introduced by future changes and refactoring, the maintenance burden and risk are vastly increased as well.

      Not sure where your comment about Java programmers came from; it certainly wasn't from me.

      I'm certainly intimately familiar with how new and delete work and how to use them. Even with that knowledge and understanding, I choose to not use them except in extremely special circumstances. My choosing not to use them is in large part *because* I understand them. Back in the '90s, use of new and delete was commonplace, but their poor interaction with exceptions and threads pre-standardisation wasn't yet completely understood, and solutions for how to handle this properly hadn't been fully developed, and this made for spectacular problems. We discovered RAII as the answer. auto_ptr (C++98) and then shared_ptr (Boost, TR1 and C++11) and now unique_ptr (C++11) are the result of our evolving understanding of how to do things correctly and robustly. The general consensus has shifted over the years strongly in favour of using smartpointers. If you read a few current books on recommended modern practice, you'll see this, and their official presence in the ISO C++11 standard library reflects this. They are *not* new; shared_ptr dates back to around 2001; I've been using it in production code since 2005.

      Ultimately it comes down to this: why do manually what can be simply and reliably automated? This is what we use computers for in the first place; not applying this logic to your own code seems illogical. What gain do you have doing things the "hard way" for little in return? The cost:benefit of using bare pointers over smart pointers is low.

      You're correct that this does lower the bar for beginners, and this is a good thing. It does make some parts of using C++ simpler. But this certainly doesn't mean it's not appropriate for experts to use as well. Real experts will know the reasons for using them. And you don't need to be using C++11 or 14 to take advantage of them; shared_ptr has been around in Boost for nearly 15 years. If you're a professional C++ programmer, keeping up to date and informed about this stuff is essential.

    52. Re:Given how C++ is taught. by rl117 · · Score: 1

      You seem to be in violent agreement with what I said. Both weak_ptr and WeakReference are a means of holding a reference to an object which may be collected when the last strong reference is lost; in both cases the weak references do not prevent collection. Both may be used for caches, as well as other purposes. Not sure why you felt the need to debate this further--it doesn't seem of any particular interest outside some uninteresting minor differences.

    53. Re:Given how C++ is taught. by angel'o'sphere · · Score: 1

      I believe we have a missunderstanding.

      I use variations of auto_ptr, unique_ptr etc. since 1993, after Andrew KÃnigs wrote some nice articles about the "STL in progress" in either the "Journal of Object oriented Programming" or the "C++ Journal". I believe the latter had a slightly different name.

      I implemented dozens of variations of "smart" pointers myself.

      My point basically was that the GP to our discussion argued that new is not needed. And more so he argued seeing a new is a mistake.

      I disagree. Basically because he put on the table the idea that you don't need dynamic memory allocation. Hiding a new behind a "make_shared" or what ever function, does not make the new get away. It is just at a different place.

      Regarding multi threading ... luckily my old C++ stuff is single threaded ... just desktop applications.

      I would never use C++ for something that need multiple threads (because I lack experience/knowledge in that, but I believe the TAO/ACE framework from Dog Smidt(Smith?) is now part of the standard library?)

      Anyway, I like your input :D

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  10. It's not about knowing, it's about understanding by rippeltippel · · Score: 5, Insightful

    Since C++ is the language of choice when you need performance (along with C and - sometimes - assembly), to write good code it's essential to understand what each line of code does to the machine (memory, registers, ...) and if/how instructions can be optimized by the compiler.

    This level of awareness is generally not required to be proficient in other languages, but in my experience it's what makes the difference between newbies and pros, at least in the areas where C++ is used for a good reason.

    Said that, it can be useful to understand as much as possible of any language and C++ can provide strong foundations in that sense, as this short article points out: http://www.forbes.com/sites/qu....

  11. Warnings by wienerschnizzel · · Score: 3, Insightful

    There is no single one thing to look for, because what you really want is EXPERIENCE with C++ programming and that encompasses a lot of things. But if you want an easy test to see if somebody has got enough experience, get some code sample that produces a lot of different warnings at compilation time and have them explain what the warnings mean and how one should get rid of them.

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

      Sure, I *could* do that. But I won't. I WON'T!

    2. Re:Warnings by Anonymous Coward · · Score: 0

      And if the person fixes all 231 warnings by adding the single missing semicolon he is guru material! The only language where compiler cries for every damn statement after a single missing statement end marker.

    3. Re:Warnings by wienerschnizzel · · Score: 1

      And if the person fixes all 231 warnings by adding the single missing semicolon he is guru material!

      In this case there would be more than just warnings - the code would not compile at all.

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

      A guru would be able to create code that generates warnings, but still compiles, when a semicolon is removed. If he can also trick you into believing that the semicolon was already there, then he is a true master.

  12. I would suggest the stl by Ambassador+Kosh · · Score: 3, Interesting

    There are many things you can use to improve your c++ code like std::vector. With that you store data contiguously in memory but you also don't have any manual memory management. No new, no delete, no malloc, no free.

    For my high performance work I tend to use std::vector, BLAS and LAPACK and my programs usually have no manual memory management of any kind in them. Valgrind shows no memory leaks and the programs are very easy to read and work with.

    If you want to do high performance c++ then learn OpenMP and MPI. If you want to do threading just use OpenMP since that makes it VASTLY easier to get threading correct. Add tasks with OpenMP along with their dependencies and you end up with a nice cross platform and very high performance code base if you have done your job correctly. If you need to scale to multiple nodes then use MPI between nodes.

    --
    Computer modeling for biotech drug manufacturing is HARD! :)
    1. Re: I would suggest the stl by fatgraham · · Score: 1

      If you want real high performance c++, don't use hacks to turn your single threaded code to MT. Use cuda and opencl2. (Both of which support a lot of c++ functionality)
      If you don't want to cross over to using external drivers, use std::futures.
      For real efficiency control other threads yourself!

    2. Re: I would suggest the stl by Ambassador+Kosh · · Score: 1

      CUDA and opencl are great for certain types of problems. If you don't have a problem that works well on GPUs then they are pretty horrible.

      For the kinds of HPC work I have been doing I get a nearly linear speedup up to 128 cpus with appropriate use of openmp.

      OpenMP is a standard and supported by all modern compilers. It works extremely well and gets rid of all the boilerplate code you would normally need with threads and gives extremely good scaling on high performance systems.

      --
      Computer modeling for biotech drug manufacturing is HARD! :)
    3. Re: I would suggest the stl by UnknownSoldier · · Score: 1

      Agreed that CUDA and OpenCL are great secondary and tertiary ways of heterogeneous multi-core programming.

      Not sure what your beef again OpenMP is. OpenMP makes it trivial to add multi-threading to your app.

      When did C++ get thread control again? Oh yeah, it wasn't until C++11 and you STILL had to wait for compilers to implement it. In the mean-time OpenMP was already here, and working for years. Considering OpenMP has been around for 18 years, calling it a hack when C++ ignored the whole standardization of multi-threading for YEARS is pretty fucking arrogant -- especially when Intel's, Microsoft's and GCC's compilers have natively supported OpenMP for years. What were Windows users supposed to use in the mean-time for portability? A port of pthreads wasn't even available for Win32 until ~2001 if this page is correct.

      There are problems with std::future as this committee paper points out:

      * N3964 (March 2014)

      Even co-routines are still relatively new:

      * N4134 (Oct 2014)

      C++11 std::thread is great for the future. OpenMP was a perfectly fine solution when C++ didn't even have one back in the day.
       

    4. Re: I would suggest the stl by Anonymous Coward · · Score: 0

      CUDA and OpenCL don't compile C++ code so you're making no sense at all here. GPU kernels are very fast but they're not "high performance C++ code". You can run the same kernel from a Python program and see little performance decrease; if you can really code your entire app in OpenCL you don't need C++ at all.

    5. Re: I would suggest the stl by david_thornley · · Score: 1

      The long gap between C++98 and C++ 11 was definitely unfortunate. The Committee has since come out with C++14, and last I looked was aiming at C++17 or so.

      However, if you use a compiler from a well-run team, you're able to use future standard features. A lot of this stuff is pretty much finalized early on, and just waits for a new Standard to slip into. Compiler teams do monitor the process.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    6. Re:I would suggest the stl by T.E.D. · · Score: 1

      c++ code like std::vector. With that you store data contiguously in memory but you also don't have any manual memory management. No new, no delete, no malloc, no free.

      ...until you add more elements that it allocated storage for, at which point it will silently do the equivalent of a C realloc() (but with copy constructors and destructors to worry about). Still, I agree that std::vector is wonderful. I use it a ton myself. You just have to know what you are doing (like with most things). If you can't deal with the realloc at runtime, either set its size large enough to avoid that in your worst ever case, or simply don't add new elements at runtime.

    7. Re:I would suggest the stl by rl117 · · Score: 1

      Now we have C++11 move constructors you should not need to worry about copying/destruction/throw on resize I would think.

    8. Re:I would suggest the stl by Ambassador+Kosh · · Score: 1

      With the type of work I have been doing additional storage is not a problem however resizing is expensive. I create all my vectors at their required size in advance in almost all cases. I think I only have a few cases where I have to dynamically expand a vector since there was no way to know the size ahead of time.

      I agree though that you could screw up pretty badly if you just create it at size 0 and then keep building it up to millions of elements. That would be horribly slow compared to the rest of the code.

      The great thing is that vectors are guaranteed to be contiguous in memory and that means you can hand them to BLAS routines.

      --
      Computer modeling for biotech drug manufacturing is HARD! :)
  13. My opinion by Anonymous Coward · · Score: 0

    Beginners can code something up, intermediates can analyze it to find resource leaks (memory, locks, ...) and segfaults, and masters can attain sought properties of a program (plain simple maintainability even when unforeseen features must be added, binary compatibilities, max. memory limits, etc)..

  14. according to this Dice article by Anonymous Coward · · Score: 0

    lolololololol

  15. according to this Dice article by Anonymous Coward · · Score: 0

    lolololololololololololol
    Slashdot is dead

  16. Re:Simple ... by Anonymous Coward · · Score: 0

    How is going from a mediocre language to a crappier language 'moving on'?

  17. Re:Simple ... by serviscope_minor · · Score: 1

    The "masters" figured after 10 to 20 years of C++ that being a master is just mental masturbation, so they moved on to .Net and JVM based languages like C# or managed C++ and Java/Scala.

    It's ironic how you accuse people of mental masturbation in a sentance that sounds likeso much wankery. I was going to correct you and point out where C++ is the superior alternative to almost everything else. I came to realise that you're not actually interested in learning. You seem more keen on letting the world know about your supposed mental superiority.

    It also sound like you're intervierwing for C++ jobs you don't want purely so you can lord it over the interviewers. Get over yourself.

    --
    SJW n. One who posts facts.
  18. Re:Simple ... by Required+Snark · · Score: 1
    I have a friend who is retired and he makes stuff in his shop. Instead of buying hinges, he makes them himself out of raw metal stock. He enjoys the challenge.

    If he was coding instead of making stuff from wood and metal, he would be using C++.

    --
    Why is Snark Required?
  19. What separates learners from masters? by janoc · · Score: 1

    Experience writing, debugging and maintaining code.

    The bucket list of having to know this and that means nothing when the programmer doesn't know how to apply it. Claiming things like the latest C++11 features (lambdas) as separating beginners from masters is just BS trying to artificially simplify the issue into something quantifiable. HR and managers love that, because it is easy to test.

    I write C++ code for over 15 years now and I can't claim that I am conversant with all those new C++11 features, like lambdas or even move semantics. I didn't need or encounter them so far in production code. The first lambda I have found was only very recently in some brand new code that is explicitly written as C++11 - and had to look up what that weird syntax was about. However, I am pretty sure I will be running circles around anyone who has just drilled themselves on the C++11 specs, but never wrote anything serious in it - I have simply seen and written so much code already that I am fluent in the language, even without knowing all the obscure features. It is the same as with learning foreign languages - you can be excellent at grammar but you still won't be able to communicate until you have to speak it for a while ...

    1. Re: What separates learners from masters? by Anonymous Coward · · Score: 0

      bingo. good software is about applying sound engineering practice

      about using qualified people instead of cheap auto-didacts. and yeah, thats unpopular.

      we all know bakers can fix teeth, correct ?

    2. Re: What separates learners from masters? by Anonymous Coward · · Score: 0

      we all know bakers can fix teeth, correct?

      Bakers bake bread, you eat bread with teeth, yep, that makes sense to a PHB!

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

    > And why the funk am I supposed to know that? Oh, easy: because you otherwise "might" shoot your self into the foot, and blow your whole leg off.

    It sounds like you failed a lot of interviews.

  21. All that being said, is there one particular thing or point that separates learners from masters?

    The ability to write code that compiles and runs correctly the first time, without memory leaks, pointer errors, and other bugs.

    How do you get that? That's easy too: write a few hundred thousand lines of complex code and debug and test it.

    1. Re:easy by david_thornley · · Score: 1

      Having written the requisite amount of complex code, my stuff often doesn't compile the first time, and rarely runs correctly the first time. I avoid memory leaks and pointer errors by using STL containers and smart pointers, which is how a novice should be taught.

      There are, by now, five ways to write error-free code. Only the sixth one works.

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

      Having written the requisite amount of complex code, my stuff often doesn't compile the first time, and rarely runs correctly the first time.

      Practice some more.

      I avoid memory leaks and pointer errors by using STL containers and smart pointers, which is how a novice should be taught

      That's the way to do it. It still takes a long time to master in C++, because there are still many ways of screwing up.

  22. Re:Simple ... by LQ · · Score: 1

    I have a friend who is retired and he makes stuff in his shop. Instead of buying hinges, he makes them himself out of raw metal stock. He enjoys the challenge.

    If he was coding instead of making stuff from wood and metal, he would be using C++.

    Except the STL provides a lot of those widgets off the shelf.

  23. There once was a clear distinction. by Sique · · Score: 1
    When people are learning a craft, there are certain levels of knowledge:
    1. The apprentice.
    2. Has little to no experience, learns the first tasks. Every step he takes has to be supervised and controlled.

    3. The journeyman.
    4. Knows how to do things, you can give him a list of task, and he will work on them until they are finished. Can supervise an apprentice.

    5. The master.
    6. Knows his trade. Knows how to organise task. Is able to split a project into several tasks he can either work on himself or give to a journeyman or even to an apprentice. Knows how to teach an apprentice. Knows how to differentiate between a well finished task and one you have to do over again.

    What we have here is the question what you have to know in C++ to be on journeyman level.

    --
    .sig: Sique *sigh*
  24. Re:Simple ... by Anonymous Coward · · Score: 0

    More like a master template ;P

    First you have to make the mold, then you have to cast the hinge, without setting the workshop on fire...

  25. Non-master by gnasher719 · · Score: 3, Insightful

    I recommend this link: http://programmers.stackexchan...

    There is someone asking whether 8 lines of slightly clumsy looking code can be replaced with something better. The beginner wouldn't ask that question and wouldn't know an answer. The master would say "your code is just fine", because it is actually straightforward, easy to understand, easy to check for correctness. The first answer on stackexchange adds two arrays, one 20 line function, and a few lines of function calls resulting in code that is hard to understand and verify.

    Now where C++ is a bit unfortunate is the fact that once you leave beginner level and think you know it all, you have unlimited potential to create code that nobody can understand.

    1. Re:Non-master by UnknownSoldier · · Score: 1

      Looks like a master did answer it; discusses a Factorial Number System, provided code, and even ended it with:

      TL:DR; You're code is already "clean" and correct.

    2. Re:Non-master by felipou · · Score: 1

      He's asking the question because the pattern occurs a few times, and he fears that it may look bad with long variable names.

      Given that, I think the current top answer (by user coredump) is a good suggestion, since it prevents duplicate code by using a function. So it basically says his code is good enough, just encapsulate it in a function (although the function name was a poor choice in my opinion).

      Also, I think the answer you refer to (I believe it's the one by user Doc Brown) is a good suggestion, although it may not be the best in that particular case. But what if all of a sudden the pattern is repeated but with more possibilities (like 4, 5 and 6 variables)? You'd need a more generic function, and this particular answer provides a step in that direction (although again I think the function and variables names were poor choices - probably because it was just an example). And he even says at the end of the answer: if you don't need a generic approach for more variables, your code is fine, and maybe you can use coredump's approach.

      Of course, my opinions reflect my thoughts about coding, mainly these: avoid duplicate code like the plague, and make some (or a lot of) effort creating the best function names possible (even though "best" is highly subjective in this case).

    3. Re:Non-master by david_thornley · · Score: 1

      The C++ language design philosophy is not to care that much whether a feature is usable, but rather whether it's useful enough and fits in well enough. If you're stupid and arrogant, you can get into all sorts trouble with C++ features, more so than with other languages. As a tradeoff, when you need to do something out of the ordinary, there's support for it.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    4. Re:Non-master by bunnyman · · Score: 1

      Could you provide a link to the "first" answer? The first answer right now does not seem to be the same answer that you are talking about. The answers are sorted by score, so the order changes when people cast votes. Thanks.

  26. Re:Simple ... by angel'o'sphere · · Score: 0

    It is a safe bet for me that I know ten times more about C++ than you do.

    I for my part wrote an STL clone around 1993 when the STL was just a lab experiment at HP.

    But I guess you will trump me in a few minutes by pointing out that you are a core boost developer.

    Perhaps you should read what I wrote: I have roughly 15 years consecutive C++ experience from 1989 till 2005, plus random 3 or 4 years over the last decade.

    I doubt you regularly find one here on /. who has significantly more C++ experience.

    And yes: I'm tired to learn every year another pitfall of C++, hence I mainly work with "easier" languages where I can focus on the solution domain and have not to struggle with the problem domain.

    Bonus point for you: figure to what that 'quote' refers. :D

    Especially I don't have to run around and wonder why young programmers make trivial mistakes in C++ ... point is: the mistakes are only trivial for a "master" ... for the noobs the code they write is obviously correct. For the compiler it is correct as well.
    But the code crashes ... why?

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  27. Re:It's not about knowing, it's about understandin by 91degrees · · Score: 1

    At this stage 'a' isn't in a register. It's a symbol that will probably be replaced by a constant 13 in a later operation, or pushed onto the stack if used as a parameter (assuming stack based calling)

  28. The C++ master by bickerdyke · · Score: 1

    The C++ master knows C, too and never forgets that he is still programming as close to the "bare metal" as with C. The only thing between him and the processor is the compiler, and no virtual machine, bytecode, or CLR runtime. C++ is a tool to write good (readable, reusable, "object oriented") C code.

    --
    bickerdyke
    1. Re:The C++ master by david_thornley · · Score: 1

      C++ is not a tool to write C code. It is a language on its own. The C++ master knows that he can program very close to the bare metal, or with abstractions, and selects the right one to do at any given time.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  29. For example ... by Anonymous Coward · · Score: 0

    know better than to use C++

    Ever heard of 'brainfuck'?

    Info @ http://www.dmoz.org/Computers/...

    Thanks to Nerval's Lobster, after Python, PHP, Java and now C++, now my brain is totally fucked

    And oh, there's even an IDE for it

    http://4mhz.de/bfdev.html

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

    Yes, in very simple words, maybe you were never a master...

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

    the code crashes because you failed to correctly pass on your superior knowledge

  32. Re:It's not about knowing, it's about understandin by rippeltippel · · Score: 3, Informative

    so, you claim you know:
    ...
    int a = 13;

    In which register a is residing, supposing we are on an ARM? Or suppose we are in an 68k? Or suppose we are on an x86?

    You are just an idiot!

    I don't claim i know, I claim that I understand: something that you're clearly neither willing nor capable of doing, as your question and offensive language suggest.

    Have a nice day!

  33. Re:Simple ... by Anonymous Coward · · Score: 0

    Yep. Java is better than C++, and java fucking sucks.

  34. Re:It's not about knowing, it's about understandin by jones_supa · · Score: 1

    Since C++ is the language of choice when you need performance (along with C and - sometimes - assembly), to write good code it's essential to understand what each line of code does to the machine (memory, registers, ...) and if/how instructions can be optimized by the compiler.

    No.

    C++ abstracts away too much for that to be useful.

    With C that kind of knowledge can be useful.

  35. Brevity by Anonymous Coward · · Score: 0

    I write C++ code since more than 10 years and I try to use it to the limits. I never wrote C. I don't always write C++. Today I wrote PHP and JavaScript for example. I wrote quite large pieces of code, and I earn a living out of this. Having those said I would comment as follows:

    1. If you are a master in C++ most probably you are just a master. You can write effective code in lots of other languages.
    2. The quality of "master" in my mind is not related to a language but to all the languages. You are master coder in fact.
    3. C++ is good as an entry point in the world of codding because of it's flexibility. A programmer has access to pretty much all the concepts invented so far in our trade. The migration from C++ to any other language tends to be way easier than the opposite migration.

    And, there is a landmark of a master:

    4. The code written by a master is easy to understand by any other guy. Including rookies.

  36. Re:Simple ... by Anonymous Coward · · Score: 0

    Only the constructor, and you can go a lifetime programming in C++ without ever having to know this. The statement is perfectly clear to anyone who sees it. If you think this is hard, it is only because you _want_ it to be hard.

  37. Masters don't play with Dice by MightyDrunken · · Score: 5, Insightful

    One of the defining feature of a non-beginner programmers is that they don't read Dice articles to find out anything about computer languages.

    1. Re:Masters don't play with Dice by Anonymous Coward · · Score: 0

      Der Herrgott wurfelt nicht!
      -- Einstein.

  38. Time by James+Durie · · Score: 1

    And lots of it

  39. Oddly by Greyfox · · Score: 1

    The HR process will grill you on C++ at a master level and yet somehow their entire production system is some Ruby abomination that has never seen the touch of a person with more than 5 years of experience in programming. They may need performance, but they're unwilling to commit to the changes required to get it. They may need a master C++ programmer, but they'll never use you to the full extent of your capabilities. And that doesn't really matter as long as they're willing to pay you like they are.

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

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

      Well, maybe it is just you. But I interviewed for C++ jobs which actually turned out to be C++ ones. As in "automatic selection of index of an in memory database".

      If they promise you C++ and then let you mainly do Ruby, that's a reason to A) complain and B) quit ASAP.

  40. Re:Simple ... by Anonymous Coward · · Score: 0

    Strange. One would expect him to write assembly, or machine code directly. At the very least, plain old C. Using C++ is the workshop equivalent of buying a finished cupboard and removing the hinge to use it for something else.

  41. Re:It's not about knowing, it's about understandin by Anonymous Coward · · Score: 0

    I agree with rippeltippel; you're being too harsh and would not work well in my team.
    At the end of the day it's all bit and bytes and concepts generally not taught in school
    but are learned from observing compiler output. Try it sometime -- gcc -S. See if you
    can follow a variable in a simple function. It's pretty enlightening. Ever wonder how C++
    "knows" where an object lives; that mysterious "this" pointer? That's how you learn...

  42. Re:It's not about knowing, it's about understandin by Carewolf · · Score: 1

    so, you claim you know:
    ...
    int a = 13;

    In which register a is residing, supposing we are on an ARM? Or suppose we are in an 68k? Or suppose we are on an x86?

    You are just an idiot!

    I know it doesn't matter, which apparently is alot more than you do.

    Btw, it might not be in any register, or even anywhere in memory.

  43. True masters... by tp_xyzzy · · Score: 1

    -true masters have their own style of writing c++ code. They don't listen to the newest silver bullets, but instead can decide themselves, which techniques to use in each situation. Masters can dodge the pressure of bleeding edge features, and focus on the requirements. They implement the simplest possible code, without any advanced tricks or newest fads, never coding themselves to a corner. They don't listen when the world screams that the code is shitty, when they know better than everyone else. Masters develop their own coding standards and conventions, distinguishing his code from the gray mass that everyone else is doing. Going against the tide is important part of being a master.

    1. Re:True masters... by Anonymous Coward · · Score: 0

      I agree with the general line of your argument, but have to add that most bosses are not capable of handling strong personalities as you describe them.

      Many artists apparently had exactly the same problems in their carees. Brown-nosing has been and is a key skill.

      But hell yeah, we would still live on trees if nobody questioned the status quo and did something amazing.

      Also, have a look at Rust and Swift. I say that as one of the initiators of both projects.

    2. Re:True masters... by UnknownSoldier · · Score: 1

      Mod parent up +1 insightful. Well said!

      As someone else pointed out in the thread Report: Aging Java Components To Blame For Massively Buggy Open-Source Software from just a few days ago (June 16):

      * "A good programmer knows when to use external libraries. A great programmer knows when not to."

      To summarize: Great programmers know how to manage code complexity. Poor ones don't.

  44. Re:It's not about knowing, it's about understandin by rippeltippel · · Score: 1

    C++ abstracts away too much for that to be useful.

    Does it? :-)

    I agree that C takes you very close to the bare metal. Yet C code is perfectly valid C++ code, and C++ allows you to achieve the same* level of control that you get in C, plus (as you pointed out) many useful abstractions that could hide what happens underneath.

    However my point is that using some of those abstractions without understanding them could have nasty effects. Just a few examples:

    • * STD lists and vectors have very different implementations in terms of memory allocation and usage (vectors are contiguous in memory and could lead to inefficient copies if their size is not managed carefully, lists are not contiguous and tracersing them may be inefficient in some cases)
    • * shared pointers are exceptionally useful, but there's an overhead in copying them unnecessarily
    • * multiple inheritance is another powerful tool, but it's easy to misuse it if you don't understand virtual inheritance

    Of course there are similar abstractions in other languages, but their implementation is often mediated by some framework/VM/etc that takes care of the shit for you to some extent. In C++ there's no garbage collector (although you can write your own) and you have full responsibility of what your code does. You can write your own tools for the job, your custom allocators, your libraries and abstractions, but you are responsible for most of it (new compilers help, thankfully).

    To write good C++ you always have to see through the code, or you'll likely end up having sub-optimal stuff (which I concede can be enough in some cases).

    * if you think that's not the case, please provide some examples.

  45. which part by nten · · Score: 1

    C++ is a decent language to choose for many types of projects, and which pieces of the language depends on which type of project that is.

    Embedded applications: There are several sets of best practice for embedded or hard real time c++, no exceptions (unbounded latency), no dynamic memory allocation (fragmentation), no dynamic casting (unbounded latency), no recursion and on and on. There actually seems to be a bit of consensus on this best practice, but it varies with the constraint of your particular system and if it needs some safety committee's approval.

    Systems programming (OS or driver): I have never read any best practice documents for this, but the code I have read all looks like C with classes. few or no templates show up I've noticed.

    Large scale performance critical stuff (games among other things): Widely varying best practice statements and all sorts of different coding, I have no idea.

    Scientific (matlab but faster): who cares, you just want the answer, not the software, right? Don't read this stuff, it hurts. but it usually works.

    I always look forward to /. c++ posts. I know I'm being clickbaited by Nerval's but its sooo fun!

    --
    refactor the law, its bloated, confusing and unmaintainable.
    1. Re:which part by MiskatonicAcademic · · Score: 4, Interesting

      Scientific (matlab but faster): who cares, you just want the answer, not the software, right?

      Not always true. Sure, there is plenty of well-motivated ad-hoc coding in scientific research. However, we sometimes have supercomputers working for months to generate the answer. Even with well-written software this could mean many core-years of number crunching. Without good high-performing software we would not get the answer at all. Developing good scientific software takes time and effort too, but if the software can be used over and over to efficiently solve >1000 problems (for instance, the GROMACS papers have been cited by users ~15,000 times), then the time invested can be very good use of taxpayer money. C++ is not a bad choice for such software in that it enables very good performance and decent maintainability.

  46. Who else stopped reading at "this dice article"? by Qbertino · · Score: 4, Insightful

    Just asking. :-)

    --
    We suffer more in our imagination than in reality. - Seneca
  47. Re:Simple ... by Anonymous Coward · · Score: 0

    Trucks are better than motorcycles. Motorcycles suck.

    That is only true when you need to transport enormous amounts of stuff.

    When the goal is to quickly transport a packet through a city, the motorbike will be better.

    Horses for courses, etc.

    Java is a nice replacement for all use cases of Cobol.

  48. Re:Simple ... by serviscope_minor · · Score: 3, Interesting

    Wow the smug condesention is strong in this one.

    I for my part wrote an STL clone around 1993 when the STL was just a lab experiment at HP.

    The hard bit about the STL is the whole concept of, well, concepts that Stepanov finally hammered out. The STL, especially 1993 era is not all that complex.

    Well, iostreams and their interaction with locales is deeply fiddly and I'd steer clear of that. But the basic algorithms, you know, vector, list, set/ma/multiset/multimap, sort, heap, priority_queue and so on and so forth are not too bad.

    Not to say it's not an achievement, but it's not enough to convince me that you're an uber-guru. I've written STL compatible containers, and STL like algorithms for things that weren't in there. Apart from quantity the principle is the same.

    Perhaps you should read what I wrote: I have roughly 15 years consecutive C++ experience from 1989 till 2005, plus random 3 or 4 years over the last decade.

    15 years experience, or 1 year of experience repeated 15 different times?

    Given you've never seen code without new in it (as your other post claimed), I'm inclined to think the latter because you seem to be deeply ignorant of whole swathes of C++ style. In a lot of code, you never see new and delete. Everything is managed by containers. I work on computer vision systems, and you can get entire working, robust systems without a new anywhere in sight. The custom containers might have a new in, but that's---well, let me check the library I'm using---let's see there's 80 instances of new in 40k lines. Of those most are in old code from before TR1 gave us many standardised smart pointers, and others could easily be replaced with a std::vector (the code's not perfect, it's been hacked on for the last 15 years), some are strange, silly uses and the rest are to initialise now deprecated auto_ptr.

    There's about one legit one which uses placement new and posix_memalign.

    With spare time, I could make that one in 40k lines of code easily. In fact that's going to happen slowly as the library is being transitioned to C++14.

    I find it terrifying that someone who pust themselves forward as a super C++ guru is splattering new so much all over the place. But you won't believe me because without knowing anything about me you've convinced yourself that you're superior.

    Let's see what a real, certifiable C++ guru says:

    http://www.informit.com/articl...

    Bjarne doesn't like new/delete either. No offence, but I'll take his invention ans stewardship of the language over your 1 year of experience repeated 15 times.

    I doubt you regularly find one here on /. who has significantly more C++ experience.

    Out of interest, do you have any T-shirts with disparaging things written about n00bs on them? And are those slogans visible under the cheeto dust?

    --
    SJW n. One who posts facts.
  49. Re:It's not 13bout knowing, it's 13bout underst13n by Rei · · Score: 1

    It's not 13bout knowing ex13ctly which register 13 is stored in, r13ther underst13nding how the compiler optimizes 13n 13lgorithm...

    Ugh, d13mmit R13ndall...

    --
    What about the Ant People? They owe us money.
  50. Re:It's not about knowing, it's about understandin by Rei · · Score: 2

    C++ lets you have just as much control over the code as C. The key difference is that it doesn't make you memory manage your objects every time, when 99.99% doing that is irrelevant toward performance and only serves as a common route to introduce bugs.

    --
    What about the Ant People? They owe us money.
  51. Re:Simple ... by locofungus · · Score: 2

    I shouldn't rise to the bait but, oh well.

    There is no single job interview where I don't have to correct the interviewer about false assumptions of how certain stuff works in C++ ...

    Any competent professional will be aware that C++ is a language so vast and with so many obscure corners that there will be corners that they would need to check to be sure and may well get wrong in an interview situation. However...

    What is called in which order? Constructor? Assignment operator? A potential cast from bla to s? Or, the copy constructor?

    And why the funk am I supposed to know that?

    The reason this question would probably asked at interview is that there is a candidate who claims to be expert at C++ who is making statements about obscure corners of the language that are probably wrong but an interviewer doesn't want to get into an argument about it. So instead they'll ask something that any reasonably competent C++ programmer would be aware of (because this syntax is a legacy of C and doesn't do what a naive C++ programmer might assume)

    It's also interesting that the really smart C++ programmers are usually quite self-effacing. They probably won't comment or will say something like "Oh, I thought it was B but I'm not sure" if they think something the interviewer said is wrong. They certainly won't be aggressive about interviewer mistakes (although any sensible programmer won't take a job where the interviewers are making to many basic mistakes in the language)

    --
    God said, "div D = rho, div B = 0, curl E = -@B/@t, curl H = J + @D/@t," and there was light.
  52. Compared to German Crafts by Anonymous Coward · · Score: 0

    The software engineering profession has a super-shitty education system. You get quite a bit of important theoretical education on the uni and you get some basic training in designing, writing and debugging software.

    BUT - the real education is done "on the job". And you might never "meet a Master" who can tell you about the "dos and donts" in a particular language, or in systems design. It is all essentially Left To Change.

    Compare that to the Azubi, Geselle, Meister system where the person is systematically educated by certified professionals. Clearly, computer science and software engineering has a shitty, irrational education system. And don't get me started about the auto-didacts. They fare even worse. Which is a major reason for shitty systems.

  53. Errata by Anonymous Coward · · Score: 0

    "It is all essentially Left To Chance"

  54. beyond a beginners level by Anonymous Coward · · Score: 0

    Dice, of course, is full of a lot of things, as well as rather pathetic. Just listing a few things
    as "the" capabilities to have is rather adolescent and amateurish.
    Knowing what is appropriate to use where and when is a better gauge.
    Being able to do the same thing with or without any of these declared "IT" things would also count.

    Past all of that there's algorithms, recursion, callbacks, event-ordering, and a touch of parallelism....

    Just my 2 cents.

  55. Simplicity by jandersen · · Score: 1

    Albert Einstein once said: 'Everything should be made as simple as possible, but no simpler'. I think that sums up the most important quality a good developer must have. It is very tempting to try to use every known feature of a programming language, and even in a simple language, the result is not pretty - C++ is far from simple, so you can imagine how ugly it can become.

    That said, to master a technology means that you are able to use the difficult features with reasonable ease, when the need arises. That includes all the reviled features in C++, such as templates and meta-programming; there is probably nothing in the language that is simply superfluous, and learning how these features are used is a good idea (and an important part of that is knowing when not to use them).

  56. Another rubbish article by Anonymous Coward · · Score: 0

    If your new recruits don't know ALL of the mentioned stuff in this article, then they shouldn't be working on your code base.
    I would REQUIRE that any developer employed at my company, even at beginner level, understand basic things like the difference between shallow and deep copies, casting, virtual functions, operator overloading, writing templates, and copy construction. You can not properly write C++ code, without at least a basic understanding of the language and of programming. All of these things are intrinsic to any C++ code base. You can not write proper C++ without understanding all of them.
    I sincerely hope that there are not people who consider themselves to be C++ developers, who do not understand this stuff.
    These are BASIC C++ skills - not intermediate level.
    Intermediate level skills might be template metaprogramming techniques, and advanced macro trickery, or a combination of the two. Intermediate level programmers will also have experience of some of the subtleties of C++. People have written multiple volumes if you don't know what these are.
    It is difficult enough to design software well. If your developers don't know how to use the language, as well as having to design programs, your projects are doomed to fail.
    I don't understand why people who have clearly never recruited a developer, or managed a software project, post this kind of rubbish.

  57. Re:Simple ... by Anonymous Coward · · Score: 0

    because you otherwise "might" shoot your self into the foot, and blow your whole leg off.

    Not really. If you code your copy constructor, empty constructor and assignment operator with the correct associativity then it doesn't matter what the compiler does in this case. And if you don't do that, there are plenty more ways for a client to fuck you up than that. The exact operation of the compiler for that case is something you don't need to know, and it's not even clearly defined IIRC (could be constructor + assignment, could be copy constructor, but since copy constructor has to be the same as constructor + assignment otherwise you're writing broken code, it doesn't matter except for a tiny bit of performance increase that might be possible if the compiler is pre-SSA.

    Just consider that the user can also write

    Something s;
    s = bla;

    and it's all pretty straightforward to realize that you have no control over what happens, so you have to actually code your class correctly for all such cases.

  58. just enough to simplify C programming not more by lano1106 · · Score: 1

    Converting C program into C++ makes you realize how much boilerplate code C++ can remove.

    constructors/destructors and replacing code using reallocs often with std::vector.

    At the end of the day, know enough C++ so that you can simplify a 500 lines, error-prime C program into an equivalent, simple to understand, 250 lines C++ and you are my C++ hero!

    I used to be a big fan of C++ until I realised how this language has so many hairy corners. When you start spending hours figuring out which feature is best to express a certain thing and have to consider all the implications of your choices, this is called mental masturbation. I prefer to focus my mental energy into actually solving problems than figuring out the intricacies of the language. The beast has become way too much complex for my taste! for that reason, I have returned back to C for the most part

    1. Re:just enough to simplify C programming not more by Anonymous Coward · · Score: 0

      Converting C program into C++ makes you realize how much boilerplate code C++ can remove.

      A big one is when your code has a lot of function pointers in structs, or switch statements based on type of data. Convert those into virtual methods and your code will be a lot cleaner.

    2. Re:just enough to simplify C programming not more by david_thornley · · Score: 1

      In C++, I focus my mental energy on solving problems with clean code. One of my rules of thumb is that, if I have to look up intricacies, the next guy is likely to also, and that's bad. I haven't even memorized the operator precedence table. If you're spending hours figuring out which feature to use instead of getting the job done, you're doing it wrong.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  59. Something missing: by Anonymous Coward · · Score: 0

    Experience.

  60. Weekly dose of how much X do you need to Y by Anonymous Coward · · Score: 0

    Why write different articles that say the same thing? Just post the same one about how much X do you need to know Y each week instead of these permutations.

  61. I could tell you... by Anonymous Coward · · Score: 0

    But then I would have to kill you.

  62. Re:It's not about knowing, it's about understandin by Anonymous Coward · · Score: 0

    Bullshit.. C is incredibly inefficient. Why, I get own down in there and optimize my NOPs, and I funroll loops!

    wait.. wait..

    Assembler is bullshit.. I get on down in there and optimize that microcode!

    sorry.. couldn't resist...

  63. The same thing as every other language by NotSoHeavyD3 · · Score: 1

    Being able to write readable code. It's a very rare skill.

    --
    Did you know 80 to 90% of the moderators on slashdot wouldn't recognize a troll even if one dragged them under a bridge.
  64. Learn your trade by Anonymous Coward · · Score: 0

    Get a copy or pdf of Stroustup, 4th Ed. You should become very familiar with the pitfalls and advice Effective C++ by Meyers, and Exceptional C++ by Sutter. Programming the examples in Gamma et al. Design Patterns is useful. Become familiar with Large Scale C++ Software DEsign, by Lakos. Most people still make a mess with physical design. Use a unit test framework like CppUnit or Google for everything you write. Be literate. I see a lot of garbage come from non-native English speakers

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

    A somewhat related question is, what do you do when an interview candidate is scheduled to be there all day, but the first two interviewers report that s/he completely lacks the technical skills needed to do the job? Escorting him or her off the premises early would be rude, on the other hand, you don't want to waste the time of valuable engineers.

    One trick I've seen is to replace senior engineers with new hires and interns in the interview chain, just to give them experience. Coach the interviewers to sell the heck out of the company. At the end of the day, the candidate is given an enthusiastic sendoff along with "We'll be in touch with your recruiter."

  66. Readable and maintainable code by snake_case_hoschi · · Score: 1

    C++ is a multi paradigm language, which allows to use low-level and high-level features. The art of coding in general is writing readble code, which uses the offered features wisely.

  67. 'static' by Anonymous Coward · · Score: 0

    My threshold for non-beginner knowledge of C++ is knowing how many distinct meanings there are for the keyword 'static'.

    I can count 4.

  68. Re:It's not about knowing, it's about understandin by jones_supa · · Score: 1

    Which is in line with my comment: when the programmer uses proper highly-abstracted C++ mechanisms, micro-managing knowledge is not useful.

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

    Congrats, you clearly have the bigger C++ e-penis in this case.

  70. Re:It's not about knowing, it's about understandin by jones_supa · · Score: 1

    Good points. You convinced me that it actually might be beneficial to know what happens under the hood even with C++, to write professional code.

  71. Re:Simple ... by serviscope_minor · · Score: 3, Funny

    Congrats, you clearly have the bigger C++ e-penis in this case.

    That's probably the most common type of logical phallusy.

    --
    SJW n. One who posts facts.
  72. The dichotomy by FithisUX · · Score: 1

    The learner is stuck in an infinite loop to learn C++. the master aborts and retries with D.

  73. Learn your trade is not enough by Anonymous Coward · · Score: 0

    This whole thread reeinforces the idea that programming is just a trade.
    I certainly don't want to depend on code written by folks who just want to learn the minimum reqiured to get paid.
    Progamming should be a craft to which one aspires to be excellent.
    Folks who do this should have no trouble both earning a living and having fun.

    For the folks who understand this and just want to get bootstrapped:

    A good lesson for anybody is
        How to make a hard problem simple and not the reverse.

    Basic things any programmer should know include:
        What is a computer, a program, a tool chain, a source repository, a library, a variable, a function, scope, syntax.
        Where do you go to find an example of something and how to get it running in your environment.

    For C++, the first skill seems to be knowing how to look up yet another feature in Stroustup.
    The second skil seems to be gathering enough experience to have the judgement to know when not to use yet another feature.

    For C and C++, not understanding pointers seems the first intermediate failure mode.
      Althought C++ constructors give pointers a close race.

  74. I stopped trying to know all of C++ by DoofusOfDeath · · Score: 1

    I started playing with C++ when I when into college in 1991. At one point I probably would have qualified as more or less a C++ expert. Then, as the language grew more and more insanely complex with each revision, I stopped trying to keep up on the whole language.

    Nowadays I'm content to just make sure I understand the subset I normally use, read up when I come across a part I don't use, and ignore the rest. For my own programming, at least, the language has simply become too complex to be worth mastering.

    1. Re:I stopped trying to know all of C++ by david_thornley · · Score: 1

      Modern C++ is simpler to read and write than the stuff you learned in 1991. If you're still using C-style arrays and strings (which is what was done back then), you're doing it wrong.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  75. Here we go again ... by gstoddart · · Score: 2

    And, once again, Nerval's Lobster gets a piece accepted which is little more than a thinly veiled reason to link to one of the endless stream of lame stories about "how much toilet paper do you really need" articles.

    Have you guys become so blatant with the click-whoring to Dice you have designated people who write pithy sounding summaries for repetitive and lame articles to drive to Dice.com?

    Because there are suspicious amount of lame "how much do you" articles submitted by this one poster, and all linking back to Dice.com. And never a mention that Dice.com is the parent company and is shamelessly shilling their own crap.

    Sorry guys, but you're becoming really obvious with this.

    --
    Lost at C:>. Found at C.
  76. How many limbs do you have left? by Anonymous Coward · · Score: 0

    Heard this quote years ago: "C lets you shoot yourself in the foot. C++ does also, but when you do it takes your whole leg off."

    I'd say the best answer is simply experience. Know where the land mines are and what is required to avoid them--usually by having struck some before.

  77. The masters... by Anonymous Coward · · Score: 0

    ... have moved away from C++ to a more sane language :)

  78. Re:It's not about knowing, it's about understandin by Anonymous Coward · · Score: 0

    For instance, declaring a loop variable as "for (uint8_t i = . . .". On an 8051 this might be good, but on a 32-bit CPU the compiler may have to generate extra code to scale it to 32 bits whenever it is used. And it's not saving any RAM, because it probably won't ever live on the stack with even minimum optimization turned on, since 32-bit CPUs tend to have a lot of registers.

  79. The simple answer is by Anonymous Coward · · Score: 0

    A full time job.

  80. First step by Anonymous Coward · · Score: 0

    The first step beyond beginner level, for any coding language, test your fucking code!

    I've seen so many times, beginners who make: just a small/trivial change to somebody else's sloppy code because they think they're smart enough to clean things up, manage break shit for everybody else because they didn't test their change. Then somebody else has to spend hours to fix that bullshit.

  81. oh good lord by sribe · · Score: 1

    If you don't know about copy constructors, when & why to use them, you're not even a beginner.

  82. Masters are still learning by davidwr · · Score: 1

    is there one particular thing or point that separates learners from masters?

    I think you mean "what separates those who are still early in their learning from those who have pretty much mastered the topic."

    As anyone who has "mastered" any topic of significant depth will tell you, there is always more to learn.

    --
    Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
  83. Scope by fkodama · · Score: 1

    All that being said, is there one particular thing or point that separates learners from masters? Knowledge of public well known libs, how to overscope and underscope legacy code without touching it keeping it manageable.

  84. Debugging pointers ... by arit · · Score: 1

    If you can debug a generic memory leak or bounds overrun (which might not cause a crash until long after the breach), then you are no longer a beginner.

    1. Re:Debugging pointers ... by david_thornley · · Score: 1

      If you're a C++ beginner, and know how to use smart pointers and STL containers, you're not likely to have a memory lead or bounds overrun.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    2. Re:Debugging pointers ... by arit · · Score: 1

      Right ... but then you're still a beginner.

  85. Memory Leaks? by Capt.Albatross · · Score: 1

    If you don't understand memory management then you are not yet a C++ programmer, let alone an intermediate one.

    In my experience of interviewing, I have spoken to many alleged C++ programmers who can give a textbook definition for the terms 'copy constructor' and 'assignment operator', but who have no idea of their purpose, and their role in resource management. Unfortunately, I do not need to imagine the sort of code they write, because I have seen it.

  86. Unethical by Anonymous Coward · · Score: 0

    You are thinking like a manager.
    As a programmer, I don't want to be replaced easily, and I don't care about my work when I'll die, or even when I quit my company.
    I have no problem to share my knowledge with my co-workers, but why should I write code for somebody who'll replace me ?

    Software Engineer Code of Ethics

    Your own insecurities related to job security are compromising your ethical values.

    When a system you build fails or costs more to maintain than it really should all because you are scared of losing a job, you are not providing the value to your project or society that the profession demands and reflects negatively on everyone here. Don't ever call yourself a professional, don't comment on the matter, and quite frankly, get the hell out.

  87. Good and Bad by cozytom · · Score: 1

    Much of the modern C++ dialects seem to be a winner. Certainly smart pointers and templates can be good, and are an improvement over the older C++ concepts. C++11/14/17 add features that make writing broken code harder.

    Like anything, with much power comes much responsibility.

    Lambdas and templates when overused make debugging next to impossible. I was working on some code that was so far nested in a bunch of templates, I couldn't use GDB to make any sense of it. Eventually I tore apart the templates to find a small bug in one of them.

    Also the G++ compiler errors don't often point to anything meaningful. Missing a semicolon can result in a paragraph of errors, one may point at the actual error.

    Don't get me wrong, I really appreciate C++, but you earn your pay using it.

  88. Re:It's not about knowing, it's about understandin by david_thornley · · Score: 1

    In either case, once you turn the optimizer to high you don't know what's going on under the hood.

    --
    "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  89. How to become a master? by tlolczyk · · Score: 1

    1) Read all of Scott Meyer's books. Not all of the rules in the old books apply anymore, but a lot still do, and they are not covered in his new books. 2) Go to https://www.youtube.com/result... pick out the videos you like and especially focus on Bjarne Stroustrup, Scott Meye, Herb Sutter, Nico Jousittis. Watch them. Look for other videos ( believe me there are more then you can watch in a lifetime unless you're a C++ superwaonk ) from other conferences. 3) Be familar with the newer concepts: variadic templates, perfect forwarding, move semantics, and concepts (lite). 4) Of course you have to have done some programming touching these things, but Scott Meyer's IIRC has never written programs. Finally, if there is something that needs to be done: for example, writing a specialized template library; and you balk because you do not have the basic knowledge needed to write that, then you are not a master.

  90. Efficiency is still important. by tlolczyk · · Score: 1

    Yes writing in C++ ( or even C ) is more expensive, but programmer cost is no longer the biggest factor in cost. Every cycle more needed by a program needs so many more milliwatts. Every cycle more generates so many calories which require so many milliwatts of airconditioning. Add enough and it really costs a lot. If you are writing for Android, it may mean that the Galaxy Tab 3 is not good enough to run your code, which means so many customers lost. Etc. It really has always been this, Moore's law just did a good job of obscuring the fact.

  91. What is truth by Anonymous Coward · · Score: 0

    From generic to specific, beginning to end. When you have a clear path the details fill themselves in. When you write, filling in the abstract concepts give flesh to inner methods, and code tends to become closer to self-documenting. This is also a critically important concept.

    Someone wrote above that a master can write code a novice can understand. This is truth, because mastery is shown through clarity.

    There are other truths; there is no quantitative or binary representation -- no master or novice, good or bad -- only qualitative. Even a novice can write the code of a master, and even be indistinguishable if the novice knows his way.

  92. The best C++ programmer is a C programmer.... by senedane · · Score: 1

    IMHO the best C++ programmer is the one that stays away from C++. When performance is a concern, C is the obvious tool of choice. If OO and speed of development are important, I'd opt for Java or Python any day over C++.... As a kernel engineer I may be a bit biased, however...

  93. master C++ by reaching C by Anonymous Coward · · Score: 0

    As for me, my path has been from C++ to C.
    In particular many in the university environment, including computer science professors and would be phd - entrepreneurs, there is a lot of over-excitement about language features, and C++ provides a stream of new features almost each year. That leads to really bad, unmaintainable software, done with total disregard for good software engineering practice that comes from, well, practice.

    I learned the advantages and pain points of the C++ features, and mostly abandoned most of them with time, until what I was left with was pretty close to C,
    and that's where I abandoned C++ for good for my use cases.
    Your mileage may differ, but knowing when _not_ to use C++ features is the key distinguishing element you are looking for I think.

    1. Re:master C++ by reaching C by Bent+Spoke · · Score: 1

      Master C++? What an oxymoron. It is quite difficult to master C, even though it is 1/10 (1/100th) the complexity of C++.

      People that are smart enough to master C++ are probably too smart to get sucked into doing lowly programming for a living.

      And yes, I have 30+ years of C coding experience, so I guess that makes me a moron.

  94. Master a limited subset by Dixie_Flatline · · Score: 1

    It's really hard to master the entirety of C++, so you're better off knowing just a meaningful subset of it. Go and pick up Effective C++ and the sequel—they're basically just filled with the pitfalls of C++ to avoid and some decent things worth knowing. That's the stuff that tends to show up on C++ interviews. There's basic stuff in there and less basic stuff, but all of it is useful.

    My company has a course on advanced C++ and C++ pitfalls, and even after 15 years, some of them caught me. Lots of them did, really. It was interesting because the room had a dozen or so programmers, and we all fell for completely different things.

    C++ gives you a lot of rope to hang yourself with. The trick to using it well is to limit how much rope is around your neck at any given time—never do something cleverly that can be done simply, even if the simple way takes up a few more lines.

    Oh, and comment your damn code. I don't care what language you're in, you're not a master of it until you know how to leave a trail of comments that even a new programmer can follow. When you're on your third 18-hour day, you have an imminent deadline and you're starting to go crosseyed, you'll either love or hate yourself based solely on the amount of good comments you left in your code. Things that are obvious when you're awake and well rested become muddy when you're tired and hungry and want to go to bed.

  95. A recent experience. by tlolczyk · · Score: 1

    I had to look at the code for dbus. I found some "interesting" things. The first is DBusString and DBusRealString. One is effectively a String class. The other is a wrapper for the first class, that for some reason hides it's content. The second thing is something called something like DBusList, a linked list of generic pointers.

    I can't say for sure, but I suspect that I could have replaced large chunks with C++ been slightly more efficoent. Just by a few simple tweaks which were obscured by all the extra verbiage and need to make sure such "localized" libraries were correct.

    Hell, as I started to write this, I realized one major inefficiency. In C++ it would have been written using "vectors" contiguous array that are resizable instead of linked lists. This would make a big difference. Advancing the iterator to a linked list involves dereferencing a pointer. Advancing the vector iterator involves incrementing a pointer. A major difference as the majority of the time the link list increment will involve a cache hit.

    So it seems a C++ version of dbus would be much faster then the C version.

    As for readability. If you insist on readablity for all "programmers" then you wind up with the piece of shit that is the Google C++ coding standard. An intermediate C++ programmer will be able to understand, a highly intelligent beginner would. Someone who indulges in stupidity would not. If you see something like MyClass(MyClass &&my_class_in) and change it without knowing what it does, assuming it is wrong ( nevermind that it does compile ) you will get into trouble.trouble. I have a simple philosophy, I use any tool in C++ to organize the software as well as possible. Everuthing else follows from that.

  96. Re:Simple ... by dlingman · · Score: 1

    or manage to proceed without collapsing the workshop, cause your iron ore was located under your workshop, so you started digging at the side...

  97. Re:Simple ... by angel'o'sphere · · Score: 1

    And that is why I call sticking to C++ "mental masturbation".

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

    Of those most are in old code from before TR1 gave us many standardised smart pointers, and
    And
    The custom containers might have a new in, but that's---well, let me check the library I'm using---let's see there's 80 instances of new in 40k lines.
    Wow, you want to argue about the amount of "new"s per kLOC? Do you really believe that makes any sense?

    At some point you have to instantiate your business objects. Regardless what they are.

    The only way around real need for new is to have all memory statically allocated.

    So the argument how many news and deletes are around makes not much sense.

    Every Smart Pointer is initially initialized via a new.

    Given you've never seen code without new in it (as your other post claimed),

    I did not claim that. I have plenty of source files that have no new, nevertheless the whole program has a lot of news. Well, actually as I mostly use prototype based factories the news are centralized and they are bottom line few.

    convince me that you're an uber-guru You pulled this out. I'm just an ex guru who is stuck with 10 year old C++ standards and thus my knowledge is declining and regarding C++11 outdated ;D

    But that is half what I want ... when I do C++ in our days I stick to Qt and occasionally embedded programming. Real business logic should be done in a safer easier to use language, and I'm tired about the "who knows more about C++" pub talks :D

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  99. Re:It's not about knowing, it's about understandin by angel'o'sphere · · Score: 1

    Erm, perhaps you should learn to read.

    The parent claimed a good C++ developer can tell from every line of code, which registers are affected.

    Which is clearly nonsense.

    However: show me the trick how such a variable may not be "anywhere in memory" ... nice try.

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  100. Re:It's not about knowing, it's about understandin by angel'o'sphere · · Score: 1

    You did claim that.
    And there is not much to understand about those lines.

    Obviously you have a mental problem, or why do you offend me by calling my language offensive?

    Is that a new fractal approach to discussion or simply a misplaced double recursion?

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  101. Re:It's not about knowing, it's about understandin by angel'o'sphere · · Score: 1

    On a SPARC processor it would most definitely be in a register ... read about register windows and such.

    The first 8 local variables in a function are in registers, so are the first 8 parameters to the function.

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

    Real business logic should be done in a safer easier to use language, and I'm tired about the "who knows more about C++" pub talks :D

    Didn't stop you from starting one.

  103. Re:Simple ... by angel'o'sphere · · Score: 1

    That question is actually rarely asked.

    It was more an example for the "complexity" of C++ that might occur in a single line of code.

    The funniest supposedly difficult question was about the size of byte, char, short, int etc. in Java and char, short, int etc. in C.

    I found that question retardedly silly and when I worked for that company in the end I met the interviewer and asked why he asked something so simple.

    The answer was: I was the only one out of ~ten interviewed persons who answered this simple question instantly and correct.

    When I point out an error of the interviewer (usually it is in his papers and not an error by himself) I'm obviously polite. But I'm also resolute. I take crafting software serious and being certain about facts and avoiding mistakes/defects is very important to me.

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  104. Re:It's not about knowing, it's about understandin by Anonymous Coward · · Score: 0

    However: show me the trick how such a variable may not be "anywhere in memory" ... nice try.

    Easy: if the object 'a' is not used it won't need storage. If the object is only read from the compiler can easily detect this and fold it into a constant. One manifestation of a constant variable in generated machine code is that it is part of instruction encoding. Depending on the architecture this may not take any extra storage or the encoding schema may vary depending on the constant magnitude.

    In compiler theory, dead code elimination (also known as DCE, dead code removal, dead code stripping, or dead code strip) is a compiler optimization to remove code which does not affect the program results.

    Dead code elimination - Wikipedia, the free encyclopedia
    https://en.wikipedia.org/wiki/Dead_code_elimination

    These are part of the easy bits, bro. You shouldn't outright dismiss ideas you don't grasp immediately. p.s. I don't like you or your bad attitude

  105. Re:It's not about knowing, it's about understandin by Anonymous Coward · · Score: 0

    You are moving the goalposts.. your one-liner did nowhere mention that the object was one of the first 8 local variables. I don't see any code accessing the object either by reading and/or writing to it either.

    It's not exactly rocket-science to grasp how simple statements could be translated into machine code. Expression trees are very popular mechanism for the translation process. When object is written into, the expression is stored in a tree and the leafs are transformed into instructions. The trick is to do this within a limited budget. SSA is very popular presentation and dynamic programming is usually a good starting point to get things moving forward.

    The tree for your statement would look like this:

    a - 13

    Very simple, no? I don't see object 'a' being a leaf in any other expression, therefore it will be eliminated. As a machine I can exhaustively comprehend that object of type 'int' will not have any side-effects when omitted from code generation; e.g., it does not have any code associated with it that should be executed.

    Therefore, I am unable to agree with you that the object would 'definitely be in a register' on a SPARC, or any other architecture for that matter, assuming the compiler is not completely brain-dead idiomatic piece of garbage.

  106. Re:It's not about knowing, it's about understandin by Anonymous Coward · · Score: 0

    Nice example of the Straw Man logical fallacy; good job!

  107. Re:Simple ... by Anonymous Coward · · Score: 0

    Of all the people to reply, you're not the one I'd expect. You cant start an e-peen war, get out e-peened, then join in the fun laughing at people with epeen insecurity problems.

    C++ is more like "artificial cow insemination". Somebody has to do it!

  108. Simple by Anonymous Coward · · Score: 0

    Debugging
    Logging
    Profiling
    Leak tests
    Unit/Integration tests

    and most importantly, readability.

    read your own code a month after you left it alone, is it readable?
    how much time did it take you to figure out what you did last time?
    how simple is it to follow the logic?
    how simple is it to add new functionality?

    and finally, how simple is it to shoot your own foot with what you wrote?

  109. Re:Simple ... by serviscope_minor · · Score: 1

    Excuse the lack of quoting, on phone.

    First, business what now? There is so much more to C++ than that. I doubt I've encountered one this year. But when I do, they can either be shoved into a container, or instantiated with make share or make unique.

    There's no need for new anywhere.

    But it seems like you're massively misinterpreting what I say as no news happen under the hood. Certainly they do, but they're all safely hidden away, so lifetime is managed cleanly and safely for you. Not sure how you came to that conclusion, but whatever.

    And dude, if you call yourself an ex guru, you're implying that you think you were a guru. It's rather tacky to describe oneself as such, not to mention lacking in credibility. Stroustrup and etc never call themselves gurus.

    --
    SJW n. One who posts facts.
  110. BLAS and LAPACK are libraries. by stoicio · · Score: 1

    BLAS and LAPACK are libraries.

    You need to differentiate between the dynamics of a language (ie: FORTRAN vs. C/C++) and the libraries available.

    FORTRAN 77 vs. FORTRAN 90/95 and up are completely different species.

    So we start talking about eigen systems programming in one language vs. another. Well, when was that library written? In what version of what language? Just because it is a widely available library, does that mean it is any good internally?

    Theoretically, if there were a fully C++ written linear algebra (or any other library) that isn't linked with some gawd aweful old FORTRAN code or (asm{ ... }) down in the bowels of the machine, then you could make an honest comparison. But since everyone seems to start off with poor examples from free programming cook books and someones opinion from the web, without seriously (re)designing or understanding the patterns used to accomplish the task, you then get what you get (ie: crap).

    After long time programming in FORTRAN 77/90/95/etc. and C, and C++, and many other languages I would have to say that most programming comes down to energy expenditure. If a grad student comes out of school after programming mainly in Matlab the first thing that person is going to suggest for a programming project is going to be Matlab. This same phemomenon is what has kept FORTRAN alive. In the case of FORTRAN , the legacy dependency code of many scientific applications ultimately led to the refactoring of FORTRAN as a language rather than discarding all that code. It amounts to loss aversion and an unwillingness to learn new languages in entrenched users.

    Why not create an open scientific co-processor card spec that has hardware advanced functions instead of farting around with GPU discretes that were originally designed for video games. Then we could just have linear algebra calls in the standard math library that are driven by math hardware instead of 50 years of accumulated CPU work-arounds for 8088 code (that was sarcasm).

    Progamming always seems be 'VHS instead of BETA' because most programmers doing applied programming for science arrive in industry with only single language skills and programming was only a sideline from whatever thier degree was in.

    I also continue run into 'C' programmers who refuse to learn C++ . it's some kind of religion thing. Deities will apparently smite them if they crack a manual.

  111. You're a selfish asshole by Anonymous Coward · · Score: 0

    As a programmer, I don't want to be replaced easily, and I don't care about my work when I'll die, or even when I quit my company.

    So you're a selfish asshole. Got it. That advice is meant for people who actually give a fuck about anything other than their own petty selves.

  112. Re:It's not about knowing, it's about understandin by 91degrees · · Score: 1

    Yes, so? If I was using a SPARC I'd be assuming register based passing.

    If it was to be used in a calculation, and the architecture doesn't have operations on constants then I'd know it would go into a register. I wouldn't know which register, but that wasn't the point. The point is knowing it will be stored in a register. In the case of a SPARC, and if we're using it as a function parameter, and if there are fewer than 8 parameters, and if the parameters are all simple types, then it will be stored in one of the upper 8 registers in the window, and a competent programmer with low level SPARC experience will be able to tell you exactly which.

  113. Re:It's not about knowing, it's about understandin by angel'o'sphere · · Score: 1

    No, you miss the point completely.

    The GP claimed a good C programmer can tell from every line of code (C code!) which registers of the processor are affected.

    Which clearly wrong. No one knows that. Not even on a SPARC or Power PC where C code to register mapping is pretty straight forward.

    And you are now running of into the wild arguing for the arguments sake.

    and a competent programmer with low level SPARC experience will be able to tell you exactly which.
    Wrong! Every programmer who gets an introduction how SPARC register windows work, will grasp that immediately. No special "I'm a super competent programmer" skill is needed. That is exactly my point. People should simply stop to claim that a C programmer is by definition more competent than any "non C programmer".
    They are not ... they are simply stuck behind on portable assembler and often have no clue about any higher level architecture or language concept ... regardless what language or architecture.

    Then they come and claim: "look at that! I know in what register that variable goes, you don't!" And how relevant is that exactly for 'what'?

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

    I did not call my self an ex guru, some idiot called me an "uber guru" and I told him, I was perhaps once a guru. Long ago.

    It does not matter how you call yourself, the question is what you are :D

    I never call myself a master in martial arts, however I am ...

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

    I never call myself a master in martial arts, however I am ...

    you just did.

    --
    SJW n. One who posts facts.
  116. Re:Simple ... by angel'o'sphere · · Score: 1

    If you think so :D

    I don't think that pointing out a fact to another person falls into "calling yourself something" .

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

    I don't think that pointing out a fact to another person falls into "calling yourself something" .

    Ah, so it's a fact that you are/were a C++ guru, eh? So my man, what precisely defines guru that makes such thing a fact? Calling yourself a guru is akin to insisting your nickname is Mr Awesome.

    --
    SJW n. One who posts facts.
  118. Re:Simple ... by angel'o'sphere · · Score: 1

    Er, you seem to lack reading skills.

    I did not use the word guru about my C++ skills before someone called me mockingly an "Uber Guru" and I made perfectly clear that I once "perhaps was a Guru" but don't feel like that anymore ... after all I stopped using C++ hard core around 2000 and afterwards only used it it from time to time.

    But seems you are obsessed with that word :D

    As long as I can still show the youngsters how stuff works I definitely don't feel "underquallified" regarding C++. though.

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.