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?

223 of 345 comments (clear)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    31. 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."
    32. 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???
    33. 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.

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

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

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

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

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

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

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

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

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

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

    46. 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.
    47. 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.

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

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

    50. 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 !

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

    52. 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
    53. 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.
  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: 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. ;)

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

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

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

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

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

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

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

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

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

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

    25. 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.
    26. 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.
    27. 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.
    28. 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.
    29. 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.
    30. 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.
    31. 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.
    32. 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.

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

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

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

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

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

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

    7. 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! :)
  9. 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.

  10. 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.
  11. 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?
  12. Re:Experts... by jones_supa · · Score: 1

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

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

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

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

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

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

  19. 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
  20. Re:Experts... by Anonymous Coward · · Score: 1

    I would rather say that about Ada.

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

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

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

  25. Time by James+Durie · · Score: 1

    And lots of it

  26. 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?

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

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

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

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

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

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

  32. 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.
  33. 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
  34. 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.
  35. 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.
  36. 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.
  37. 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.
  38. 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"

  39. 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.
  40. 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).

  41. 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 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
  42. 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.
  43. 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.
  44. 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.

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

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

  47. 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.
  48. 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.
  49. The dichotomy by FithisUX · · Score: 1

    The learner is stuck in an infinite loop to learn C++. the master aborts and retries with D.

  50. 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
  51. 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.
  52. 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"

  53. 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?

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

  55. 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.
  56. 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.
  57. 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.

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

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

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

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

  62. 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
  63. 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

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

  65. 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
  66. 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
  67. 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.

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

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

  70. 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?

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

  72. 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
  73. 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.

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

    Bzzt. Dollar sign is a gcc extension.

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

    And MSVC as well.

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

  77. 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.
  78. 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.
  79. 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.
  80. 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.
  81. 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.
  82. 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

  83. 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.
  84. 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."
  85. 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.

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

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

  88. 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?

  89. 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.
  90. 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.
  91. 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.

  92. 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?

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

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

  95. 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.
  96. 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.
  97. 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.
  98. 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.
  99. 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.
  100. 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.
  101. Re:Experts... by Foresto · · Score: 1

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

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

    Yep, technically you are correct.