Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ehnus
Apr 16, 2003

Now you're thinking with portals!
code:
class SomeClass
{
public:
    SomeClass( const SomeClass& )
    {
        assert( 0 && "This constructor should not be called" );
    }
};
:v:

Adbot
ADBOT LOVES YOU

ehnus
Apr 16, 2003

Now you're thinking with portals!

Avenging Dentist posted:

Also my favorite is still
code:
#define private public
#define protected public

I've done that occasionally for writing test code (along with "#define class struct" :shobon: ) but, yeah, finding it in something that's about to ship always amusing.

ehnus
Apr 16, 2003

Now you're thinking with portals!

Factor Mystic posted:

I'm skeptical that goto has a valid place outside of perhaps some simple scripting. I challenge you to show me a valid example of goto use in modern object oriented code.

Two that come immediately to mind are breaking out of nested loops in C/C++/C# and cleaning up/freeing resources upon failure in environments that do not provide exceptions. I've used them when I've written parsers too as there was no other clear way of providing similar functionality.

Linus Torvalds addresses the use of "goto" in the Linux kernel with some good points here.

Yes, they can turn code into an unreadable mess but, sometimes, they can also make code more readable and more intuitive.

edit: I'm inclined to think that people who believe that "goto" has no place in modern programming languages have not been programming for long enough.

ehnus
Apr 16, 2003

Now you're thinking with portals!
In C# you can use System.Diagnostics.Debugger.Break(). C/C++ often have platform-specific ways of triggering a debug break point, and on PCs there's always interrupt 3. I'm not sure about other languages but they often have their own ways of breaking into the debugger

ehnus
Apr 16, 2003

Now you're thinking with portals!

Ryouga Inverse posted:

Yeah, the SDET we hired is one of those.

He seriously tried to defend the use of global variables.

Really? Global variables? How heinous!

What's next, is he going to say that "goto" actually makes sense in certain situations?

ehnus
Apr 16, 2003

Now you're thinking with portals!
I found a coding horror today:

Zombywuf posted:

Get a better compiler or write it in asm. If you're second guessing your compiler's interpretation of instruction cache usage, you have a problem.

If you don't have a healthy paranoia of the code your compiler generates then you probably haven't been developing for very long. Not every platform has the luxury of being able to switch to a potentially better compiler either, not to mention that writing it in assembly because of it's C/C++ line count is just dumb.

ehnus
Apr 16, 2003

Now you're thinking with portals!

Zakalwe posted:

That's not a horror, that's an extreme optimisation for an operation done a lot in many renderers. Low accuracy bitwise hack combined with one Newton-Raphson iteration.

It's a coding horror for any x86 (post-1999) or PowerPC based computer.

ehnus
Apr 16, 2003

Now you're thinking with portals!

julyJones posted:

I wrote some C# code last week that made me laugh later:

session.Close();
session.Dispose();
session = null;

The next day, I see this article on Reddit:
http://www.codinghorror.com/blog/archives/001211.html

I brought it up to the other guy on the project, who assured me he did not submit the code in question. He then politely introduced me to the "using" statement. :)

There are some people that shouldn't write about programming. Jeff Atwood is one of them.

Relying on the garbage collector to free resources other than memory (sockets, database connections, etc.) is pretty dumb because the behaviour of the GC is determined only by the state of the heap. If you run out of space in the active portion of the heap it will collect but if you depend on finalizers to clean up other resources you can easily run into problems where the resource is exhausted and the GC hasn't yet run. The GC doesn't care if you've hit your connection limit or whatever because it's just monitoring heap activity.

If you're using unmanaged resources (sockets, files, database connections, etc.), dispose of them after use and don't let the GC clean up after you if you want consistent performance and behaviour.

ehnus
Apr 16, 2003

Now you're thinking with portals!

julyJones posted:

That is my thinking as well, so I disagree with the article a bit. It was funny though to see code almost identical to mine appear on a WTF-type blog.
I like to code defensively, so I'd honestly probably do the same thing again if I hadn't learned about "using". As I understand it, it's basically syntactic sugar for calling Dispose() in a finally block on whatever you're "using".

Yeah, that's exactly what using does, it's pretty handy.

ehnus
Apr 16, 2003

Now you're thinking with portals!

Erasmus Darwin posted:


Worst of all is the use of "if (x) { return true; } else { return false; }". What an awful idiom to be teaching to people.

A coworker stumbled across this and forwarded it to me:

code:
BOOL SomeWin32Function(DWORD param);

bool Function( uint32_t param )
{
    bool mybool = SomeWin32Function(param);
    int myint = (int) mybool;
    
    switch(myint)
    {
        case 0:
            {
                return (bool) 0;
            }     
            break;
        case 1:
            {
                return (bool) 1;
            }
            break;
    }
}
*sigh*

