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
Presto
Nov 22, 2002

Keep calm and Harry on.

Bonus posted:

Ultimate variable naming scheme
Once when I was looking at some files for a MUD I used to work on, I found some code that went something like:
code:
int eger;
int egral;
int yacis; // Yes A Cow Is Smelly
I don't know.

One of the creators of the MUD had a penchant for naming variables things like bing, blue, rabbit, or womble; and his RCS comments half the time are something like "fixed up the thingy a bit". I think he works for Google now. (If you're reading this, Hi David!)

Adbot
ADBOT LOVES YOU

Presto
Nov 22, 2002

Keep calm and Harry on.

Painless posted:

That's pretty likely to go boom on GCC FYI
Should be fine, although it may bitch about violating strict aliasing rules.

Presto
Nov 22, 2002

Keep calm and Harry on.

Painless posted:

It won't "bitch", but it's quite possible that it will randomly fail! Just use unions drat it. Jeet chirst this is making me so angry. What nubbery..
Strictly speaking, this:
code:
union {
    int i;
    float f;
} butts;

float x;

butts.i = 666;
x = butts.f;
is not guaranteed to work either. You can't assign to one union member and then read another union member of a different type. The exception is that if the union members are structures with the same initial sequence of members and the union currently holds one of those structures.

Presto
Nov 22, 2002

Keep calm and Harry on.
Just now found a classic:
code:
i = (++i) % j;
...in 5 places in the same file.

Presto
Nov 22, 2002

Keep calm and Harry on.

Not UNIX posted:

Are you using AS2 or AS3? The definition in AS2 is public static get([index:Number]) : Camera, and in AS3, it's getCamera(name:String = null):Camera.
Yes, but:

Adobe posted:

name:String (default = null) — Specifies which camera to get, as determined from the array returned by the names property. For most applications, get the default camera by omitting this parameter. To specify a value for this parameter, use the string representation of the zero-based index position within the Camera.names array. For example, to specify the third camera in the array, use Camera.getCamera("2").

Presto
Nov 22, 2002

Keep calm and Harry on.

Flobbster posted:

Sadly I was never able to figure out how to duplicate it reliably. Sometimes forcing -O0 would fix it, but then on another student's code it would be broken under -O0 but -O3 would work instead.
gcc is just bizarre like that. I was working with code similar to this:
code:
somevar = someval;
if (somevar != prev_somevar) {
    do_something();
    prev_somevar = somevar;
}
With -O2 gcc apparently decided the 'if' block was not needed and optimized it away, so the code failed; but with no optimization, it worked perfectly. If I stuck a printf before the 'if', then it would work with -O2.

I ended up having to declare somevar volatile to fool the optimizer.

Presto
Nov 22, 2002

Keep calm and Harry on.

No Safe Word posted:

What is an unaigned int ??
An off-by-one error. :v:

Presto
Nov 22, 2002

Keep calm and Harry on.
code:
int zero = 0;
int one = 1;
int four = 4;
int five = 5;
int nine = 9;
:psyduck: This occurs in several files, with different combinations of numbers. And there are occurrences of things like this:

code:
for (i = zero; i < 15; i++)
It's like someone heard that magic numbers in code were bad, so they just thought they'd name them all, and the most obvious name is of course the word for that number. Or maybe they were guarding against the day when the value of 4 changes.

Presto
Nov 22, 2002

Keep calm and Harry on.

mr_jim posted:

This thread just came full circle.
Maybe it's the same guy. :aaa:

Forgot about this part too: double dzero = (double)0.0;

Presto
Nov 22, 2002

Keep calm and Harry on.

BigRedDot posted:

code:
char * FML = api->GetPoint(x,y)->getOutput()->getOutputDataSet()->getOutputData()->get(size)->getResultSet();

The real horror to me with this one is that I know exactly how it was obtained, because I had to write a slew of code identical to this.

You're digging your way down through a pile of auto-generated code to get the thing out that you actually want.

Presto
Nov 22, 2002

Keep calm and Harry on.

Pardot posted:

and so on up to arg249
Should have gone to arg255. Everyone knows if you're going to pick an arbitrary point to stop at, you pick a power of 2. That way people think there's some deep-seated reason for it.

Presto
Nov 22, 2002

Keep calm and Harry on.

Scaevolus posted:

"<< 1" instead of "* 2" is generally a horror.

Well, assuming this is C/C++, plus is higher precedence than shift, so what that actually does is
code:
bd = &bdt[USTATbits.ENDP << (1 + USTATbits.DIR)];

Presto
Nov 22, 2002

Keep calm and Harry on.

dietary supplement posted:

Edit: I had tested it with 2* in there, but then switched it to <<1 because I'm so clever!!
It's generally a bad idea to mix bitwise operations with arithmetic operations. You can either do (A << 1 | B) or (A * 2 + B); but, as we have just seen, you're asking for trouble if try to do both at the same time.

Presto
Nov 22, 2002

Keep calm and Harry on.

angrytech posted:

If you are using an IDE that doesn't allow you to set the number of spaces defined by a tab, then you a scrub.
I don't use an IDE. And I indent with spaces. :smugdog::pipe:

Presto
Nov 22, 2002

Keep calm and Harry on.

Volte posted:

If you ever come to a point where you think "A goto would be really easy here, otherwise I'll have to add in a bunch of boolean flags and conditionals to code my way around it" and then add in the boolean flags and conditionals, you're doing it wrong
If you ever come to a point where you think "A goto would be really easy here", you're probably already doing it wrong. :)

Presto
Nov 22, 2002

Keep calm and Harry on.

Internet Janitor posted:

to this. Does anybody still intentionally write method signatures like that? What is the deal with that hostent pointer?
It's prototyping the gethostbyaddr function. I guess netdb.h didn't exist at the time.

You shouldn't be calling it now anyway because it's obsolete (so I guess it's a good thing it wasn't used). Use getnameinfo instead.

Presto
Nov 22, 2002

Keep calm and Harry on.

SlightlyMadman posted:

I can't remember for the life of me, but I was working with some horrible scripting language not long ago that would actually throw AN ERROR if you tried to do that CORRECTLY. Declaring "int i" a second time would tell you that i was already defined. I ended up having to declare all of my iterators at the top of the function.
I know Adobe Flexbuilder bitches if you do 'for (int i; ...' more than once. I think it's just a warning though.

Presto
Nov 22, 2002

Keep calm and Harry on.

Look Around You posted:

:stare:

Jesus christ what the gently caress. Why do people still use this garbage?

You can do similar things in makefiles. I've made use of it. :ohdear:

It's kind of like driving to work in a tank. It makes some things much easier, but it's likely to end in disaster.

Presto
Nov 22, 2002

Keep calm and Harry on.

seiken posted:

I kind of agree in principle but really references are an awesome language feature and IDEs these days should totally be able to pop up a signature with the &s there for you to see as soon as you type the ( :toot:
And then one day you'll be stuck on an ssh connection into a remote box to try to fix some crucial problem and the only thing you'll have is vi. Where's your IDE God now, Buster? :colbert:

(I don't like references.)

Presto
Nov 22, 2002

Keep calm and Harry on.

DStecks posted:

The typo had no tag. This typo had been undetected and part of a program that ran every day, and somehow never caused an abort, in 20 years.
Welcome to software development. I've fixed one-in-a-million bugs you would expect to see once in a blue moon that occurred every 10 minutes; and bugs in heavily-used code that somehow hadn't been triggered in 5 years.

It's a funny business.

Presto
Nov 22, 2002

Keep calm and Harry on.

bucketmouse posted:

Also regarding the hello world chat: I the only one who considers C++ streams a horror in the context of people learning to program?
I think they're a horror in any context.

Presto
Nov 22, 2002

Keep calm and Harry on.

beoba posted:

Just be glad you aren't using ClearCase. I left a place in 2010 which was still using it at the time. Here's a brief summary of a typical user experience:


If you imagine streams of blood coming out from between this person's fingers, that's my experience with git. I think git was literally invented by Satan to cause chaos on the mortal plane.

Presto
Nov 22, 2002

Keep calm and Harry on.
code:
retflag = (retflag == 2) ? 2 : 0;
If it's two, put in a fresh two, because the original two might be getting stale.

Presto
Nov 22, 2002

Keep calm and Harry on.

baquerd posted:

Other than readability, I just don't see a huge problem here.
It's not a big problem, just pretty dumb.

Volmarias posted:

Edit:
retflag = !((retflag >> 2) || (retflag << 30))*2 maybe?
What have I done? :ohdear:

Presto
Nov 22, 2002

Keep calm and Harry on.

QuarkJets posted:

It's exactly for the reasons that you say; the older crowd wants to keep using FORTRAN and IDL because that's what they've always used, whereas the younger crowd wants to use Python and C++ because it's what they learned in school (and a lot of other reasons)
Many moons ago at work we were trying to get a certain mathematical model to run on some digital signal processor chips. The code was in Fortran, but the DSPs only had a C compiler so we had to convert it. We used a commercial tool for most of it, but some of the functions were such a convoluted tangle of computed GOTOs that the converter just took one look and poo poo itself.

Long story short, we eventually got it all converted to C. It still wasn't pretty, but it was better. We offered the C version back to the group who provided the original Fortran source.

They didn't want it.

Presto
Nov 22, 2002

Keep calm and Harry on.

evensevenone posted:

You have to realized that anyone still working in FORTRAN has been told by well-meaning-individuals who don't actually know what they are talking about that "C (or C++ or Java or Python or Boost) is better" for literally 40 years now.
Just to clarify, I'm not some rabid Fortran hater. We use another model written in Fortran that's actually pretty nice. It's clean and relatively easy to follow. The code I was talking about earlier though, not so much.

Presto
Nov 22, 2002

Keep calm and Harry on.

Sailor_Spoon posted:

Also, git is the best.
Git is a torture device invented by Linus Torvalds because he secretly hates programmers. :colbert: (I hate git.)

Presto
Nov 22, 2002

Keep calm and Harry on.

Doctor w-rw-rw- posted:

Though, frankly, the idea of most people using Git actually cargo-culting based off of some other DVCS instead of learning how it works is a horror.
The problem is that I've tried to learn how it works. We had tutorial meetings about it at work. I've read all the sites. But there's just something about it that I just. don't. get.

The other problem is that it's insidious. Every time I think I finally have a handle on it, it does something that I can't fathom. "OK, I'll just do a pull here and... wait, how can I have a merge conflict in a file that I haven't loving touched?" And if you gently caress something up with git, then God help you. We used to use CVS, and yeah, it's primitive; but if something got trashed at least I could fix it manually if I had to. :( Now my work computer is littered with directories called things like "wtf.git", "git.poo poo", and "fuckyougit" because usually it's just easier to clone the repository again and start over than to figure out how to undo whatever just happened because I cast the wrong git spell. Not to mention the commits I have with a comment like "WTF just happened?"

Right now I just have a series of commands that I follow that I don't really understand, but that do what I want. Hooray for cargo cult revision control!

Presto
Nov 22, 2002

Keep calm and Harry on.

Gazpacho posted:

This can happen if you have your editor set up to mess with files when opening them (or when saving them without any changes), or you're in the habit of committing files without doing a once-over review of what you're committing, or if you did the once over and committed irrelevant changes while giving no fucks.
Except I've had it complain about files that I have literally never looked at. Because they're java. :v:

quote:

Whatever the case may be, git provides you the necessary diff tracking to find out what happened and learn from it so you should do that. And god help you if you believe hacking a CVS repo is a reasonable recovery option.
I didn't say it was reasonable, only that it was possible.

And once I had git completely throw away a whole bunch of commits I had just done like they never existed. I'm sure it was something I did, but there's no way to figure out what.

Look, I'm just a CVS guy trapped in a git world, OK? :colbert:

Presto
Nov 22, 2002

Keep calm and Harry on.

Flobbster posted:

CEs can't teach proper programming or software design in my experience, and they have the tendency to (try to) prematurely optimize because they're thinking about the hardware too much instead of trusting the compiler.
Speaking as a CE, compilers over the years have given me plenty of reasons not to trust them. We have a problem right now at work where some code that has worked perfectly everywhere for years now fails when built at one particular site with one particular version of g++. But if you turn off the optimization flag it works OK.

Presto
Nov 22, 2002

Keep calm and Harry on.

b0lt posted:

Sounds like you have some ~undefined behavior~

The good news is that it's 3rd-party code, so if it's broken I take no responsibility. :angel:

But I'm still pretty sure it's g++ loving up again. I've had problems with the optimizer before in an older version where it decided a comparison was not needed when it quite obviously was. (And no, it wasn't ~undefined behavior~.)

Presto
Nov 22, 2002

Keep calm and Harry on.

That Turkey Story posted:

It's not unheard of for an optimization to screw up, though if it's eliminating a comparison I have to ask -- was the code dealing with threads? There are some "bad" idioms dealing with threads that are still probably commonly used but that inadvertently rely on undefined behavior (specifically people relying on volatile to do more than what the standard actually says). A comparison not being performed when a programmer expects that it would could definitely be a symptom of this.

Nope, this was something very simple in a single-threaded app. It was 1. compute new_sum; 2. if (new_sum != old_sum) { do stuff } else { never mind }

The 'if' was getting totally ignored. If you put any additional reference to new_sum in the code, like printing it out, then it worked correctly again. I ended up making new_sum volatile. I think the next gcc revision fixed it (this was somewhere early in the 4.x series I believe) and later the code got rewritten anyway.

I've been unlucky with this kind of stuff throughout my career. One time we had code on a DSP that was failing inexplicably, and we chased our tails for a good while until one of the developers figured out a reproducible case, which got sent to our vendor, who pared the case down further to a couple machine instructions and sent it to the chip manufacturer, who said, "Oh yeah, that's a bug in the processor". This is why I'm old and bitter and distrust all software and hardware. :corsair:

Presto
Nov 22, 2002

Keep calm and Harry on.

quote:

You just have to memorize these names. Sorry.

No, actually I don't.

Presto
Nov 22, 2002

Keep calm and Harry on.

My Rhythmic Crotch posted:

Each directory had a Makefile inside it - something I have never seen before or since.
It's a recursive make system. We have the same thing at my job.

Presto
Nov 22, 2002

Keep calm and Harry on.

Plorkyeran posted:

Recursive make is kind of terrible (it has a lot of overhead, doesn't track dependencies very well, and doesn't parallelize very well)
I had ours parallelized to the point that if I left off the number following the -j option for 'make' it would lock up the OS from trying to spawn a few thousand compiler processes. The fact that this is possible is kind of a horror in itself.

Presto
Nov 22, 2002

Keep calm and Harry on.

revmoo posted:

Git is amazing as long as you don't have coworkers that read HackerNews 24/7 and get distracted by every shiny new thing and come up with ridiculously outlandish branching and merging processes. Then you end up with things that belong in this thread.
Git is amazing in sort of the same way having ebola is amazing.

Presto
Nov 22, 2002

Keep calm and Harry on.
Also, people had been using hacks for concatenation like #define GLUE(a, b) a/**/b. But then they standardized on comments being replaced with a single space, which meant they needed some formal way to do concatenation, which begat ##.

Presto
Nov 22, 2002

Keep calm and Harry on.

Ithaqua posted:

Back to the original "horror": I don't know why it's a horror that every story is 3 points. That can happen.
It means the developers are sick of each other and sick of agile and sick of arguing, so everybody goes, "It's a 3 I guess. Whatever. Can we get out of this meeting now?"

Presto
Nov 22, 2002

Keep calm and Harry on.

Ithaqua posted:

You're going to be the person working on the thing in a few days; would you prefer that an arbitrary estimate was handed down by someone who had no clue?
What do you do when the developers' estimate is equally arbitrary and clueless?

Adbot
ADBOT LOVES YOU

Presto
Nov 22, 2002

Keep calm and Harry on.

Ithaqua posted:

If I give an estimate and it sucks, it's my own drat fault. As someone with my head in the codebase, when I give an estimate, I'm at least likely to be in the right ballpark, not wildly high or wildly low.
At my last job, the main product was a couple million lines of code. Even with my head in the code base if you asked me how hard it would be to fix problem X I probably would have no idea. Might be one line of code or I might have to add a thousand lines scattered over 50 files. And none of the other devs would have any realistic idea either.

This is probably where someone will say "then you need to hire more people and break the project into smaller chunks!" Yep, and I would like a Lamborghini too.

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