4 ms·
I often dislike C++ and Java (note: did not say object oriented programming), because the logic tends to be distributed in so many different files and locations
by vardump 12y ago
I often dislike C++ and Java (note: did not say object oriented programming), because the logic tends to be distributed in so many different files and locations. The abstractions, which should be beneficial, to decrease mental load, have the opposite effect over a longer time. To understand what just one overloaded method call does, I have to often read through a dozen of different files. Context sensitive IDEs don't make it much easier. Simply grepping files at command line is often the fastest way!
Combine that with object mutable state. And that with multi-threading (surprise state changes). Add exceptions on top (surprise hidden gotos, especially annoying in C++). The end result is often nearly impossible to fully understand.
However, this is not anti-OOP rant really. I recognize OOP has its uses.
The bigger issue is almost always when there's a discussion whether X is better than Y, some people seem to forget often both X and Y have their place in the toolbox. They're often complementary. When you like technology X, technology Y is not a threat to you, but an opportunity to learn something new. In the same way, criticism against X can be an opportunity to learn and improve. Not hostility against people who like or are used to technology X. No matter how much you like hammer doesn't make a saw a bad tool.
- jimmaswell 12y ago>To understand what just one overloaded method call does, I have to often read through a dozen of different files. Context sensitive IDEs don't make it much easier. Simply grepping files at command line is often the fastest way! Right click -> Find all references / go to definition don't do that faster than typing out the grep command? You said mutable state makes it harder to understand, and you said exceptions make it harder to understand because they're hidden gotos (which if statements and while loops are too), but didn't explain either. In my experience, exceptions have been a very simple, helpful, intuitive component of control flow.
- vardump 12y ago> Right click -> Find all references doesn't do that faster than typing out the grep command? Yes, IDE is not generally faster. Find all references is not faster for me in most real life scenarios. Typing grep command is just arrow up, ctrl-something to get the cursor to right position, type something, hit enter. Piped to less, I hit / to search within the results. Done right, results from grep appear pretty much instantly, no waiting. Some operating systems are much better for this technique than others, due to cost of dealing with small files. > You said mutable state makes it harder to understand, and you said exceptions make it harder to understand because they're hidden gotos (which if statements and while loops are too), but didn't explain either. In my experience, exceptions have been a very simple, helpful, intuitive component of control flow. Whenever you call some method (or overloaded operator), it can throw. The fact is completely hidden from the context in front of you in C++. In Java, you do know what might throw, because you have to declare it. On the other hand, the cost is high when anything you call changes the exceptions it throws. Or more like, it's set in stone.
- jimmaswell 12y agoThat still sounds like more work than the way I do the same process in Visual Studio, which uses the AST or something around that level to search the code instead of just a text search, so it doesn't find irrelevant results. I guess it depends on your environment. It is better when it's specified exactly what exceptions can be thrown by a method, yes. One of the only things I prefer in Java over C#.
- vardump 12y agoIf only Visual Studio/C++ used AST! At least in Visual Studio 2012/C++, context sensitive search doesn't often work at all. Try to get context for something common like ".create". You get a lot of non-context hits, even thousands. Maybe I'm doing something wrong? Maybe this doesn't happen in VS2013? In most other IDEs context sensitivity is better, but I still fall back to command line in Linux. It's just so much faster (for me). I get what I want in about 0.1 to 3 seconds and can easily search near (grep -A and -B switches) these context hits with '/' in "less". Git grep is great too. Regardless, if it works for you, great. We should all use what works and disregard needless debate and politics.
- jimmaswell 12y agoI haven't used it for C++, only C# and VB.NET. It's integrated more with those, probably not with C++
- taeric 12y agoOne point I often see missed is that having a code base that supports grep style searching often involves a codebase that does not constantly reuse the same function names. With one that is really done this way, the same variable name appearing in multiple places will be informative, as well. Even if the types are different.
- edgyswingset 12y agoIn my experience, VS2013 with peek-at-definition really is unmatched. I'm all for text searches (it's my go-to, rather than point-and-click files), but the contextual definition (and ability to edit) is stellar.
- GFK_of_xmaspast 12y agoIn C++ at least there's not much stopping you from putting every single class and method in a single header file like an animal.