• Hey Guest. Check out your NeoGAF Wrapped 2025 results here!

GAF Devs Thread - a thread about programmer's rants

Status
Not open for further replies.
It is just for a Computer Science class, but when I have to read in lines such as "10:40 PM E DAVE 4" from a text file, and turn the fields into meaningful data what would you use instead? Mind you, I have to do it in C, and can only use standard C Libraries.

Also, while the passed in time will get modified, the value is only used the one time to be passed into the function. I don't need the string version of it after.
 
Drkirby said:
It is just for a Computer Science class, but when I have to read in lines such as "10:40 PM E DAVE 4" from a text file, and turn the fields into meaningful data what would you use instead? Mind you, I have to do it in C.

Also, while the passed in time will get modified, the value is only used the one time to be passed into the function. I don't need the string version of it after.

1) Always work on (local) temporary buffers (try to keep them as close to the size as needed). This has the added bonus of allowing you to allocate enough space for a null terminator.

2) Handle finding delimiters yourself.

3) It's a good idea to have the size of the character array as a parameter. This allows for much safer code.

4) Do extensive error checking. It's not going to penalize you that much, and it's less likely to overwrite memory it shouldn't.

These are fairly general, but parsing text should never imply that you need strtok. I use my own C functions for finding patterns and delimiters in a string.
 
Ah, gotcha. I would probably use sscanf:

Code:
int ConvertTime(char *Time, char *Midday)
{
[B]  //Converts a field in the format of ##:## PM into the time in minutes
  int hours, minutes;
  if (2 != sscanf(Time, "%d:%d", &hours, &minutes)) {
    // error condition: return 0 or something
  }
  
  if(hours == 12) hours = 0;
  int time = (hours * 60) + minutes;
[/B]
  if (strcmp("PM",Midday) == 0) time += 720;
  return time;
}

sscanf is nondestructive, threadsafe, etc. But it's not exactly the same interface as strtok() so you can't always use it as a perfect replacement. It's good to be aware of alternatives.

In a real-world situation, you should probably use a regular expression library, or honestly if you're going to be doing text processing, do it in a language with good regular expression support like Perl, Python, or Ruby. But sscanf should work in this situation.
 
Alright. Just a note, you forgot in C that all variables have to be declared at the very start of a function. So saying "int Time" mid function is illegal syntax.
 
Drkirby said:
I tend to do the following on such thing
Code:
if (someCondition) doSomething();

I *intensely* dislike that form because you cannot easily stick a breakpoint on the case where someCondition is true in the debugger.

It'd be against the coding standards in most places I've worked.
 
Drkirby said:
Alright. Just a note, you forgot in C that all variables have to be declared at the very start of a function. So saying "int Time" mid function is illegal syntax.

That has more to do with the compiler.
 
My main problem with programming isn't the actual programming. It's the poor planning and how the credit is accorded. My project manager gets all the credit and is a piss poor project manager, and I really can't say anything because it will look petty. But constantly my coworkers and I will stay late because he hasn't actually planned anything.

The kicker is now he's trying to understand our system and he gets it completely wrong, but will NOT trust my judgment unless we check with the Director of Technology (my boss). It's so aggravating that I'm going to talk with my boss tomorrow and see if there's anything he can do.
 
TheBranca18 said:
My main problem with programming isn't the actual programming. It's the poor planning and how the credit is accorded. My project manager gets all the credit and is a piss poor project manager, and I really can't say anything because it will look petty. But constantly my coworkers and I will stay late because he hasn't actually planned anything.

The kicker is now he's trying to understand our system and he gets it completely wrong, but will NOT trust my judgment unless we check with the Director of Technology (my boss). It's so aggravating that I'm going to talk with my boss tomorrow and see if there's anything he can do.

I worked with a programmer who actively tried to get me to copy code (in this case, it was JavaScript for a simple image switcher). I confronted him, and my then-boss, who was my brother, actually told me to back off. I realize it's not the same thing, but when even you're brother makes an appeal to authority, it's a real kick in the balls.

So I feel your pain when it comes to just being trusted to get the job done :\
 
Wormdundee said:
More rantish stuff. Why the hell do people return out of void functions?!? It doesn't make any sense. In general I don't like a return statement anywhere except at the end of the function. Each return statement makes it more difficult to read and understand what the actual result is going to be and I hate it. Haaaaate it. It's especially nonsensical in void functions though.

