5 ms·
This article is probably one of the reasons why C++ gets the reputation it has. Please do not program like this. Aside from the fact that this is C++98, which l
by svalorzen 11y ago
This article is probably one of the reasons why C++ gets the reputation it has. Please do not program like this. Aside from the fact that this is C++98, which lacks tons of features now widely accepted and useful in C++, the code in this article has no consistency, uses most bad practices I know, and is most certainly not geared towards competitive programming.
All this information is readily found in any online docs about C++. Please read those.
- bdrool 11y agoOn that note, these links are the best place to start when it comes to writing "good" C++ these days: https://isocpp.org/blog/2015/09/stroustrup-cppcon15-keynote https://isocpp.org/blog/2015/09/stroustrup-cppcon15-keynote http://herbsutter.com/2015/09/27/my-talk-at-cppcon/ http://herbsutter.com/2015/09/27/my-talk-at-cppcon/ https://github.com/isocpp/CppCoreGuidelines https://github.com/isocpp/CppCoreGuidelines
- thrownaway2424 11y agoSeriously. Nobody needs to think about stuff like this any more: vector< vector<int> > Who even does that?
- spdionis 11y agoJust curious, what should you use instead?
- svalorzen 11y agoHe's talking about the fact that older compilers used to get confused if you happened to open/close multiple template tags in sequence; i.e. "<<" or ">>". These were mistaken for operators, and the code failed to compile. Nowadays there's no need to keep them separated, and compilers parse them correctly.
- deleted 11y ago[deleted]
- scott_s 11y agovector<vector<int>> Prior to C++11, the code above would fail to compile. The lexer would see the final ">>" and assume it was the out-stream operator. This was such an annoying issue that they eventually changed the grammar so that the above would compile as expected.
- jzwinck 11y agoMatrix2D<int>. Removing a space from between the brackets misses the forest.
- forrestthewoods 11y agoPeople on C++03 where vector<vector<int>> is defined as operator >>. This wasn't fixed until C++11. https://en.wikipedia.org/wiki/C%2B%2B11#Right_angle_bracket https://en.wikipedia.org/wiki/C%2B%2B11#Right_angle_bracket
- static_noise 11y agoDon't use C++03 in 2016 please.
- hikarudo 11y agoExcept if the compiler for your target platform (cough TI DSP cough) supports only C++03, and never will support anything newer.
- whitegrape 11y ago> Don't use C++ in 2016 please. Fixed that for you.
- ska 11y agoNo, you really didn't. For all it's problems (some of which are being addressed in recent standard update , some not so much yet) it remains the best available tool for some domains. More's the pity.
- 1024core 11y agoSeriously. C++ seems like a layer of hacks, one upon another, each designed to "fix" things in the layers below, only to add more confusion. Maybe "D" is the answer, or Go...? I don't know. I started with C++ a long time ago, but for whatever reason, kept getting out of it (for a few years) and then every time I'd get back in, I'd be surprised at the new stuff.
- jjnoakes 11y agoNot all of us have the luxury of using the latest compilers. Or the systems we support don't even have compilers which handle anything newer than C++03. Do you think compiler support is instantaneous for all platforms on all operating systems, retroactively, when the standard is published?
- GFK_of_xmaspast 11y agoPersonally I find the version with spaces easier to read, but I'm not going to get annoyed either way. Of course, it should also be std::vector<std::vector<int>> ...
- stinos 11y agoor more spacey, like std::vector< std::vector< int > >
- ThatGeoGuy 11y agoI cannot support this view enough. After reading about `typeof(a + b)` to do what `auto` in C++11 does, I cringed a little inside. If you want to get good at C++, there are no shortcuts. Read books (Scott Meyers, Bjarne Stroustrup), read Herb Sutter's GotW series, but don't read this.
- fsloth 11y agoI would add "Physically based rendering" by Pharr and Humphreys to that list. They demonstrate how to construct a complex application using C++ using a fairly unique literary programming style, and they also provide the source code for a functional system in their homepage. It's domain specific but the domain happens to be concerned with efficiency and correctness so it's not a bad one to learn.
- aksx 11y agoYou think this is bad? try reading the code submitted during coding competitions (hackerrank, google's code jam). lots of macros to do operations quickly, the code is not even readable.
- jstimpfle 11y agoCan you give concrete example what you are referring to? From a quick skim, I would say that's quite clean, straightforward algorithmic code -- while it could be improved a tiny little bit by sprinkling in a little C++11 syntax (don't overdo it). (For context, I'm mainly a C / Python / Unix Programmer, with an interest in common sense and architectures based on clean plain data interfaces instead of wrong abstractions, and with a good track on SPOJ)
- svalorzen 11y agoJust random things that pop up: - using namespace std; - variable names inconsistent and random, using uppercase and lowercase randomly (code also would not compile since it is cased randomly) - indenting and braces inconsistent - use of macros for trivial tasks where they are absolutely not required - use of macros in totally dangerous ways ("#define all(c) c.begin(), c.end()", seriously?) - usage of compiler dependent features - code should be for "competitive programming", and proposes a vector of vectors to make a 2D matrix - Counterproductive and unhelpful typedefs EDIT: I'd like to tell you more, but looking at that page is making me feel unwell. The ostringstream example seems to be out of a nightmare. Just learn C++ from a reputable source and save yourself and everybody else around you the pain.
- jzwinck 11y agoYou're right that some of those items are bad practices in normal development. But some of them would actually help a person bang together crappy but working code more quickly for a one-off task. Perhaps we should read "competitive programming" as "programming quickly without regard for quality." Taken that way, the article could even be titled "programming to impress nontechnical managers so you can become one."
- Nimitz14 11y ago> proposes a vector of vectors to make a 2D matrix what would be the right way to do this?
- Stasis5001 11y ago
- Hernanpm 11y agoI do not agree, this is tutorial is very specific for competitive programming and it is well known that it doesn't mean good code, e.g. https://news.ycombinator.com/item?id=9324209 https://news.ycombinator.com/item?id=9324209 and actually it was great tutorial years ago but now we have c++11 and I would like an updated version of this tutorial that use c++11 features.
- zjarek 11y agoYou don't get C++11 or newer features on gcc 4.0.2 (https://community.topcoder.com/tc?module=Static&d1=help&d2=generalFaq#183 https://community.topcoder.com/tc?module=Static&d1=help&d2=g...). You have to keep in mind that code for this kind of competitions is generally write only and uses basic facilities of a language to solve given algorithmic problem as fast as possible. Consistency isn't important when your solution fits on a single page.