5 ms·
The linked http://strlen.com/java-style-classes-in-c http://strlen.com/java-style-classes-in-c was both horrifying and tantalizing. I'd expected a preprocessor
by jongraehl 13y ago
The linked http://strlen.com/java-style-classes-in-c http://strlen.com/java-style-classes-in-c was both horrifying and tantalizing. I'd expected a preprocessor that generates appropriate .hpp/.cpp, but instead I learned about yet another corner of C++ I hadn't exactly induced from experience.
- eliasmacpherson 13y agoHave a look at juce_amalgamated.cpp in the JUCE library for a real world example of this. The author of this java style classes article has taken one extreme view and I have taken another, that no code, inline or otherwise belongs in a header. Just declarations all the way. It's remarkable that modifying C++ headers is such a chore that it comes up as a reason for getting something done in a tiny fraction of the time for a roughly comparable task.
- Groxx 13y ago>It's remarkable that modifying C++ headers is such a chore that it comes up as a reason for getting something done in a tiny fraction of the time for a roughly comparable task. Couldn't agree more. Though I don't find it all that painful - lots of editors/IDEs have a 'go to header file' shortcut that makes this take a couple seconds at worst. But then I have repeatedly wondered why IDEs don't seem to have a way to synchronize your cpp changes to your header automatically. Rename function in .cpp -> automagically rename function in .h. That's all you really want a lot of the time.
- seanmcdirmid 13y agoNo intrinsic limit, just that c++ is so incredibly hard to tool that so many useful tools (say for refactoring) will never get written for it.
- ygra 13y agoIn fact, I think the Visual Studio team once said that it's so excruciatingly hard to build C++ refactorings that won't destroy code in unhappy circumstances that they won't bother shipping such things.
- eliasmacpherson 13y agoI suppose clang is the great white hope for C++: https://www.youtube.com/watch?v=yuIOGfcOH0k https://www.youtube.com/watch?v=yuIOGfcOH0k link taken from here: http://stackoverflow.com/a/13840863 http://stackoverflow.com/a/13840863
- seanmcdirmid 13y agoNew C++ code should be outlawed. Really, the language was just designed to make everything difficult, problems that just don't exist in modern programming languages. Crazy syntax, use of type information during parsing, convoluted namespaces...there is a reason C++ code is twice as hard to write, let alone trying to write a decent compiler for it. Heck, for the longest time there was only one portable parser that worked available for licensing, and the licensing costs were north of $150K. C++ has no future by design.
- eliasmacpherson 13y agoI'm not in a position to advise people on what they should or shouldn't do, I am ignorant of a great many things. Until I wrap my head around the following, I won't be writing C++ unless I have to: http://en.cppreference.com/w/cpp/language/except_spec http://en.cppreference.com/w/cpp/language/except_spec The fact this is deprecated in c++11 is my personal pet peeve. I can't reason about what the impact is without putting it in to practice, but given that exception safe C++ can be hard to write and it's deprecated does that mean it's going away in C++14 and what are the implications of that? The throw() specifier (counter intuitively meaning 'should not throw anything') is everywhere! If it turns out that all the advocacy for using exceptions has resulted in written code that uses deprecated conventions and requires maintenance and re-understanding, then I will be very very disappointed.
- eliasmacpherson 13y agoIt's not the editing of the header that's the problem, it's doing the edit correctly so that the program still builds. I call it include hell. In addition changing a header file can at times trigger a lengthy build. Visual Studio and ctags based 'IDE' style features allow you to go to definitions or declarations fairly easily. Unless I'm mistaken I think the eclipse CDT for c++ can change/refactor file and header as you wish for. [1] [2] [1] http://help.eclipse.org/helios/topic/org.eclipse.cdt.doc.user/tasks/cdt_t_refactoring.htm http://help.eclipse.org/helios/topic/org.eclipse.cdt.doc.use... [2] http://r2.ifs.hsr.ch/cdtrefactoring http://r2.ifs.hsr.ch/cdtrefactoring I'm unaware of anything that can change function prototypes correctly, but maybe eclipse CDT can do it.
- Groxx 13y ago>In addition changing a header file can at times trigger a lengthy build. Well yeah, but that's true for doing it by hand too. If it's that slow, you won't have automatic builds on anyway, and you can usually cancel it if you need the CPU for some other reason (in which case, again, why do you have automatic builds on). And even if it were only a 90% thing, that's a 90% savings. I mean, literally, if you change the name alone, change the header name. You get immediate notification that other locations might need changing if/when the build fails. Similarly for argument order / name (type will probably cause build failures). But all those build failures would happen anyway if you changed it by hand, so it's not any different, just faster. Isn't faster the goal here?
- eliasmacpherson 13y agoI'm not making a distinction between manually editing and automated editing of a header file. Both are a PITA. Changing the header name sounds like a reasonable suggestion, but I don't think it's a goer with large projects. The problem with headers is that as soon as you are doing anything beyond trivial you can get in to a big fight with the compiler, leading to the following sorts of problems: http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix http://stackoverflow.com/questions/12573816/what-is-an-undef... When these problems are C++ template related, then you have to remember exactly what you changed and where because even on the intel compiler, the compiler isn't really going to tell you what's wrong.
- xyzzy123 13y agoIt's enough of a chore that entire products exist to help. I rather like "Visual Assist X".