Basically what's happening in many places in our code is people doing if checks on some sort of flag and then returning early out of the function if the flag is 'wrong'. What I prefer is a check to see if the flag is 'right'.

....

This way you can naturally see what's driving the flow and it's much easier to tell when something actually executes, especially when you get multiple flag checks. And there are no stupid return statements.
Deep nesting gets very difficult to read, as any else statements that exist become very separated from the if statements they correspond to. Even if there aren't any else statements, you need to look around to determine that.

Returning out of the function means that all jumps within the function are short distances.
 
TheExodu5 said:
Gotcha.

I need to mess around with C++ a bit to get the hang of it. I was never a fan of pointers when I used C in microcontroller programming.

Is there a half decent IDE out there that might be comparable to Eclipse? The one we used didn't even have real-time syntax checking. We would compile code for 5 minutes to put onto the microcontroller, only to find out we made a syntax error somewhere. Drove me insane.

I really like CodeBlocks
http://www.codeblocks.org/

Its not fancy but its cross-platform and open source which matters to me.
 
TheBranca18 said:
My main problem with programming isn't the actual programming. It's the poor planning and how the credit is accorded. My project manager gets all the credit and is a piss poor project manager, and I really can't say anything because it will look petty. But constantly my coworkers and I will stay late because he hasn't actually planned anything.

The kicker is now he's trying to understand our system and he gets it completely wrong, but will NOT trust my judgment unless we check with the Director of Technology (my boss). It's so aggravating that I'm going to talk with my boss tomorrow and see if there's anything he can do.
The problem is that a lot of companies think "Good developer==Good project manager" or "Good Project Manager == Good programming manager."

Both are disastrous. It takes a different kind of person to be able to run a technical track. Get someone who's too technical and egotistic and they'll micromanage and second guess their employees until their employees can't be efficient. Further they might be able to set good technical direction but they might be indecisive, or play favorites, or have gold fish memory.

Get someone that's not technical enough and the developers wont respect them. They'll set bad technical direction. Worst case they might be decisive but will make decisions completely divorced from reality thereby demoralizing their developers until they leave in frustration or have to keep checking for permission with the boss until they're no longer effective.

For me I find that having a project manager that's functional and an architect that's technical and having them be separate but equal tends to be ideal so long as the arch and PM mesh well. This is by far the way I prefer to run things. The architect keeps the PM rooted in reality and sets the technical direction and takes care of things that are too technical for PMs while the PM deals with the meetings and business/people decisions that the architect doesn't really care about/doesn't have the acumen to deal with. If I can't get that then great care must be taken as to who will lead because, frankly, most companies get it wrong.

Even then people forget that programming is a different beast. It's like building a skyscraper and having the location of the rooms change every couple of days. Home builders wouldn't stand for it, engineers would never think of it. But we do just that in programming as a matter of course. Further people forget the truth that in programming at your worst you can do a lot of damage, but even the best programmer cannot guarantee success.
 
ronito said:
The problem is that a lot of companies think "Good developer==Good project manager" or "Good Project Manager == Good programming manager."

This is so very true, and it is indeed disastrous.

And it's not only companies, is developers themselves sometimes. Many of my coworkers see it as the only logical career path, but being a manager is not necessary the top of the field, and it is a terrible decision to follow that career when your simply don't have the ability to do so, you end up with teams full of frustration and never finishing on time.
 
GOD I HATE VISUAL STUDIO 2010

It's so slow and laggy and buggy adds nothing of value and WPF is the worst rendering engine ever and MSI setup projects are garbage and broken and ARGH

edit: At least it's not Eclipse :D
 
I'd just like to post that I'm I'm pretty happy right now.

I'm making significant progress on a game I've been working on, and I'm having a blast doing it.
 
Still in the beginning of self-learning some stuff, but I'm doing some weird computing course right now and I managed to get the booklet of a sister (programming centered) course. It had a lesson dedicated to something they call a world-recognized system for code (like, guidelines and stuff).

I'm having doubts something like that exists, but the guidelines themselves are pretty nice.
Like putting variables directly one under another if you're breaking a line into two lines, always putting spaces between operators, I wouldn't think about doing those but it makes things look so much damn better. Quick example of what I'm talking about (not necessarily the best presentation, just a demo)

Code:
int  nNum //note the spaces
char cChar

if ((dFactor*((nNum1 + nNum2 + nNum3 + nNum4) /
               SUM_NUMBERS) > dLimit) ||
    (IsFunc(bIsThisLongEnough, bIsEnough, nNum)))
{
    ...
}

