Skip to main content
GameDev.net gamedev.net
🔒 Locked

A Crappy C++ article, and why the internet is bad source of information

Started by fpsgamer Oct 7, 2007 at 5:41 PM 52 replies 13.5k views
Original Post
fpsgamer
fpsgamer
I did a quick Google search so I could quickly review the C++ cast operators. In the search results was an www.informit.com article. Without having really read much from that site before, I had assumed it was a decent quality resource (something like Dr. Dobb's Journal). The article was titled "Why I Hate C++ Cast Operators". I rarely appreciate articles with such drastic statements since very few people in software engineering or computer science have the credibility to be so bold (see: Bjarne Stroustrup). Always wanting to learn more I read the article anyways. The article is utter shit. The part where I officially lost my mind was the example he gave for why C++ cast operators are in fact "dangerous"!
Quote:
Excerpt from: Why I Hate C++ Cast Operators by Danny Kalev / www.informit.com --- int n; double d=15.95; int n= static_cast (d); This code will not compile, though. Our naïve programmer doesn’t give up. He decides to modify the code a bit: int n= reinterpret_cast (d); Surprise, surprise. This version wouldn’t compile either. As a last resort, our poor programmer uses the following: int n= *reinterpret_cast (&d); This version compiles without a problem. Our programmer expects that after the cast operation, n shall be 15. Alas, it’s actually 1717986918! The reasons for this aren’t very important at the moment; what’s important is that many C++ programmers do believe that the cast expression above should initialize n to 15, which it doesn’t. Lo and behold, C-style cast does get it right.
First of all, the first line is explicit and self documenting but most importantly it is the correct cast to use and does compile. END OF EXAMPLE. Regardless, the author continues the example with a series of nonsensical operations that a fictional newbie would attempt next. Eventually he decides that *reinterpret_cast (&d); is the cast that a user would end up with -- and is indeed entirely wrong. Whats worse is that he immediately uses that bull crap example to justify why int n= int (d); is the superior notation. How did this get published? How did nobody email them? This is madness. I have long insisted that the internet should not be the last stop for information. I'll typically use it as a starting point, then I will immediately use a bound and well reviewed book. I will use select internet resources from or recommended by trusted individuals. However overall, the internet is a shit hole, and I'm not only talking about goatse. [Edited by - fpsgamer on October 7, 2007 9:00:17 PM]
dmatter
dmatter
I'd stop reading at the first line:

Quote:
Quote from linked article
Fortunately, C++ doesn’t have many "royal annoyances" that would make you tear your hair out
Andrew Russell
Andrew Russell
LOL - someone gave a talentless C programmer a C++ compiler and a soapbox.

The whole thing is apparently 347 pages - I don't know if the whole thing is terrible, but what I skimmed going back and forth from the OP's link is pretty horrific.
Jarrod1937
Jarrod1937
Apparently he has a published guide to C++.

edit: after looking more closely, perhaps its just a book version of his online guide.
-------------------------Only a fool claims himself an expert
instinKt
instinKt
The internet is a good example of why democracy doesn't work. ;)
Cypher19
Cypher19
What I find funniest is that the so-called newb programmer would expect a result of 15 when doing that cast in the end since it'll take the exact same data instead of doing the proper float to int conversion.
Andrew Russell
Andrew Russell
Quote:
Original post by Jarrod1937
Apparently he has a published guide to C++.

edit: after looking more closely, perhaps its just a book version of his online guide.


The publisher is "Pearson Custom Publishing" - which appears to be closer to a print-on-demand service than a traditional publisher.

But it does indeed appear that the book is just a printed version of the online content.

Really, the content would be better titled "My experiences with C++" rather than "C++ Reference Guide". Although it should be noted that the page the OP points out is in a section titled "Soapbox".
capn_midnight
capn_midnight
This is why I only stick to reading official documentation when it comes to programming languages and APIs. That also happens to be the same reason I don't use a lot of different FOSS projects, the complete lack of real documentation.
fpsgamer
fpsgamer
Quote:
Original post by eedok
Could be worse


Apparently according to that article all you need to create an MMO is:
Quote:

1) Visual Basic (6.0 preferred)
2) Photoshop and MS Paint


3) ...
4) Profit?
dmatter
dmatter
Quote:
Original post by fpsgamer
Apparently according to that article all you need to create an MMO is:
Quote:

1) Visual Basic (6.0 preferred)
2) Photoshop and MS Paint


3) ...
4) Profit?

