|
There may be reasons to dislike C++, but surely this one is a programmer induced problem.
|
|
|
|
|
One reason to dislike C(++) is that it provides excellent tools for a programmer to make a mess in a very simple way.
In the earlier days, you could see quite a few horrible cases of poiner arithmetic - and the programmers were proud of it, proud of how they could do things that were impossible in toy languages like Pascal that gave you a slap on your fingers for just addressing outside the array limits, and introducing artificial differences between a pointer to the start of an array and the array itself. Every knowledgeabler person should know that they are the same!
Fortunately, intricate pointer arithmetic is no longer the way to prove your skills. OO techniques has been more popular for that for at least 15-20 years. Virtual functions and overrides may be terribly abused, too, and what is the big difference bewtween operator overloading and virtual functions, at the conceptual level?
|
|
|
|
|
Member 7989122 wrote: the programmers were proud of it,
This is a problem in any language, and exactly what I am getting at here.l C++ give bedroom nerd programmers who think complexity is good the chance to do this.
Real engineers dont.
Member 7989122 wrote: what is the big difference bewtween operator overloading and virtual functions
Huge.
An overridden function is subclass specialisation.
An operator overload is supposed to *improve* the operator's functionality specifically for that class. In fact without overloading that operator might be dangerous.
Take the classic 'class contains an allocated pointer' and not overriding the '=' operator. The class being copied to needs new memory allocating, and the contents copied to it.
This is good. This is logical.
Using [] to add a member to the end of an array is just stupid.
|
|
|
|
|
Munchies_Matt wrote:
This is a problem in any language, and exactly what I am getting at here.l C++ give bedroom nerd programmers who think complexity is good the chance to do this.
Sure every programming language has facilities that may be abused. Some has more such "options" than others. Take pointer arithmetic: You can do that in C an C++, but not in C#. Adressing out of array bounds (deliberately or accidentally) you can do in C, but not in Pascal. Silent fall through in a switch statement you can do in C, but neither in Pascal (no fallthrough at all) or C# (explicit). Dividing 'B' by 2 to get an exclamation mark: Allowed in C, not in properly typed languages.
Fortran had its 'facilities', such as common blocks and GOTOs. Actually, most languages do provide labels and GOTO, but I don't think I have programmed a single GOTO in my 35 years as a programmer, and I have hardly ever come across code that uses is. At least not after that 101 Elementary Programming as as freshman at the U, which was taught in Fortran (the next year they switched to Pascal).
Other languages, too, can be abused. But languages do vary a lot in how much effort it takes to get to those misbehaviour features (I think you could do pointer arithmetic tricks in "unsafe" C#, and many Pascal compilers lets you turn off the array index checking).
It also varies a lot what is commonly accepted programming style in textbook examples, widely distributed open source code etc. For C, you see things like (usually unsafe) pointer arithmetic, or pro forma arrays of length 0 because they will be arbitrarily indexed out of bounds etc. Fortran examples could have lots of labels and GOTOs, and so could Basic, but you would rarely if ever see a GOTO in a Pascal or C# textbook.
You may be a "clever" C programmer able to "prove" that you can do the same nasty things in a more strictly typed language, a language lacking explicit pointers, etc. "So that other language is just as bad as C". No, it isn't, if you have to be an expert and do special tricks that noone does by accident.
In C (/C++) you might do things by accident or delibrately, and a bystander will be unable to distinguish between them. You need not do anything to "allow" neither switch fallthrough, out-of-bounds indexing or pointer arithmetic. Many other languages are far more helpful, trying to guide you not to do silly things. C is a "you asked for it, you got it"-language.
|
|
|
|
|
Munchies_Matt wrote: what is the big difference bewtween operator overloading and virtual functions Huge Implementationwise: Yeah, probably, in most compilers. Not necessarily.
On an abstract level, for the user: Not very much. Both mechanisms provide similarly identified operations to be interpreted differently for different types/classes. The intention is that the implementations for various types shall have similar semantics, but it doesn't have to be.
In my "childhood engineering years" (i.e. after graduation) I was programming in a Pascal-inspired proprietary language which allowed a left argument as well as right arguments, and a single right argument didn't require parentheses. Furthermore, the identifier syntax for functions allowed a big selection of special characters and Functions could be overloaded. "+" was a perfectly fine name for a function that could take MyComplex left and right arguments, or a MyComplex left and (float: re, float: im) right arguments. Conceptually, predefined "+" functions for int+int, int+float, ... were just like user functions. (Obviously, the compiler compiled wellknown builtin functions like these quite differently from those that were actually user written.)
I made a function library for all assignment functions (like C's =, ++, -- and so on) for struct types, that updated the reference count and triggered whenever an object was freed with more than one reference to it, or the reference count went to 0 in a non-free operation. This was for development/debugging only; for production work the library (with its noticable overhead) was omitted and the "simple" assignments took their place, as the default implmentation for the assignment functions.
This language wasn't a fullblown OO language; it didn't have a 'virtual function' concept. Yet having worked with overloaded "AddToList(MyComplex)" and overloaded "MyComplex + MyComplex", using identical mechanisms for the two, certainly blurs the distinction between overloaded operators and overloaded functions. Adding virtual functions on top of that doesn't make a very large conceptual difference.
|
|
|
|
|
As our program manager said once:
After object-oriented design course every programmer writes only singleton classes.
|
|
|
|
|
Wait.. what?
Are you talking about std::array<t>, std::list<t> or std::map<k,v>? Don't mix their terminology, please.
I'm guessing you're dealing with a map<k,v>.
And I'm guessing the some_map[value] is initializing a KV-pair with value as key (hella confusing name, btw) and a default value (of type V).
Typically, this is done before some algorithm which relies on a particular key existing / values to be initialised to keep its complexity low.
Nothing wrong with that, except the very awful variable names.
Something like this would make more sense:
std::map<keytype, valuetype=""> some_map = new std::map<keytype, valuetype="">()
some_map[new KeyType("key 1")];
KeyType key = new KeyType("key 2");
some_map[key] = new ValueType();
|
|
|
|
|
Seems to be something like that.
Anyway, reading my_array[value]; and that is it, is damn confusiing!
|
|
|
|
|
|
Don't get frustated, create your own adpator so you can do something like:
[static] map_adaptor::wrap(some_array_which_is_really_not_a_primitive_array).find_element_or_insert(value);
|
|
|
|
|
|
No sh*t it inserts it, I just said that.
RTFOT FFS.
|
|
|
|
|
Why I don't hate the C++ language I have found it to be overly arcane with its syntax...
Steve Naidamast
Sr. Software Engineer
Black Falcon Software, Inc.
blackfalconsoftware@outlook.com
|
|
|
|
|
Or is that Agile ? [^]
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
I reckon that we Alsatian have always been a bit weird.
|
|
|
|
|
Do share the perceived correlation between this and Scrum or Agile...
Indeed, tomorrow does arrive, but only on Tuesday's.
|
|
|
|
|
You're asking me to make literal sense ... in the Lounge ?
Well, if I had to estimate the current location of the semiotic goalposts, I'd throw an a priori marker on the field near the phase-state transition between histrionic and hysteric.
cheers, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
You can tell a good horror movie just by the reaction of the audience[^].
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
That's been quite well done - pity the sound was added afterwards, and the owner can be seen waving the toy...
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You would also be explaining the tricks during a magic show.
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
|
|
|
|
|
Would I?
That would be against Magic Circle rules.
(But I'm not a member of the Magic Circle, so "Yah! Boo! Sucks!" to them!)
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Quote: You would also be explaining the tricks during a magic show ...and what's wrong with that?
We are all engineers here.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
What did Grandma always say...
about hyper-threading?
PQOTW takes a long summer break now. I hope you survive. See you in late August.
... such stuff as dreams are made on
|
|
|
|
|
The knit knots not neat?
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
Nice to knit, innit?
... such stuff as dreams are made on
|
|
|
|
|