Dunno if this is common sense or something, but it's the first I've seen a straight coherent list full of guidelines. They also had a huge code for example and it looked amazing and different from the mess I had up until then.
 
upandaway said:
Still in the beginning of self-learning some stuff, but I'm doing some weird computing course right now and I managed to get the booklet of a sister (programming centered) course. It had a lesson dedicated to something they call a world-recognized system for code (like, guidelines and stuff).

I'm having doubts something like that exists, but the guidelines themselves are pretty nice.
Like putting variables directly one under another if you're breaking a line into two lines, always putting spaces between operators, I wouldn't think about doing those but it makes things look so much damn better. Quick example of what I'm talking about (not necessarily the best presentation, just a demo)

Code:
int  nNum //note the spaces
char cChar

if ((dFactor*((nNum1 + nNum2 + nNum3 + nNum4) /
               SUM_NUMBERS) > dLimit) ||
    (IsFunc(bIsThisLongEnough, bIsEnough, nNum)))
{
    ...
}

Dunno if this is common sense or something, but it's the first I've seen a straight coherent list full of guidelines. They also had a huge code for example and it looked amazing and different from the mess I had up until then.
This is known as best practices and naming conventions. There's no "right way", though some things are pretty well agreed upon as far as style goes. My company, and I imagine many others, have a loosely enforced coding style, which makes it much easier for any developer to drop into an area and be able to read it easily.
 
Wormdundee said:
More rantish stuff. Why the hell do people return out of void functions?!? It doesn't make any sense. In general I don't like a return statement anywhere except at the end of the function. Each return statement makes it more difficult to read and understand what the actual result is going to be and I hate it. Haaaaate it. It's especially nonsensical in void functions though.

Basically what's happening in many places in our code is people doing if checks on some sort of flag and then returning early out of the function if the flag is 'wrong'. What I prefer is a check to see if the flag is 'right'.

So instead of

Code:
public void someFunction()
{
   if(!thingIsEnabled)
      return;

   doSomeStuff;
}

I prefer to have it this way

Code:
public void someFunction()
{
   if(thingIsEnabled)
   {
      doSomeStuff;
   }
}

This way you can naturally see what's driving the flow and it's much easier to tell when something actually executes, especially when you get multiple flag checks. And there are no stupid return statements.

That's fine when you're only validating one or two things. It gets a little hairier when you have multiple validations to do, and all of them require you to bail out of the function. Your method would end up with something like:
Code:
void doSomething(OBJECT *obj)
{
    if(obj != NULL)
    {
        if(obj->someAttribute & SOME_FLAG)
        {
            if(obj->refCount > 5)
            {
                if(someGlobalBoolean)
                {
                    obj->timer++;
                }
            }
        }
    }
}

Compare that to:

Code:
void doSomething(OBJECT *obj)
{
    if(obj == NULL) return;
    if(!(obj->someAttribute & SOME_FLAG)) return;
    if(obj->refCount <= 5) return;
    if(!someGlobalBoolean) return;

    obj->timer++;
}

There are multiple advantages to this method:

- Adding additional validators is easy and doesn't require moving the meat of the function even further to the right.
- It's a lot simpler if you need to reorder the validators so that the O(1) tests can run before the O(n) tests
- the meat of the function is kept close to the left margin which makes it easier to find.
 
Megadrive said:
Only thing in all of that is that I would've used iNum instead of nNum.

I wouldn't even do that. The name of the variable should describe what it is. I don't like variables having the letter in front of them. That might just be me though.
 
I love working at my current job. Perl + vim + Linux environment = happy me

Had never used Perl before starting here but I actually really like it. Started using vi at the same time, and let me tell you it's nice being able to use the same editor on client/server alike.
 
thcsquad said:
I love working at my current job. Perl + vim + Linux environment = happy me

Had never used Perl before starting here but I actually really like it. Started using vi at the same time, and let me tell you it's nice being able to use the same editor on client/server alike.

Wow, what kind of work still uses Perl?
 
gblues said:
Code:
void doSomething(OBJECT *obj)
{
    if(obj == NULL) return;
    if(!(obj->someAttribute & SOME_FLAG)) return;
    if(obj->refCount <= 5) return;
    if(!someGlobalBoolean) return;

    obj->timer++;
}
Is there any reason you don't combine those in a single "if" statement with "||"?
 