ehnus
Apr 16, 2003

Now you're thinking with portals!

Flobbster posted:

The "not" operator is a redundant feature? :v:

No, but "unless" certainly is.

ehnus
Apr 16, 2003

Now you're thinking with portals!

pokeyman posted:

What's the difference? Isn't "unless(statement)" identical to "if (!(statement))"?

e: Come to think of it, isn't "if" redundant if you have goto? And "else" is sure overrated hey? I just jump right there. Surely we don't need for loops if we have while loops. Why have a break statement when you can just use a flag?

When does "arbitrary" cross into "quite helpful" for you? Especially if it boils down to the same instructions in the end.


Sorry to break it to you but "unless" is redundant as it does the same thing as using if with a negated condition but saves no typing and some (like myself) might even say it does nothing to improve code clarity or comprehension.

ehnus
Apr 16, 2003

Now you're thinking with portals!

Ryouga Inverse posted:

"If not (whatever) do this" is less clear to you than "unless (whatever) do this"? I mean, one of them is a common English construct.


There are many common natural language constructs that have no business whatsoever belonging in a programming environment. In my case I find "unless" somewhat foreign (and less clear than if-not) because I'm largely steeped in C#/C++.

If you can't figure out how to negate a boolean expression and require keywords like "unless" in your language then you probably aren't going to be a successful programmer.


pokeyman posted:


Calling something "redundant" doesn't imply it's a worthless feature; we've covered this. Stop using that as a crutch, and just explain your opinion.

It's simple - redundancy breeds inconsistency and inconsistency leads to incomprehensible code bases. Probably the worst example of this is Perl because there are so many ways to express the same functionality. Each programmer has their own idea of what they like, one may use "if (!condition) { blat }", another "blat if (!condition)", a third may use "unless (condition) { blat }", and a fourth "blat unless (condition)".

When I'm working in an area of code that other people are working on and I come across something that isn't what I would think as idiomatic my mind is divorced from finding out what's going on in the code temporarily to figure out why the pattern was chosen. This is where coding standards come into play -- they help enforce consistent styles and practices so that people only really need to think about the problem at hand rather than why certain syntactic elements in the code were chosen. But if your coding standard dictates which of the conditional styles above are to be used then you've eliminated the need to have the alternate methods at all. If this is the case then redundancy has lead to these language extensions being worthless.

ehnus
Apr 16, 2003

Now you're thinking with portals!

ymgve posted:

Is this actually enough for a computer to be Turing complete?

Yes.

ehnus
Apr 16, 2003

Now you're thinking with portals!

Zombywuf posted:

Nothing wrong with writing their own STL implementation for consoles, apart from STL implementations being a dime a dozen. Or with writing their own STL for performance reasons (the EASTL doc reeks of crazy though). Instead they decided to use their own array object for compatibility reasons?

Really the EASTL doc reads like it was written by a genius, about 20 years after his peek, just as he's starting to be destroyed by drink.

Paul is a genius, and you couldn't be more wrong on everything else. There isn't any "crazy" in EASTL beyond what has been required and requested by internal game development teams.

ehnus
Apr 16, 2003

Now you're thinking with portals!
I have no problem with #if 0 ... #endif but it's nearing horror status when it gets checked in.

ehnus
Apr 16, 2003

Now you're thinking with portals!

Flobbster posted:

This is considered safer in languages (like C and Objective-C, assuming by your example), where any expression is allowed inside an if clause. It's meant to prevent errors caused by accidentally using = instead of ==:
code:
if (img = nil) { ... }
This will compile fine and give the wrong results, but if (nil = img) will fail to compile.

Technically it isn't necessary if the operator is !=, but the author is just doing it for symmetry's sake.

What compilers these days don't warn about assignment in a conditional?

ehnus
Apr 16, 2003

Now you're thinking with portals!
Encountered today:

code:
public:
//private:
It's not as elaborately and stupid as most of these other coding horrors but it still makes me wonder what the intent was, why this was done, and if I can change it back without breaking people who may be depending on these private members now being public.

ehnus fucked around with this message at 04:32 on Apr 14, 2010

ehnus
Apr 16, 2003

Now you're thinking with portals!

A A 2 3 5 8 K posted:

Always make backward-incompatible changes after consulting a group of strangers on the internet but before consulting your team.

That wasn't a question for this thread, I guess my original wording wasn't clear enough.

I know who made this change but they are no longer with my company.

Adbot
ADBOT LOVES YOU

ehnus
Apr 16, 2003

Now you're thinking with portals!
I found this method in a C++ mutex class the other day:

code:
bool IsThreadSafe() const { return true; }

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply