+ 1

Any tips for c++ beginners?

I have just started c++ , it looks a bit complicated . Can you help me and give some tips for beginning with c++ .

1st Apr 2018, 10:51 AM
Majestic Ayush
Majestic Ayush - avatar
2 odpowiedzi
+ 4
Readability is a tricky thing, and involves several aspects: Never surprise the reader of your code, even if it will be you a year from now. For example, don’t call a function max() when sometimes it returns the minimum(). Be consistent, and use the same conventions throughout your code. Not only the same naming conventions, and the same indentation, but also the same semantics. If, for example, most of your functions return a negative value for failure and a positive for success, then avoid writing functions that return false on failure. Write short functions, so that they fit your screen. I hate strict rules, since there are always exceptions, but from my experience you can almost always write functions short enough to fit your screen. Throughout my carrier I had only a few cases when writing short function was either impossible, or resulted in much worse code. Use descriptive names, unless this is one of those standard names, such as i or it in a loop. Don’t make the name too long, on one hand, but don’t make it cryptic on the other. Define function names by what they do, not by what they are used for or how they are implemented. If you name functions by what they do, then code will be much more readable, and much more reusable. Avoid global state as much as you can. Global variables, and sometimes attributes in an object, are difficult to reason about. It is difficult to understand why such global state changes, when it does, and requires a lot of debugging. As Donald Knuth wrote in one of his papers: “Early optimization is the root of all evil”. Meaning, write for readability first, optimize later. The opposite of the previous rule: if you have an alternative which has similar readability, but lower complexity, use it. Also, if you have a polynomial alternative to your exponential algorithm (when N > 10), you should use that. source, fore more: https://www.quora.com/What-things-should-every-C++-beginner-know
1st Apr 2018, 12:05 PM
Baraa AB
Baraa AB - avatar
+ 1
learn everything from here till classes then attempt coding challenge check other people's code and try to understand them, modify them if you get struck you can ask here
1st Apr 2018, 11:27 AM
‎ ‏‏‎Anonymous Guy