- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
So, why not just go and replace all of those macros? Simple sed -i (or perl -ip, or whatever tool you like).
Admin
Don't use macros in C++. Don't use the OFFSET_OF() trick. Don't try to beat the compiler's ability to inline. Don't sprinkle your code with #ifs and #ifdefs. Learn the ways to avoid these things. C++ code can be almost as clean as Java or C# tend to be if you don't litter your code with crap.
Admin
I don't think he was posting to TDWTF to get tips on how to resolve said ball of yarn. I believe he was attempting to illustrate the misjuided attempt of his predecessor(s) at a design pattern (of which my personal fave is the foreach-switch pattern).
I'm sure a CTRL-A, SHIFT-DELETE at the root application folder would also suffice, but then again this may be a little extreme.
Admin
Dear Colleague,
I am needing of the header file to include to overload double pointer indirection operation to perform exponent calculation. Can you send this plz?
Sinceerely, Your friend, Rajendra Kumar
Admin
Wow, Nagesh's boss is posting here too...
Admin
Paschal: adj. Having to do with the Jewish festival of Passover. (Maybe you meant "Pascal"?)
Admin
Shh! Careful saying something like that! There might be Lispers around!
Admin
Admin
On a related note, Haskell has a semi-macro language in the form of template-haskell, but it's a bit closer to reflection than a macro in that it's fully typed and must pass type checking at compile time relative to the rest of the code. The compile process basically goes Template-Haskell + Haskell to Haskell to Object to Linked Binary. The nice thing is that if it passes the first step it's pretty much guaranteed to pass the second one. The idea behind TH isn't to fix any particular shortcoming of the language, but to allow you to eliminate as much boilerplate code as possible by encapsulating it all inside of functions that get evaluated at compile time.
Admin
Macros can be good. Although I would like to get rid of them other ways, here's a pattern I keep hitting: suppose you have a polymorphic data type (say, a string from an XML file) that needed to be processed by a templated function (templated by its type). Assume for a second that getting the type as an enum is easy. The best way I can figure out how to call the appropriate function is with a switch. Since the same logic appears with the same enum type in different places (with different function calls), macroing that switch seems to be the best solution.
Please tell me I've been doing it wrong, and I will gladly refactor my code.
Sometimes, just sometimes, I know better than the compiler when it comes to inlining.
#if/#ifdefs can be useful for a few features (how else do you handle cross-platform issues when it's a 3 line change in a larger class?) Or turning off sections of the code as a debugging technique. Or maybe you're familiar with the #ifdef _DEBUG used for asserts?
Admin
Macros can be good. Although I would like to get rid of them other ways, here's a pattern I keep hitting: suppose you have a polymorphic data type (say, a string from an XML file) that needed to be processed by a templated function (templated by its type). Assume for a second that getting the type as an enum is easy. The best way I can figure out how to call the appropriate function is with a switch. Since the same logic appears with the same enum type in different places (with different function calls), macroing that switch seems to be the best solution.
Please tell me I've been doing it wrong, and I will gladly refactor my code.
Sometimes, just sometimes, I know better than the compiler when it comes to inlining.
#if/#ifdefs can be useful for a few features (how else do you handle cross-platform issues when it's a 3 line change in a larger class?) Or turning off sections of the code as a debugging technique. Or maybe you're familiar with the #ifdef _DEBUG used for asserts?
Admin
No, it was the fact that they were trying to implement java interfaces through macros.
Admin
Admin
That's the ... problem, I guess. I mean, maybe these languages have a place.
It's nice to know that there are languages that, for the most part, attract all the coding flies. Sure, programmers sometimes use them too, but the "hey I need help in PHP/VB" post (usually) tells us we're dealing with someone who CAN'T count to his IQ.
The other way to tell is when they insert lolcat speak in their posts.
Admin
Who can't count to 10?
kthkbai
Admin
Admin
Admin
Admin
What about using an abstract factory so that you only need one switch?
Admin
Admin
Wow, I guess I need to focus on what matters and really brush up on my lolcat speak...
I think I'll just leave the (un?)intentional buffoonery to the fictitious frits.
Admin
Define "have to type" in this context. I write in Delphi, and I can get the IDE to fill in most of the boilerplate automatically for me. Does that count?
FWIW I don't consider having code with a familiar, predictable structure ("boilerplate") a failing of the language; I see it as a readability aid. If every single expression in your program is unique, as the Cult of Paul Graham seems to believe is the ideal state of source code, how are you supposed to be able to become familiar with it, seeing as how the human brain is first and foremost a pattern-matching engine?
Considered in conjunction with the fact that the great majority of coding time for any serious program these days is spent in maintenance and not in initial development, and it's hard to escape the conclusion that an exceptionally high degree of "expressiveness" (again, as defined by Paul Graham) is, objectively speaking, a negative language feature, not a positive one.
Admin
All programming languages are garbage. Deal with it.
Admin
Admin
Admin
Oh yeah, LOLCODE. Hilarious.
Admin
Also, does repeating the ( and ) character count as boilerplate?
Admin
I don't know if no-code counts as a code-related WTF...
Sitting around doing nothing other than watching pr0n for 6 months is (technically) a WTF however this can be achieved on any platform or language.
Admin
I think that if you are repeating lines statements, that's one thing (call this method with these parameters to set up the database connection and get back a connection object). If you have have to copy-paste more than a couple of lines then it is probably boilerplate which can be refactored.
If you are thinking something along the lines of: I should put this in a macro so I don't have to do all of this stuff every time; that's a sign that a refactor is due (and no, adding a macro is not the answer)
Admin
Looks like code written by a Pascal or Delphi developer...
Anyone else here play Space Empires V? The scripting language looks like some horrible bastardization of Pascal... I don't remember the exact syntax but it looks something like this:
deffunc addten params xyzzy: integer endparams vars retval: long endvars returns long begin set retval := call Sys_Exec_Gratuitously_Long_Function_Name_Which_Converts_Integers_To_Reals_In_SPAAAAAAACE xyzzy return retval call Do_Other_Stuff_After_We_Return_Yes_This_Is_Possible_OMG end enddeffunc
Admin
Ouch! Looks like someone trying to copy Pascal but they were more comfortable with BASIC. Or... something.
Admin
He may be right. In our shop 8 out of 10 project use some java. 1 use Powerbuilder / D2K / VB 6 etc and 1 use .NET language.
We like to hire people who have all round vision.
Admin
Your stick is getting old. You are doing that since calendar code you ask many many ages ago.
Admin
Speechless... Just, speechless...
Admin
David Kaye is one of the best names I've seen on this site, yeeees.
Admin
If only my post was meant to indicate that, contrary to Vacaloca's theory, there have been many code-related Java WTFs on this site, concise or otherwise.
Of course, each of these WTFs was due to the programmer being a total halfwit, and not failings of the language. But I don't suppose anyone can look past the real reason that crap code exists when they have the chance to bash languages that they personally don't like.
Admin
Admin
booger, If you don't care, stop saying it loudly. It disturb my flow of thoughts. As is trying to translate all these symbols and letter is playing short-circuit with my brain cells.
Admin
Stroustrop said it best: "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off."
Admin
Admin
I don't get it. Why do people treat what language you (primarily/exclusively) use like it's some religious trait worthy of a declaration of war? Are we not all telling some machine to do something?
The people who think web development isn't serious programming are just trolling out the wazoo. They're probably kernel developers, which, as we all known, is very serious. Indeed, kernel developers aren't allowed to even look at code written in a language besides C or assembly lest they be tainted by the sin of OO or functional programming like some 50-year old nun whose hand touches the cashier's while buying lamp oil at the market.
After all, if you've never committed an accepted patch to the linux kernel, errrrrrr, have your changes merged to the trunk of the kernel's git repo, you're not a real developer. So why bother talking about the differences between languages if you're not even a real developer?
Admin
Admin
Admin
Here here!
Admin
Admin
Not especially. You're right, the macros seem to be trying for something like a Java interface, but the whole macro thing would be completely alien to any Java programmer. No preprocessor directives in that language, and the syntax used is totally alien.
Admin
Admin
Admin
Admin