thcsquad said:
I love working at my current job. Perl + vim + Linux environment = happy me

Had never used Perl before starting here but I actually really like it. Started using vi at the same time, and let me tell you it's nice being able to use the same editor on client/server alike.

Client/server? What exactly are you editing on the server? My work has virtual servers for development and production for ease of creating new ones on the fly, which means finally after five years of working here that we have the same environment dev and live. So don't have to do any of that server editing. I guess if you're a system admin it's a different story...

Also thank god we switched to git from perforce, having the version control system make files not writeable until you check them out was torturous.
 
TheBranca18 said:
Also thank god we switched to git from perforce, having the version control system make files not writeable until you check them out was torturous.

Wait, what?
 
TheBranca18 said:
Client/server? What exactly are you editing on the server? My work has virtual servers for development and production for ease of creating new ones on the fly, which means finally after five years of working here that we have the same environment dev and live. So don't have to do any of that server editing. I guess if you're a system admin it's a different story...

Also thank god we switched to git from perforce, having the version control system make files not writeable until you check them out was torturous.

We're a startup with a handful of engineers, so we do our own sysadmining, which accounts for most of the server vi usage. Obviously we're not doing regular programming on the server, there's deploy scripts for that.

We have one internal server that doesn't do anything in production, so most things on it happen through live editing. One engineer actually does all of his work ssh-ed into that box.

As for the language choice, I guess the first technical guy at the company (long gone) chose it. If you had told me a year ago that I'd be primarily working in Perl I would have vomited, but after using it I'm very glad to not be at a .NET house like my last job.
 
Halycon said:
Is there any reason you don't combine those in a single "if" statement with "||"?

For me it depends on the conditions and how many there are. 4 is pretty save that I do the if (blah) return; blocks instead of ||s.
 
ronito said:
perl is awesome for parsing files and feeling like a hipster dev

wow really? I work with C#, and I'm doing a parser and it hasn't been easy. It has been fun but all the time when I see all those nested ifs I feel I'm not doing it right.

And now I look at the wikipedia article and I see I know nothing about this. I should've start there! the parser is finished anyway, but it sucks to look back and to know you could have done it better.
 
ronito said:
perl is awesome for parsing files and feeling like a hipster dev


And then you look at what you did 3 months later, and your mind is blown, because it looks like jibberish.

That is, if you use Perl as infrequently as I do.
 
Hopefully someone remembers this.

I remember reading a bunch of stories from. Game dev who worked at a company where the owner was a complete imbecile. He'd say non sensical stuff and back it up with "Who's the millionaire, me or you?" I think the dev called this guy "the creature".

Not sure how true it all was, but it made very entertaining reading! Anyone know what I'm thinking of?
 
TheBranca18 said:
Also thank god we switched to git from perforce, having the version control system make files not writeable until you check them out was torturous.

We're using Perforce right now in my course and last night a guy checked out the entire server (don't ask me why) and then just left it checked out. So people were locked out of their binary files (models). It wasn't too bad for us programmers but our UML diagrams in dia and our documentation (doc file) were unusable and unupdateable until an admin got around to fixing it (3pm). We didn't have access from 9am till 3pm. Horrible.

I hate Perforce. Give me bloody SVN over Perforce.
 
Question (Game/Physics) Dev GAF!

Has anyone used the Separating Axis Theorem to handle polygon collisions on their code? I finally came to understand how it works but I'm having trouble knowing how to calculate a position correction based on the minimum translation vector obtained.

Aside from that not ranting much as my main rants with my current job are basically reflected in the OP and I just got a new job anyway :D better salary and from the looks of it better management
 
Working at a savings bank doing at first C/C++ both in UNIX and Windows, but nowadays I've gone 100% Java. Thankfully didn't start with COBOL (ew).

I once got asked if I could take care of a bug in some Java code. They gave me the compiled JARs and I asked for the source:

"we have no source, the main dev lost the code some years ago and each time someone needs to change something, they decompile it, then copy the compiled changes again. Which is a problem cause this code is quite used and regularly changed by different staff. We are not even sure whether there is someone around making conflictive changes in their workstations".

O_O

I went ballistic and made him do some phone calls to get the people making changes send me all the known jar versions and on-going changes, checked all of them and checked it in our svn server. Then talked to management, sent an e-mail telling them no further changes there were approved unless they used svn. Then went out for a cigarette.