You mean 'capital', you won't make any profit until you've used VB6.0 and MSPaint to create your awesome MMO.
niteice
niteice
Whoever wrote the RPG article is clearly vastly superior to all of us. After all,
Quote:
Not much is required to create a game, you just need to know how to do everything.
Zipster
Zipster
Quote:
Original post by dmatter
Quote:
Original post by fpsgamer
Apparently according to that article all you need to create an MMO is:
Quote:

1) Visual Basic (6.0 preferred)
2) Photoshop and MS Paint


3) ...
4) Profit?

You mean 'capital', you won't make any profit until you've used VB6.0 and MSPaint to create your awesome MMO.

I've just found a crumpled $5 bill in my back pocket, will that work? Maybe I can photocopy it a few times too.
Muhammad Haggag
Muhammad Haggag
Quote:
Original post by fpsgamer
How did this get published? How did nobody email them? This is madness.

"The C++ Guide" is the name of his blog. No one at InformIT reviews it because--probably--nobody cares. Either that, or he impressed them with his claim to 15 years of C++ expertise.

Anyway, lots of people commented on that particular post, but InformIT uses a custom comment/discussion system that doesn't quite support locating discussion topics, reading them, posting to them, or--God forbid--finding your own damn posts after you've submitted them.

I managed to find the comments to that article through google, by searching for my username [1]: here. Of course, the aforementioned page is an amalgamation of posts from different topics, so you'll have to search the page for the string: "from Why I Hate C++ Cast Operators", and you'll be able to navigate the replies.

As a bonus, though, you'll find a couple of replies by Herb Sutter in there (to a different topic, IIRC--something C++/CLI related).

[1] User name auto-generated from the email address used for registration. I actually had to login to know what it was. Sigh.

SimonForsman
SimonForsman
Quote:
Original post by niteice
Whoever wrote the RPG article is clearly vastly superior to all of us. After all,
Quote:
Not much is required to create a game, you just need to know how to do everything.


He is right though, if you know how to do everything the rest shouldn't cause much trouble.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Ysaneya
Ysaneya
Quote:
Original post by eedok
Could be worse


That's incredible. It's just the fourth dimension. Quote from the second page:

Quote:
A MMORPG is not very hard to program, most people think it would be very difficult, but if you really think about how to program it, they are very simple to do. First off the Client program (the game the player has) has to communicate with the Server program (where everything gets stored from all the players). I find the best way to store information is by using variables instead of textboxes and list boxes and what not.

Wan
Wan
Quote:
Original post by fpsgamer
I have long insisted that the internet should not be the last stop for information. I'll typically use it as a starting point, then I will immediately use a bound and well reviewed book. I will use select internet resources from or recommended by trusted individuals. However overall, the internet is a shit hole, and I'm not only talking about goatse.

That's great, but you can't always buy a book. The Wikipedia entry on Bjarne Stroustrup you posted could be full of mistakes, but I won't be off running to the book store to check all the facts. Besides, just because it has been printed on paper doesn't mean anything to me. It will still contain someone's personal view, and in this case the information may even be outdated.
I find it to be more relevant to know who the author is: what he has worked on previously, how experienced he is, which people refer to his writings, etc. With the "C++ cast operators" article, at least I know who wrote it, and I'll make sure to be extremely cautious when I stumble upon one of his articles in the future.

Quote:
Original post by eedok
Could be worse

I had seen that before, it's pretty hilarious.
If have no idea whether these are accurate (perhaps someone made the mistake to use variables instead of proper text boxes), but the statistics at the end of page two are truly horrifying:
Quote:
http://www.onrpg.com/contentid-5-2.html
Published on: 2003-08-26 (141746 reads)

OrangyTang
OrangyTang
Quote:
Original post by WanMaster
Besides, just because it has been printed on paper doesn't mean anything to me. It will still contain someone's personal view, and in this case the information may even be outdated.

A book printed through a reputable publisher (I usually find Addison Wesley to be good for techinical books) will go through at least one editor for review before being published. Random articles on the internet have none of that.
Wan
Wan
Quote:
Original post by OrangyTang
Quote:
Original post by WanMaster
Besides, just because it has been printed on paper doesn't mean anything to me. It will still contain someone's personal view, and in this case the information may even be outdated.

A book printed through a reputable publisher (I usually find Addison Wesley to be good for techinical books) will go through at least one editor for review before being published. Random articles on the internet have none of that.

I would too be more likely to trust a reputable source than a random one, but regardless of the medium.
Zmurf
Zmurf
Quote:
This is because C-style cast, unlike the new style cast operators, is context sensitive and cleverer.


The word cleverer is such an oxymoron lol.
If it's possible for us to conceive it, than it must be possible.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.