Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Programming IT

Knowing C++ Beyond a Beginner Level 345

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?
This discussion has been archived. No new comments can be posted.

Knowing C++ Beyond a Beginner Level

Comments Filter:
  • by perpenso ( 1613749 ) on Tuesday June 23, 2015 @03:12AM (#49967893)

    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.

    • by Ihlosi ( 895663 )
      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).

      • by TheRaven64 ( 641858 ) on Tuesday June 23, 2015 @06:07AM (#49968393) Journal

        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.

    • by PolygamousRanchKid ( 1290638 ) on Tuesday June 23, 2015 @03:44AM (#49967985)

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

      • by eulernet ( 1132389 ) on Tuesday June 23, 2015 @05:32AM (#49968285)

        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.

        • by Anonymous Coward on Tuesday June 23, 2015 @05:50AM (#49968343)

          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.

          • by eulernet ( 1132389 ) on Tuesday June 23, 2015 @07:28AM (#49968657)

            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.

            • by evenmoreconfused ( 451154 ) on Tuesday June 23, 2015 @08:46AM (#49969019)

              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.

            • by Xenna ( 37238 )

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

        • by TheRaven64 ( 641858 ) on Tuesday June 23, 2015 @06:09AM (#49968395) Journal
          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?
          • by eulernet ( 1132389 ) on Tuesday June 23, 2015 @07:13AM (#49968613)

            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 ?

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

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

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

        • by Actually, I do RTFA ( 1058596 ) on Tuesday June 23, 2015 @09:30AM (#49969369)

          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?

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

    • Re: (Score:2, Insightful)

      by AmiMoJo ( 196126 )

      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.

      • by serviscope_minor ( 664417 ) on Tuesday June 23, 2015 @06:16AM (#49968443) Journal

        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.

    • 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 sys

      • Re:which part (Score:4, Interesting)

        by MiskatonicAcademic ( 2620997 ) on Tuesday June 23, 2015 @06:15AM (#49968429)

        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.

    • by Rei ( 128717 )

      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,

    • by hsa ( 598343 )
      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..
    • by rioki ( 1328185 )

      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

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

  • by vux984 ( 928602 ) on Tuesday June 23, 2015 @03:14AM (#49967901)

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

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

  • Error Handling (Score:5, Insightful)

    by oggiejnr ( 999258 ) on Tuesday June 23, 2015 @03:28AM (#49967925)

    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.

    • Re:Error Handling (Score:4, Interesting)

      by Ambassador Kosh ( 18352 ) on Tuesday June 23, 2015 @04:41AM (#49968165)

      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.

  • by serviscope_minor ( 664417 ) on Tuesday June 23, 2015 @03:31AM (#49967933) Journal

    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.

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

      • by DrVxD ( 184537 )

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

      • 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 librar
  • by rippeltippel ( 1452937 ) on Tuesday June 23, 2015 @03:32AM (#49967935)

    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... [forbes.com].

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

      • by Rei ( 128717 )

        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.

        • Which is in line with my comment: when the programmer uses proper highly-abstracted C++ mechanisms, micro-managing knowledge is not useful.
  • Warnings (Score:4, Insightful)

    by wienerschnizzel ( 1409447 ) on Tuesday June 23, 2015 @03:32AM (#49967939)
    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.
  • by Ambassador Kosh ( 18352 ) on Tuesday June 23, 2015 @03:33AM (#49967943)

    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.

    • 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!

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

      • 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 [cppreference.com] 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

  • 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 l

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

  • 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

  • Non-master (Score:4, Insightful)

    by gnasher719 ( 869701 ) on Tuesday June 23, 2015 @04:42AM (#49968169)
    I recommend this link: http://programmers.stackexchan... [stackexchange.com]

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

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

  • by MightyDrunken ( 1171335 ) on Tuesday June 23, 2015 @05:14AM (#49968237)
    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.
  • 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.
  • Just asking. :-)

  • 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

  • Being able to write readable code. It's a very rare skill.
  • 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

  • by gstoddart ( 321705 ) on Tuesday June 23, 2015 @09:22AM (#49969315) Homepage

    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.

  • If you don't know about copy constructors, when & why to use them, you're not even a beginner.

E = MC ** 2 +- 3db

Working...