The damn decompiler was already choking on exceptions from Java 1.4 binaries!

Also, we needed a new web service client for UNIX written in C, a task I'd already gone thru. Since we were quite busy we got a consulting firm to get us an expert. Turns out their chosen "expert" had no experience with UNIX or C and I had to answer tons of questions thru e-mail for months on end. 90% of them were solved by pointing him to a section in the library manual. The other 10% was pointing out obvious flaws in his pointer logic.

Nowadays they got a trainee to take care of my old tasks since I'm working on a huge new project. One manager asked us to give him some time estimation for a change. Told the trainee to look at the stuff (which I had already taught him) and answer with his estimation. One week later we get an e-mail asking for the estimation again, then the trainee fricking asks me to send the estimation. After a few words with him he answered "a month", which is the minimum I told her it would take. *sigh*.
 
Halycon said:
Is there any reason you don't combine those in a single "if" statement with "||"?

Long chains like that are a pain in the ass to debug. I tend not to use them except when I need to do a test conditionally, i.e.

Code:
if( obj->player != NULL && obj->player->flag & SOME_FLAG ) return;

If something goes wrong in your long chain, you end up having to unroll it anyway to determine which one is going wrong. KISS.
 
The rule for anything is readability. If it makes logical sense and is more readable to have a few conditional statements together, go for it.

upandaway said:
Still in the beginning of self-learning some stuff, but I'm doing some weird computing course right now and I managed to get the booklet of a sister (programming centered) course. It had a lesson dedicated to something they call a world-recognized system for code (like, guidelines and stuff).

I'm having doubts something like that exists, but the guidelines themselves are pretty nice.
Like putting variables directly one under another if you're breaking a line into two lines, always putting spaces between operators, I wouldn't think about doing those but it makes things look so much damn better. Quick example of what I'm talking about (not necessarily the best presentation, just a demo)

Code:
int  nNum //note the spaces
char cChar

if ((dFactor*((nNum1 + nNum2 + nNum3 + nNum4) /
               SUM_NUMBERS) > dLimit) ||
    (IsFunc(bIsThisLongEnough, bIsEnough, nNum)))
{
    ...
}

Dunno if this is common sense or something, but it's the first I've seen a straight coherent list full of guidelines. They also had a huge code for example and it looked amazing and different from the mess I had up until then.

See for an if statement like that, I find I need to take the first half of it and assign it to a variable with a descriptive name for it to make more sense.

like

Code:
dResult = dFactor*((nNum1 + nNum2 + nNum3 + nNum4) / SUM_NUMBERS)

if(dResult > dLimit) 
...

I hate when an if statement can't be read in one simple line.
 
So should I be worried that I'm going into my senior year and I've not programmed C++ (just one class in C) and I'm not sure I would be able to code many of these problems on the spot?
 
Genesis Knight said:
So should I be worried that I'm going into my senior year and I've not programmed C++ (just one class in C) and I'm not sure I would be able to code many of these problems on the spot?

Can you program in Java or C#?

My biggest problem with the program at my school is you can go through most of the requirements without ever programming anything. It's supposed to be beneficial in that it's theoretical so that you can adapt to anything, but it doesn't do a thing to prepare you for the real world.

If your school offers short electives in specific languages, you should take the opportunity now before you're out.
 
Zoe said:
Can you program in Java or C#? If your school offers short electives in specific languages, you should take the opportunity now before you're out.

I've taken a lot of classes with Java and I do some C# coding at my internship. My university doesn't even have a dedicated C/C++ class that I'm aware of.
 
I have been screwing around with Python to write some simple file parsers for work. A really easy language, didn't even need to read a book on it, just a little googling. Very useful, I wish I would have learned it earlier. I used to use Matlab for this kind of stuff, but it is nice not being tied down to licenses and crap, I can install Python on everything.
 
Mister Zimbu said:
GOD I HATE VISUAL STUDIO 2010

It's so slow and laggy and buggy adds nothing of value and WPF is the worst rendering engine ever and MSI setup projects are garbage and broken and ARGH

edit: At least it's not Eclipse :D

VS 2010 is pretty clunky but coming from VS6 to this is still much better....and I really enjoy WPF. What specifically don't you like about it?
 
ronito said:
The problem is that a lot of companies think "Good developer==Good project manager"

I've seen this firsthand. The person had pretty much 0 people skills and made my life a living hell.
 
Status
Not open for further replies.
Top Bottom