5 ms·
The problem with C++ is the constant introduction of unneeded features that are infinity obscure in necessity. People will say "Oh just don't use that feature"
by gravypod 10y ago
The problem with C++ is the constant introduction of unneeded features that are infinity obscure in necessity.
People will say "Oh just don't use that feature" but that's not how this works. If something is there it is used. In reference to C, I don't think I know of a single feature or release that had major changes in how I wrote C. Maybe C99 and allowing me to declare in a for loop.
I've been using C++ for class this semester and the only thing I like is reference types. Makes pointers much more concise. Other then that it can all go in the bin. In order to keep my C++ project clean I've needed to avoid a huge set of features and keep it in a data-oriented design.
- hackits 10y agoWhen I think about features in C++ that I would love to have in C, the only thing that comes to mind is constructors and deconstructions for RAII.
- Koshkin 10y agoProblem is, using destructors (and RAII) may have, in general, certain performance implications that C may not be willing to deal with. This is somewhat similar to demanding that C had a garbage collector built in. Note that, being lazy, memory management by means of garbage collection may turn out being more efficient than using the (eager) destructors.
- hackits 10y agoDon't see how there could be any performance implications with having RAII within C. It would be a simple method call with the this pointer to the struct during complication. Though if your performance consideration is at the assembly code level why use C? I've had some good/bad experiences with garbage collectors. They do help improve productivity and ROI within the enterprise space where memory isn't too much of of issue. Then when memory does become a issue within smaller memory footprint environments they can be a real pain in the ass.
- gravypod 10y agoIf anything this video shows us that there is probably a lot less of a performance hit actually is take. That's one of the things mentioned in the source video.
- gravypod 10y agoMy issue with RAII is that it's fundamentally not what you expect to happen. If I say: int i; I don't expect that to create an integer. I expect that to reserve memory in the program's space for an integer. In the same way I don't expect this to call malloc: int *i; I just expect that to hold the space in the program data where and int pointer can be stored. Furthermore I don't expect this to run any code (just as the other two). string s; I don't expect that to construct anything, that's just a place for me to put data. This way, we know not to use data before it's initialized. In C++: int i; if (i > 10) printf("Greater then 10\n"); Is that going to always work how we expect it? How about: string s; if (s.length() > 10) printf("Len is greater then 10\n"); That is going to always work how we expect it since it was constructed. This is fundamentally different then uninitialized integers or primitives so I dislike it's use. I strongly dislike the use of this term but it in my mind is an "Anti-pattern" as it promotes two separate ways of thinking about variables that are fundamentally completely different. Info taken from: http://www.cplusplus.com/reference/string/string/string/ http://www.cplusplus.com/reference/string/string/string/ http://www.cplusplus.com/forum/general/67249/ http://www.cplusplus.com/forum/general/67249/ Now I'm no expert in education but this knowledge has taken me years to learn through my life and I don't think I'd have been able to do it if I didn't LOVE computers and programming. I don't know how someone would think that this is good behavior because of it's inconsistencies between two outwardly similar cases.
- hackits 10y agoHi gravypod. It depends. Oh I hate that word. When I see int i; without context I don't know anything about where memory is allocated. It can either be the following. 1) Stack allocated 2) Heap allocated 3) Is in the read only data segment. Just starting with a int, it can be any of the above three, two that reserve the memory on the heap/stack and another that is only a read only part of memory. The heap is the only place where I would need to call malloc/free. Though for most common libraries when I see string s; They mostly have a pointer null terminated string in memory, and the primitive data types residing as the member's of string. RAII helps in the situation where instead of having to do tedious code such as. String s; allocate_string(&s); // do something with string. free_string(&s); It can all be done via a standard convention of calling the deconstructor or constructor to initialise and free itself.
- jonstewart 10y agoThe problem with posts about C++ on Hacker News is that people who aren't experienced C++ programmers (you've been using C++ for a semester? do tell) feel compelled to write posts explaining the problems with C++.
- yosefk 10y agoAs someone who's had to deal with C++ since the last century, I find that one problem with C++ is that people who aren't experienced C++ programmers can't get shit done, especially in a code base where experienced C++ programmers have demonstrated their erudition and knowledge of C++ arcana in all its glory. In fact, the intersection of people who had the patience to learn enough C++ to get shit done and people who also have the patience or basic desire to actually get shit done (as opposed to programming wanky wrappers and stuff) is annoyingly small (this however is not true everywhere, I'd expect no such problem to exist with game programmers, for example.) The fact that a language is terrible for newcomers is a real problem, and a newcomer is a very good judge of that even if they aren't a very good judge of other aspects. Especially loathsome are those people who teach, say, undergraduates majoring in physics some C++ as a way to introduce them to programming. You might think that someone who manages to deal with the math needed to do physics would be able to absorb C++, and often you'd think wrong; one physics undergrad told an experienced programmer after trying to understand what the fuck cout<<x actually does, "your head is full of garbage!", by which he meant that the amount of completely arbitrary rules that you need to memorize was not something that dealing with math and science prepared him for. From the above I conclude that people who have a semester's worth of experience in C++ might not be C++ experts but they certainly know enough to burn the instructor who chose C++ in the first place at the stake.
- sseagull 10y ago> what the fuck cout<<x actually does I'm not sure where that conversation would go. It prints to stdout. Would the student say the same thing about printf("%d", x)? How far down the rabbit hole did he want to go? Stream insertion syntax os pretty bad, though, I'll agree with that. Especially when you want to print floating point.
- sseagull 10y agoI've been using C++ for a long time (10+ years). At one point (around C++11), I decided to really embrace the advanced features (template metaprogramming mostly) and stop trying to make the language something it wasn't. It can be complicated, for sure. But there is a certain plesantness that comes with letting the compiler do a lot of work for you. It can almost be like the switch to python - just let the compiler figure stuff out. This results in a lot less duplicate code, etc. The cost is some pretty bad syntax and compile time, though. Try to keep an open mind
- gravypod 10y agoI mean I've been programming for some time and I come from a strong Java background. I get the basis of what C++ is trying to do with their new features but I think it's horribly executed when looked at in comparison to other modern languages like Java and Rust. Speaking from a very strong Java background after Jigsaw I think Java will outdo the generics capabilities present in C++ in every way. Java 9 is bringing some crazy features to the mix. From what I understand they are getting rid of the boxing to object from generics to keep types static through lists and other generic elements. That's amazing and something C++ still does as templates are basically massively duplicated code in your binary while the JVM will get this for free at runtime. Rust is also just out of left field as they are doing amazing things with their "cost-free abstraction"
- KKKKkkkk1 10y agoThe other thing about C++ is that you start by saying "I'll write C and only use this one extra feature from C++." and thereby you open a Pandora box. You decide to use reference types, and all of a sudden your classes are not default-assignable.
- gravypod 10y agoI just don't use classes. I'd like to but again it's just not a good idea. I also don't like default constructors see my other post as to why I think they are not reliable behavior to the programmer if they don't have experience in the language. Again I didn't lie when I said "I am using C in C++" as I am using C in C++.