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
Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

dwazegek posted:

I have a colleague who also does stuff like this. For whatever reason, he refuses to use return anywhere, except the last line of a method. This frequently results in methods with absurd amounts of indentation, or stuff like this:

code:
public bool HasValidItems(SomeClass[] items)
{
  bool retVal = false;
  foreach(SomeClass item in items)
  {
    retVal = retVal || item.IsValid;
  }
  return retVal;
}

public SomeClass FindSomeItem(SomeClass[] items)
{
  SomeClass retVal = null;
  foreach(SomeClass item in items)
  {
     if(item.MatchesWhateverWeAreLookingFor)
     {
       retVal = item;
     }
  }
  return retVal 
}
Who cares if we've already found what we're looking for, let's keep on looking :cool:

It's an application of the Single Function Exit Point philosophy, with which I don't agree. I think it's good for some issues, especially resource management, but largely you want to use RAII for that anyway, and code can get very messy if you can't bail out early (goto, anyone?).

Adbot
ADBOT LOVES YOU

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

rotor posted:

When I used to work in the build department, I inherited some real doozies. The build scripts were giant shell scripts running under MKSTools. Probably half of the code we compiled was generated by a process I won't pretend I even came close to understanding. There was a lot of necessary complexity because we built for a shitload of different platforms, but one thing really stuck out.

The guy who wrote the bulk of the build scripts really wanted inheritance in his shell scripts. In order to accomplish this, the script searched through the 'parent' shell script for a particular line (not some kind of obvious comment delimiter like "#---THIS IS A DELIMITER---", just another line of a shell script), then took that line and the next 50 or however many, and piped it to a file. He then sourced that file, deleted it, then called functions that the now-deleted file had. It must have taken me a week to figure that poo poo out. And he did it in like four places.

:psyduck:

It blows my mind that anybody that would know how to do that would actually do it.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

such a nice boy posted:

Dude, whitespace changes can be incredibly annoying, and sometimes autocorrect functions don't work well.

The horror... the horror. - Col. Kurtz, ~1970

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

chocojosh posted:

In all seriousness then, how would you encode N different options that can be on simultaneously? I always assumed the bitmask would work (and I would go so far to say that it is a simple and clear solution that should be efficient enough for small cases, n <= 8 or n <= 32).

std::vector<bool> AFAIK is almost always implemented as a bitfield that uses proxy objects to modify its 'bool references'. I doubt that the 31 bits you save per bool really add up to anything significant, but it's a simple solution at least.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

chocojosh posted:

Alright, so then you also second the bitmask suggestion (which means I'm not totally crazy).

In C++ you can use the bitset

No, that's just a viable alternative if you're retarded and don't want to go with the prime factorization solution. Why would you use dynamic memory at runtime when you can quickly run through a sieve of eratosthenes and get some valid, unique flags?

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

Flobbster posted:

I'm surprised nobody has mentioned this advantage yet. If I remember my Win32 API correctly, there's a window style called WS_EX_THICKFRAME. But it doesn't let me control the degree of thickness.

code:
DWORD exStyle = WS_EX_THICKFRAME; // thick
DWORD exStyle = WS_EX_THICKFRAME | WS_EX_THICKFRAME; // DAMMIT IT'S NOT THICKER
How restrictive! But if we redefined the styles to use prime numbers, imagine the thickability:

code:
DWORD exStyle = (DWORD) pow(WS_EX_THICKFRAME, 10);
Now THAT'S a thick-rear end window frame that will draw the attention that my awesome application deserves. I mean, come on.

WS_EX_GIRTHYFRAME will do that too.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED
GCH is leaking! :supaburn:

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

yaoi prophet posted:



Haha, I love the 1/2 being 0%. Some of the int-float-int-float conversion that I see sometimes is sickening. The compiler really should be stricter when you're going to 'promote' and lose data :(.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

ShoulderDaemon posted:

Why? If you're about to dereference a pointer in a dynamically-allocated structure, then there's a very good chance you've lost memory locality and are about to stall on memory access anyway, so the check is essentially free. It inflates code size slightly, so I wouldn't do it inside a tight loop, but I'd be trying not to traverse large structures in a tight loop anyway.

Because as expensive as LHSes are, mispredicted branches can still hurt quite a bit on modern architecture. Remember, the fastest and least buggy code is the code that's not run, or ideally never written.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

TSDK posted:

Hungarian notation is an old technique that has no place in modern C++ programming, but there are one or two odd exceptions which are either genuinely useful, or are a strange hang-over.

Well, not really. It was originally intended to give context to the variable's usage, not type. So you might prefix something with 'idx' or some such to indicate that it's an index, but you wouldn't put the type in the variable name since that's just stupid.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

tripwire posted:

God I hate hungarian notation. How in the hell did anyone ever think it was a smart idea :psyduck:

Its original intent - to document the purpose and usage of the variable - was a great idea. Somehow it got perverted into being only the type, which is obviously useless.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

tripwire posted:

At the risk of opening a can of worms, its retarded in either form. You are only adding more headaches for yourself later on.

I'm not some hungarian evangelist - I'm just saying its current usage is unambiguously worthless, but its original intent had potential to make more readable, self-documenting code. Not that it matters since most of us don't get to decide on the coding style for our particular codebase anyway.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

geetee posted:

There is no way &1 even compiles (right?) so I don't understand what this entire fiasco is about. The logical operator "AND" requires two ampersands, not one. I'm surprised none of your IDEs warned you about this. It's just a segfault waiting to happen. Just use modulus and move on.

There's more than one kind of 'AND'... :ssh:

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

No Safe Word posted:

*whoooosh*

edit: or "look at you, look how stupid you are" I guess

I guess I would have been more suspicious of a fakepost if it was funnier? I.D.K.

Adbot
ADBOT LOVES YOU

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED
code:
bufferIndex++ %= 2;
(C++)
Just saw this at work, someone should tell this chucklefuck that there's only one sequence point here. :argh: :siren: :ohdear:

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