• Norman (unregistered) in reply to C# Man
    C# Man:
    StychoKiller:
    SR:
    Patrick:
    Yes, but this isn't C. It's [url=http://thedailywtf.com/Articles/5_years_C-pound_experience.aspx]C-Pound[/url

    I prefer C-Hash

    It's actually C-Octothorpe!

    I don't know why you Americans pronounce it Pound. This is a pound sign £, and this is a hash sign # otherwise own as sharp (as in musical notation). At least anytime I phone an automated phone line I'm always asked to push the 'hash' sign after keying in some number.

    It doesn't refer to the monetary unit, but the weight unit (really force if you are pedantic), i.e. 5# potatoes.

  • Jimmy Jones (unregistered) in reply to Ed
    Ed:
    The seperate cast methods in C++ may be the most horrifically difficult to use things I've ever encountered, especially in code that thrives on crazy pointer manipulation and Templates.

    Um, that was deliberate - to discourage writing of such code.

  • Jimmy Jones (unregistered) in reply to Doug
    Doug:
    My code is valid C and C++.

    The compiler will accept it but those casts are discouraged in proper C++. A C++ programmer is supposed to use the static_cast<>() thingy - which will fail.

  • Peter (unregistered) in reply to Norman
    Norman:
    C# Man:
    I don't know why you Americans pronounce it Pound. This is a pound sign £, and this is a hash sign # otherwise own as sharp (as in musical notation). At least anytime I phone an automated phone line I'm always asked to push the 'hash' sign after keying in some number.

    It doesn't refer to the monetary unit, but the weight unit (really force if you are pedantic), i.e. 5# potatoes.

    Does anyone really write "5# potatoes" for "5lb potatoes"? It's not a usage that I've ever seen.
  • (cs) in reply to Peter
    Peter:
    Norman:
    C# Man:
    I don't know why you Americans pronounce it Pound. This is a pound sign £, and this is a hash sign # otherwise own as sharp (as in musical notation). At least anytime I phone an automated phone line I'm always asked to push the 'hash' sign after keying in some number.

    It doesn't refer to the monetary unit, but the weight unit (really force if you are pedantic), i.e. 5# potatoes.

    Does anyone really write "5# potatoes" for "5lb potatoes"? It's not a usage that I've ever seen.

    It's a little archaic now, and rarely seen outside the food industry. In this context the symbol is a simplification of a combined "lb" with a line across the top (℔).

  • (cs) in reply to Doug
    Doug:
    frits:
    In C++ templates, the compiler generates the code at compile time, so you still get compiler type checking and code optimization. C# generics do none of this. Note my example:
    long i = Cast<long>("I Like Puppies!");
    
    
    

    This not only compiles, but signal my intent to cast "I Like Puppies!" to a long. I'm not sure where this could ever be useful.

    So, it's the same thing as

    long i = (long)("I Like Puppies!");
    

    just like in C, C++, and Java. I agree -- a worthless construct. If the compiler can manage to inline and optimize everything (which it should be able to do, in theory), then all's good in performance land. The only WTF, then, is the questionable syntax advantage.

    Sorry for the jerkiness yesterday, it's just my way.

    Now that I realize your example is C++, not C#, a much closer C++ approximation would be:

    template <class T>
    T * Cast(void * val) 
    { 
      return (T*)val;
    }
    
    long i = *Cast<long>("I like puppies!");
    
    
    

    That should illustrate the non-utility of the function in the article.

  • Anon-y-mouse (unregistered) in reply to Doug

    [quote user="Doug"][quote user="frits"] The secondary reason is to make casts stand out more visually: "An ugly operation should have an ugly syntactic form."[/quote]

    In C++ pretty much everything has "an ugly syntactic form.".

  • VJ (unregistered) in reply to TheCPUWizard

    If you knew differences between c++ casts, you wouldn't write such nonsense.

  • Poodle (unregistered) in reply to Escaped Lunatic

    [quote user="Escaped Lunatic"][quote user="Coward"] You cannot reinterpret_cast<float>(int). You need to do the ugly-fugly ((float)(&int)) instead. Well, I suppose you could do reinterpret_cast<float>(&int) , but that is just as ugly.

    Ah, the joys of floating point formats not supported by the processor or the compiler... [/quote]

    The reason that's ugly is because you should not be using a cast there. You should be using a union. If your floating point format is not supported, I imagine you would write a set of functions or a class for encapsulating this format which would use a union internally for performing the operations you want to perform. Overload operators and hey presto you've added support yourself, in one singular place. I feel you are blaming ugly code on a language you don't really understand.

  • BentFranklin (unregistered)

    If you don't click on sponsor links don't complain about anything. And never complain about the proofreading because that requires a second set of eyes, which I suspect Alex does not possess.

    Now that I'm on Alex's good side, may I suggest that code snippets in articles explicitly mention the language? That would cut down on a lot of chaff in the comments.

  • the beholder (unregistered) in reply to lolwtf
    lolwtf:
    Much less stupid workaround:

    #define CAST int x = (CAST int)2.1;

    define CAST as nothing, and you're free to stick it next to any casts without having any effect at all on the compiled code, while making said casts easy to locate.

    Or if not using C, of course, use the methods provided by your language.

    At last someone used common sense to provide a decent solution to this non-problem. I thought of using defines too, but my C/C++ skills are very rusty and I decided not to throw a half-working solution to the wolves.

    CAPTCHA- Who cares what's in my captcha?

  • SR (unregistered) in reply to BentFranklin
    BentFranklin:
    If you don't click on sponsor links don't complain about anything. And never complain about the proofreading because that requires a second set of eyes, which I suspect Alex does not possess.

    Agreed

    BentFranklin:
    Now that I'm on Alex's good side, may I suggest that code snippets in articles explicitly mention the language? That would cut down on a lot of chaff in the comments.

    Oh come on! I prefer my sniping to be platform-agnostic but I do enjoy reading other people's :o)

  • Schmalls (unregistered) in reply to Someone You Know
    Someone You Know:
    Peter:
    Norman:
    C# Man:
    I don't know why you Americans pronounce it Pound. This is a pound sign £, and this is a hash sign # otherwise own as sharp (as in musical notation). At least anytime I phone an automated phone line I'm always asked to push the 'hash' sign after keying in some number.

    It doesn't refer to the monetary unit, but the weight unit (really force if you are pedantic), i.e. 5# potatoes.

    Does anyone really write "5# potatoes" for "5lb potatoes"? It's not a usage that I've ever seen.

    It's a little archaic now, and rarely seen outside the food industry. In this context the symbol is a simplification of a combined "lb" with a line across the top (℔).

    It is definitely seen in the engineering industry. An example is a 150# ANSI Standard Flange which is pronounced "150 pound". The pound is supposedly in reference to the pressure rating in pounds per square inch (psi), but the pressure rating is different depending on the temperature and the rating doesn't really appear in the list anywhere (though the rated pressure at 500 F is approximately double the rating for everything above the 150 rating).

    CAPTCHA: wisi - We were blind, but now wisi.

  • (cs) in reply to Ed
    Ed:
    Debuggery:
    Ed:
    The seperate cast methods in C++ may be the most horrifically difficult to use things I've ever encountered, especially in code that thrives on crazy pointer manipulation and Templates.

    Of course they're difficult to use in crazy pointer manipulation: crazy pointer manipulation is bad. Stop doing it. Declarative casts are designed to keep type manipulation sane and compile time checked.

    There are only four separate casts, and two of them are only for extreme situations. The other two are extremely simple.

    That depends on the functionality you are trying to achieve: you try writing a monte-carlo neural network simulation framework without doing some very crazy pointer based nonsense.

    That's a lousy attitude for a professional engineer to take.
    Daniel Dennett:
    "Philosophers' Syndrome: mistaking a failure of imagination for an insight into necessity"
    The alternative hypothesis to your theory that there is only one possible way to write a monte carlo neural network framework and therefore C++ is a bad language, is that you simply lack the knowledge and skills to envisage an alternative way of doing it, and C++ is just fine.
  • (cs) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    What is with all these so-called "Senior Developers" and crap code (and usually a crappier atittude)? Nearly every "Senior Developer" I've worked with hasn't been senior at anything and seems to be senior in terms of tenure and not skill.
    Well yes, that's actually what it means in a lot of places, and although there's an implicit assumption that seniority == experience, what management often overlooks is that sometimes also seniority == senility.
  • (cs) in reply to BentFranklin
    BentFranklin:
    ...And never complain about the proofreading because that requires a second set of eyes, which I suspect Alex does not possess.

    I've seen at least three names other than "Alex Papadimoulis" in the bylines of TDWTF articles. Is your suspicion that these people are all really Alex in disguise, or that none of them have eyes?

  • (cs) in reply to Someone You Know
    Someone You Know:
    BentFranklin:
    ...And never complain about the proofreading because that requires a second set of eyes, which I suspect Alex does not possess.

    I've seen at least three names other than "Alex Papadimoulis" in the bylines of TDWTF articles. Is your suspicion that these people are all really Alex in disguise, or that none of them have eyes?

    I thought he meant that Alex doesn't wear glasses.

  • Bim Job (unregistered) in reply to DaveK
    DaveK:
    Ed:
    That depends on the functionality you are trying to achieve: you try writing a monte-carlo neural network simulation framework without doing some very crazy pointer based nonsense.
    The alternative hypothesis to your theory that there is only one possible way to write a monte carlo neural network framework and therefore C++ is a bad language, is that you simply lack the knowledge and skills to envisage an alternative way of doing it, and C++ is just fine.
    That was kind of my supposition, too. There's nothing obvious about a Monte Carlo neural network framework that requires anything of the kind. I'm thinking shedloads of templates, creative use of the STL and graph-building packages, and also concepts -- which unfortunately don't exist.

    I'm sure crazy use of pointers would speed up some of the bits that aren't broken. I'm equally sure that direct implementation in Assembler is a rather better case, if that's really necessary.

  • Quirkafleeg (unregistered) in reply to Bim Job
    Bim Job:
    I'm sure crazy use of pointers would speed up some of the bits that aren't broken. I'm equally sure that direct implementation in Assembler is a rather better case, if that's really necessary.
    Probably. But then you're maintaining at least two versions: one in C or some other high(er)-level language, and at least one asm version.

    If you're targetting one particular CPU type, fine, you can probably get away with just the asm, but then that's probably embedded.

    What?

    Oh, all right then. Probably embedded and without a file system.

  • Not frist (unregistered) in reply to Anon-y-mouse

    [quote user="Anon-y-mouse"][quote user="Doug"][quote user="frits"] The secondary reason is to make casts stand out more visually: "An ugly operation should have an ugly syntactic form."[/quote]

    In C++ pretty much everything has "an ugly syntactic form.".

    [/quote]

    Umm... That's deliberate, to discourage you from writing code in C++ </Flamebait>

  • Ouch! (unregistered) in reply to AA
    AA:
    TRWTF is that Alex doesn't realize <int> needs to have the angle-brackets escaped if it appears in regular HTML.
    But at least he knows how to close his tags :)
    View Page Source:
    so we can write 'someNumber = Cast<int></int>dataObject'
  • Dmytry (unregistered) in reply to Anonymous

    On the last one. Are you guys total morons, or complete idiots?

    It is writing HTML that's to be sent to a client, and it's optimizing the size of that HTML for slow connections, by removing some whitespace, at expense of script run time, which is likely to be entirely insignificant.

    [ on the second, its a bit weird indeed if the cache is being read from in some different place. The first isn't a WTF, it lets you search for the cast; anyone who in fact EVER used C++ should be familiar with this (dynamic_cast, static_cast, etc), and furthermore anyone who used c++ and doesnt understand the casts and difference between them is a noob and should better refrain from any commentary ]

  • foxyshadis (unregistered) in reply to Jay
    Jay:
    frits:
    This not only compiles, but signal my intent to cast "I Like Puppies!" to a long. I'm not sure where this could ever be useful.

    That would be useful if you only like long puppies, like daschunds.

    Wish I could vote this comment for the blue!

  • Quirkafleeg (unregistered) in reply to Norman
    Norman:
    It doesn't refer to the monetary unit, but the weight unit (really force if you are pedantic), i.e. 5# potatoes.
    No no no. Potato products. 5 # browns, for example.
  • Andreas (unregistered) in reply to Anonymous
    Anonymous:
    Debuggery:
    I was about to say the same thing. Anyone who thinks the first one is a serious WTF has never had to search for a bloody C style cast.
    Hardly surprising, considering this isn't even C.

    You, dear sir, are a moron.

  • raj (unregistered) in reply to Anon-y-mouse

    [quote user="Anon-y-mouse"][quote user="Doug"][quote user="frits"] The secondary reason is to make casts stand out more visually: "An ugly operation should have an ugly syntactic form."[/quote]

    In C++ pretty much everything has "an ugly syntactic form.".

    [/quote]

    so C++ was designed to discourage its use ;)

  • nulla (unregistered) in reply to Ed

    TRWTF is

    Ed:
    writing a monte-carlo neural network simulation framework

    in C++. Or C.

    Static typechecking is way overrated. Testing is underrated.

    Captcha: nulla (E van Vogt?).

  • Anonymous Coward (unregistered)

    The real WTF here is that in a proper OO codebase there's exactly zero need for casting.

    But no codemonkey knows this. Because codemonkeys think that since they know how to code in Java/C# they know OO...

  • Works in a Team (unregistered)

    That's the reason for many WTFs in this world - people showing off how smart-ass and witty they are about others' mistakes. Like, come on, was it that difficult to tell this Senior Programmer that this does not do what he wanted, and make the world a better place ?

    Instead of making a fool of yourself, my College Student friend.

  • Schol-R-LEA (unregistered)

    Call me weird, but from the title I had assumed that this posting involved someone doing something bizarre in an FP language like Haskell (where 'pointless design' is a common approach, if somewhat hard to master).

Leave a comment on “Rendered Pointless”

Log In or post as a guest

Replying to comment #:

« Return to Article