mr_square
Member
(04-02-2011, 11:05 PM)
#151

From a class I inherited from an ex-colleague:

Quote:
static int thingToMakeItDifferent = 77;
s.m_gear += thingToMakeItDifferent;
thingToMakeItDifferent += 12;
if( thingToMakeItDifferent > 9999 )
{
thingToMakeItDifferent = 31;
}
<_<
nickcv
Member
(04-02-2011, 11:57 PM)

nickcv's Avatar
#152

Originally Posted by Zoe:
Wait... how can you send code that belongs to your workplace?
not the whole thing, maybe just some snippets of some classes changing of course the part of code that totally relate to the project (for security sake and copyright issues).

plus often in the places where i worked we released part of the software (ie the scrapping engine) as open source.

Quote:

Does anyone else like JavaScript or am I the only one? >.> Seems most people here are systems, backend, or hardcore game engineers.
i do web application, but i mostly take care of back-end, webservices, streaming and scrapping.

i'm a senior, zend certified, php developer.
studying objective-c right now too.

i love js when it's well done, even if i don't get to use it too often (once one of my bosses made use js server-side... that was quite an experience, and let me tell you: it doesn't really make any sense to do something like that)


Quote:
From a class I inherited from an ex-colleague:

Quote:
static int thingToMakeItDifferent = 77;
s.m_gear += thingToMakeItDifferent;
thingToMakeItDifferent += 12;
if( thingToMakeItDifferent > 9999 )
{
thingToMakeItDifferent = 31;
}

<_<
ex colleague because some killed him after that?

Quote:

How do you guys plan before starting a new project (to an existing project or a completely new project, w/e)? Simple 5 minute pencil and paper design, or do you go as far as UML diagrams?

Also, this describes my programming career, and it's currently KILLING me: http://en.wikipedia.org/wiki/Analysis_paralysis
once we had a meeting about the too many meetings we were having! (thank gosh i left that place)

don't really like UMLs, i actually find them pretty useless... i prefer to plan the application while drawing the db er diagram.

while we do that we conceptually divide the application into it's layers (what has to be taken care from models, what from controllers and what from views) split the whole thing into smaller task, estimate times for each one of them and then each programmmer choose a task and complete it.

we also do daily meetings (about 10 minutes long) in which we recap how everything is going on.
Last edited by nickcv; 04-03-2011 at 12:11 AM.
Andrex
ὁ αἴσχιστος παῖς εἶ
(04-03-2011, 12:05 AM)

Andrex's Avatar
#153

Originally Posted by nickcv:
i do web application, but i mostly take care of back-end, webservices, streaming and scrapping.

i'm a senior, zend certified, php developer.
studying objective-c right now too.

i love js when it's well done, even if i don't get to use it too often (once one of my bosses made use js server-side... that was quite an experience, and let me tell you: it doesn't really make any sense to do something like that)
But node is awesome. :(
Zoe
(04-03-2011, 12:13 AM)

Zoe's Avatar
#154

Originally Posted by nickcv:
not the whole thing, maybe just some snippets of some classes changing of course the part of code that totally relate to the project (for security sake and copyright issues).

plus often in the places where i worked we released part of the software (ie the scrapping engine) as open source.
In my industry... I don't know if there's really anything that can be shared.
nickcv
Member
(04-03-2011, 12:18 AM)

nickcv's Avatar
#155

Originally Posted by Zoe:
In my industry... I don't know if there's really anything that can be shared.
what do you guys work on exactly? gaming?

Quote:
But node is awesome. :(
didn't know about node... i'll maybe give it a try but i still believe that forcing a client-side language to act server-side is mostly a time consuming and probably (almost certainly) worthless o.o

my 2 cents of course.
Last edited by nickcv; 04-03-2011 at 12:27 AM.
roxya
Member
(04-03-2011, 12:47 AM)

roxya's Avatar
#156

Originally Posted by BigNastyCurve:
Comments are for poor coders. Really REALLY good code is self-documenting. Small functions. Good function names.

edit: Which is not to say the code ronito was scanning was anything but garbage.
So you've never worked on a real world project?
Andrex
ὁ αἴσχιστος παῖς εἶ
(04-03-2011, 12:53 AM)

Andrex's Avatar
#157

Originally Posted by nickcv:
didn't know about node... i'll maybe give it a try but i still believe that forcing a client-side language to act server-side is mostly a time consuming and probably (almost certainly) worthless o.o

my 2 cents of course.
JavaScript, or rather ECMAScript is only bound to the client side because of the DOM... when you take the DOM away it can be used for anything. (Heck, Adobe uses it for ActionScript.)

JavaScript has been attempted on the server side a lot in the past but those attempts failed because they were trying to shoehorn existing conventions into the language... Node is brilliant because it's playing to JavaScript's strengths, that is, the brilliance of callbacks. And it uses this not to make a traditional server, but an entirely new kind of asynchronous server.

Jeeze this sounds like marketing speak... :P I haven't messed with Node a ton but I do know I agree with its philosophy.
Elfforkusu
Member
(04-03-2011, 01:25 AM)

Elfforkusu's Avatar
#158

Originally Posted by roxya:
So you've never worked on a real world project?
I have, and he's right. Good code doesn't require comments. Because good code has unit tests that both test and document the code!

Question about the horror stories of long hours, etc: is this purely game industry stuff you guys are talking about, or are there other industries under the umbrella of software development I should also avoid?

Comment about using javascript server side: Why would you do that? Why would anyone do that?
Zoe
(04-03-2011, 01:25 AM)

Zoe's Avatar
#159

Originally Posted by nickcv:
what do you guys work on exactly? gaming?
Very highly regulated gaming...
jvalioli
Member
(04-03-2011, 01:28 AM)

jvalioli's Avatar
#160

Originally Posted by Zoe:
In my industry... I don't know if there's really anything that can be shared.
I can't view code(snippets or otherwise) on anything that isn't a work computer.
cartoon_soldier
Member
(04-03-2011, 01:30 AM)
#161

Client: "I am not a technical person, but it sounds like this should be really simple change to make"

No ass hat, I will tell you where it's really simple to do or not.
Complex Shadow
Cudi Lame™
(04-03-2011, 01:30 AM)

Complex Shadow's Avatar
#162

Originally Posted by tafer:
He he he... newbies, real men program WITH THIS:

(First RPG example I found)
oh god not again, i won't go back, you can't make me. never again!
Half and half
Banned
(04-03-2011, 01:32 AM)

Half and half's Avatar
#163

Here's a C++ compiler issue I encountered recently.

I was trying to speed up a member function I had written. One of the issues turned out to be a simple assignment operation. Let's say the class name is Foo, and the variables are var1 and var2.

Quote:
void Foo::SomeFunction() {
// ... do a bunch of operations.
int result =somevar; // where somevar is the result of the local operations.

var1 = var2 = result; // slow code here
}
What the compiler decided to do was write the value of result to var2's memory location. Then it read var2 back into a register, and then wrote the value of that register into var1. So var1 had to wait for result to be written out to memory, read back in, and then written back out.

The device I'm on doesn't have store forwarding, so no short-cuts. Just a long stall waiting for memory to be written to and then read back in.

Changing it to:

Quote:
var1 = result;
var2 = result;
Fixed my problem.
Last edited by Half and half; 04-03-2011 at 01:36 AM.
Slavik81
Member
(04-03-2011, 01:47 AM)

Slavik81's Avatar
#164

You need comments for things like explaining some careful optimization that was made, or explaining the role of a certain class in your program. They can also be quite good for explaining an API. For example, all the Qt class references were generated from their comments. Example: QString.

Generally speaking, though, the need for a comment implies that something about your code is confusing or unclear. If you can instead make the code more sensible, do that instead. Only if clear code is not possible, leave a comment.
tafer
Member
(04-03-2011, 03:23 AM)

tafer's Avatar
#165

Originally Posted by nickcv:
here's an article about how to write unreadable code i found some time ago.
... long evil and delicious post.
Thanks for that!

Originally Posted by Slavik81:
You need comments for things like explaining some careful optimization that was made, or explaining the role of a certain class in your program. They can also be quite good for explaining an API. For example, all the Qt class references were generated from their comments. Example: QString.

Generally speaking, though, the need for a comment implies that something about your code is confusing or unclear. If you can instead make the code more sensible, do that instead. Only if clear code is not possible, leave a comment.
Originally Posted by Elfforkusu:
I have, and he's right. Good code doesn't require comments. Because good code has unit tests that both test and document the code!

Question about the horror stories of long hours, etc: is this purely game industry stuff you guys are talking about, or are there other industries under the umbrella of software development I should also avoid?
Any work place/industry with terrible project managers/retarded high level assholes will make the normal life of the programmers impossible.... in other words, pretty much everywhere.

And for the comments stuff:
- Not all programming languages out there are easy to read (Perl, old RPG for example), in-code documentation is mandatory!
- Well commented code will tell anyone what it is doing but never WHY!. (Complex/broken business logic requires comments)
- "Witty" solutions might be elegant and efficient, but they are usually confusing at first! (Comment and brag about it!)

Originally Posted by shadowcomplex:
oh god not again, i won't go back, you can't make me. never again!
MWAHAHAhaha... ha... h... ugh... damn it... :(





Funny link:
http://computersight.com/programming...ing-languages/



Specially funny (LOLCODE):
Code:
HAI
CAN HAS STDIO?
I HAS A VAR
GIMMEH VAR
IZ VAR BIGGER THAN 10?
YARLY
	BTW this is true
	VISIBLE "BIG NUMBER!"
NOWAI
	BTW this is false
	VISIBLE "LITTLE NUMBER!"
KTHX
KTHXBYE
Complex Shadow
Cudi Lame™
(04-03-2011, 03:29 AM)

Complex Shadow's Avatar
#166

Originally Posted by tafer:

And for the comments stuff:
- Not all programming languages out there are easy to read (Perl, old RPG for example), in-code documentation is mandatory!
- Well commented code will tell anyone what it is doing but never WHY!. (Complex/broken business logic requires comments)
- "Witty" solutions might be elegant and efficient, but they are usually confusing at first! (Comment and brag about it!)
so true. also rpg is not a language and i will refuse to use it on all fronts, i toke a class on it, it was hell. there were times where all the logic was there but it still wouldn't work.
tafer
Member
(04-03-2011, 03:52 AM)

tafer's Avatar
#167

Originally Posted by shadowcomplex:
so true. also rpg is not a language and i will refuse to use it on all fronts, i toke a class on it, it was hell. there were times where all the logic was there but it still wouldn't work.
Hehe, current RPG is ok... it tries so hard to be modern that it is kinda cute.
Turfster
Member
(04-03-2011, 05:07 AM)

Turfster's Avatar
#168

Code:
static int thingToMakeItDifferent = 77;
s.m_gear += thingToMakeItDifferent;
thingToMakeItDifferent += 12;
if( thingToMakeItDifferent > 9999 )
{
thingToMakeItDifferent = 31;
}
I'm... going to lay awake all night now, trying to figure out what the hell he was using that for. Thanks!

I always shudder in fear if I have to fix a bug in some of my old code, since most of it is... well... held together by magic. To be fair, this code was usually some kind of reverse engineered file format, so it's pure guesswork and "hey, this works. I dunno why, but I'll take it!" but yeah, a few months later on, I have no bloody idea what the hell it does or how it works and I spend a few hours (if I'm lucky) cursing myself.
butzopower
brain butz
(04-03-2011, 05:23 AM)

butzopower's Avatar
#169

Maybe this is more of a Software Development than a general programming question, but does anyone here do Test-Driven Development, and if so, whadda ya think of it?
Elfforkusu
Member
(04-03-2011, 05:29 AM)

Elfforkusu's Avatar
#170

Originally Posted by butzopower:
Maybe this is more of a Software Development than a general programming question, but does anyone here do Test-Driven Development, and if so, whadda ya think of it?
Yes. Mandatory at work.

It's a little tricky getting used to at first. "Writing tests sucks," you think to yourself. "How can I possibly test this?" you wonder. But once you're in the right mindset, it's actually very reassuring when you're done to know that the thing you wrote does exactly what you wanted it to do.

Also, usually the standards for unit tests are a little more lax, so you can indulge yourself in goofy class names/unnecessary overloads/etc that wouldn't fly in production code. Good times all around.
ronito
got my tag in the OT
(04-03-2011, 05:31 AM)

ronito's Avatar
#171

Depends on the project/program. I like it for smaller more restrictive projects but I find at times that really you can't account for every stupid thing a user might do so it's sorta like coding with blinders on. And that's sorta where TDD sorta falls apart when compared to XP and other methodologies.
Elfforkusu
Member
(04-03-2011, 05:35 AM)

Elfforkusu's Avatar
#172

Originally Posted by ronito:
Depends on the project/program. I like it for smaller more restrictive projects but I find at times that really you can't account for every stupid thing a user might do so it's sorta like coding with blinders on. And that's sorta where TDD sorta falls apart when compared to XP and other methodologies.
FWIW, our codebase is enormous and it works fine. That said, inheritance ends up being more or less verboten. On a large scale project, I'd argue that TDD implies delegation at every level.

e: Actually, I guess what we do is also similar to the XP concept as well... I'm not sure how these approaches are particularly different.
Last edited by Elfforkusu; 04-03-2011 at 05:39 AM.
Scrow
Banned
(04-03-2011, 05:37 AM)

Scrow's Avatar
#173

Originally Posted by Zoe:
Very highly regulated gaming...
slot machines/pokies?
Animal
Member
(04-03-2011, 05:54 AM)

Animal's Avatar
#174

Originally Posted by Scrow:
slot machines/pokies?
You'd be surprised how regulated Tetris games are.
butzopower
brain butz
(04-03-2011, 06:04 AM)

butzopower's Avatar
#175

Originally Posted by Elfforkusu:
FWIW, our codebase is enormous and it works fine. That said, inheritance ends up being more or less verboten. On a large scale project, I'd argue that TDD implies delegation at every level.

e: Actually, I guess what we do is also similar to the XP concept as well... I'm not sure how these approaches are particularly different.
Maybe I'm wrong, but I always thought XP was more a set of practices; TDD, Pair Programming, etc.

I've actually become accustomed to it and can't see myself doing task like projects any other way. It just makes sense from a focused/iterative approach. Glad to see others dig it.

Actually, I just moved to SF yesterday, and start a job in SOMA on Monday, any GAFers work down there?
Elfforkusu
Member
(04-03-2011, 06:05 AM)

Elfforkusu's Avatar
#176

Originally Posted by butzopower:
Maybe I'm wrong, but I always thought XP was more a set of practices; TDD, Pair Programming, etc.

I've actually become accustomed to it and can't see myself doing task like projects any other way. It just makes sense from a focused/iterative approach. Glad to see others dig it.

Actually, I just moved to SF yesterday, and start a job in SOMA on Monday, any GAFers work down there?
Yeah, looking at wikipedia it looks like a superset of a bunch of stuff. TDD included.
rodvik
Member
(04-03-2011, 06:49 AM)

rodvik's Avatar
#177

Originally Posted by Kalnos:
How do you guys plan before starting a new project (to an existing project or a completely new project, w/e)? Simple 5 minute pencil and paper design, or do you go as far as UML diagrams?

Also, this describes my programming career, and it's currently KILLING me: http://en.wikipedia.org/wiki/Analysis_paralysis
Whenever possible I like to hack together a prototype as fast as I can, even in a different language if thats quicker. Then write it again "for real" after the prototype is working.

I find this more useful than writing things down and trying to code it right first time. Its also quicker for me than UML or paper.

Exceptions are things which are math heavy for that I hit the paper.
subversus
I've done nothing with my life except eat and fap
(04-03-2011, 08:55 AM)

subversus's Avatar
#178

Originally Posted by rhfb:
Love javascript when it works (been doing a ton of stuff with javascript/jQuery/google maps lately), but since I'm currently using it in an asp.net project coding in vs2008 I hate when I've missed something very very simple and the compiler doesn't catch or complain about it :(
My teacher praised Ruby on Rails today. Is it really that good?
nickcv
Member
(04-03-2011, 09:19 AM)

nickcv's Avatar
#179

Originally Posted by subversus:
My teacher praised Ruby on Rails today. Is it really that good?

my project manager loved it, but i never got to use it so i cannot give you a real opinion about it.

the only thing i can tell you for sure is that if you want to use ror you better do it on your own server. few hosting companies support it (kinda like postgres).


Quote:

I can't view code(snippets or otherwise) on anything that isn't a work computer.
five out of six companies i've been working for didn't provide us with computer or gave us the choice to use our own machine or their (usually the one they provided was an utter piece of s**t)

i'm getting really tired about working in italy... we are not even recognized as a profession by the government, at the chamber of commerce we usually figure out as factory workers
Last edited by nickcv; 04-03-2011 at 11:57 AM.
butzopower
brain butz
(04-03-2011, 03:18 PM)

butzopower's Avatar
#180

Originally Posted by nickcv:
my project manager loved it, but i never got to use it so i cannot give you a real opinion about it.

the only thing i can tell you for sure is that if you want to use ror you better do it on your own server. few hosting companies support it (kinda like postgres).




five out of six companies i've been working for didn't provide us with computer or gave us the choice to use our own machine or their (usually the one they provided was an utter piece of s**t)

i'm getting really tired about working in italy... we are not even recognized as a profession by the government, at the chamber of commerce we usually figure out as factory workers
On mobile GAF and can't figure out how to only quote the first part, but heroku.com is THE place to host ruby on rails apps.
ephemeral garbage
Member
(04-03-2011, 03:56 PM)

ephemeral garbage's Avatar
#181

Originally Posted by butzopower:
On mobile GAF and can't figure out how to only quote the first part, but heroku.com is THE place to host ruby on rails apps.
Heroku is unreasonably awesome. Letting you start for free, and only pay when you need to scale, is a brilliant idea on their part.
Lathentar
Member
(04-03-2011, 04:03 PM)

Lathentar's Avatar
#182

Originally Posted by rodvik:
Whenever possible I like to hack together a prototype as fast as I can, even in a different language if thats quicker. Then write it again "for real" after the prototype is working.

I find this more useful than writing things down and trying to code it right first time. Its also quicker for me than UML or paper.

Exceptions are things which are math heavy for that I hit the paper.
That's basically what I do. Usually jot down on a paper the requirements of the system and get to coding a prototype. You will quickly see where things fall apart and need reworking. If you start to feel dirty doing something, look at where you went wrong and fix it.

This is an area where TDD excels as you write tests to ensure your requirements are met while designing how users will interact with your code. You'll want to make your tests simple as possible which leads to your design being simple and straightforward.
Drkirby
Corporate Apologist
(04-03-2011, 04:12 PM)

Drkirby's Avatar
#183

Originally Posted by Lord Cuze:
Here's a C++ compiler issue I encountered recently.

I was trying to speed up a member function I had written. One of the issues turned out to be a simple assignment operation. Let's say the class name is Foo, and the variables are var1 and var2.



What the compiler decided to do was write the value of result to var2's memory location. Then it read var2 back into a register, and then wrote the value of that register into var1. So var1 had to wait for result to be written out to memory, read back in, and then written back out.

The device I'm on doesn't have store forwarding, so no short-cuts. Just a long stall waiting for memory to be written to and then read back in.

Changing it to:



Fixed my problem.
Reminds me of one of the most annoying issues I had with some code.

atoi(OneCharacter) returned a 2 digit number. I had no clue why. I even dug down in debug and watch line the all the input going in, and it was a one character array with a proper null character. But it would return things like 89 instead of 8 and 71 instead of 7. And it kept doing it on the same line too. I eventually had to put in a line of 'if (number > 10) number %= 10;'which should of been totally unnecessary. I blame Dev C++ and being forced to use it in one class (Which I stopped due to the Debug features being useless, and just ran the code once in it to make sure it worked)
Wormdundee
Member
(04-03-2011, 05:06 PM)

Wormdundee's Avatar
#184

Wow, this many people work crazy overtime?

I've been at my current job for a little over 2 years and I have yet to work even an hour of overtime.

Anyway, the current task I'm on is horrible. We do ERP software and the new version is being moved over to GWT (the google web toolkit) which compiles Java into javascript. They changed how the event model works in GWT 1.7 so I've had to go through our hundreds of source files and change all the events to the new model.

We also have 50+ jobs outsourced in India so I'm sure I'll have lots of wtf code to share with you guys.
Half and half
Banned
(04-03-2011, 06:07 PM)

Half and half's Avatar
#185

Originally Posted by Drkirby:
Reminds me of one of the most annoying issues I had with some code.

atoi(OneCharacter) returned a 2 digit number. I had no clue why. I even dug down in debug and watch line the all the input going in, and it was a one character array with a proper null character. But it would return things like 89 instead of 8 and 71 instead of 7. And it kept doing it on the same line too. I eventually had to put in a line of 'if (number > 10) number %= 10;'which should of been totally unnecessary. I blame Dev C++ and being forced to use it in one class (Which I stopped due to the Debug features being useless, and just ran the code once in it to make sure it worked)
Yeah that does seem annoying. That's certainly worth reporting to the compiler guys if you can repro with a simple test case (which I'm guessing not though).

Was the input always one character (and positive)? If so, you could skip the atoi call and do something like:

Quote:
int finalNumber = oneCharacterArray[0] - '0';
heh, I just spent a few minutes trying various ways to reproduce your bug. No luck (Visual C++ 2005)
Dimmuxx
The Amiga Brotherhood
(04-03-2011, 09:41 PM)

Dimmuxx's Avatar
#186

This thread makes me really glad that I'm working on a pretty recently started project. It's LTE related and we use Scrum, TDD & Pair Programming in C++ & Java and almost no overtime so it "feels good man".
Elfforkusu
Member
(04-03-2011, 10:21 PM)

Elfforkusu's Avatar
#187

Originally Posted by Drkirby:
Reminds me of one of the most annoying issues I had with some code.

atoi(OneCharacter) returned a 2 digit number. I had no clue why. I even dug down in debug and watch line the all the input going in, and it was a one character array with a proper null character. But it would return things like 89 instead of 8 and 71 instead of 7. And it kept doing it on the same line too. I eventually had to put in a line of 'if (number > 10) number %= 10;'which should of been totally unnecessary. I blame Dev C++ and being forced to use it in one class (Which I stopped due to the Debug features being useless, and just ran the code once in it to make sure it worked)
atoi takes a char*, did you give it the right thing?

If it's not wetware, Dev C++ still wouldn't be the problem. It'd be your version of mingw32 or whatever compiler ships with it.

FWIW, I always liked Dev C++, and used it when I was a student. But the Visual Studio debugger is the best thing ever.
Haly
One day I realized that sadness is just another word for not enough coffee.
(04-04-2011, 12:55 PM)

Haly's Avatar
#188

Project due in 15 hours. Sleep? Who needs it?

I could've taken the easy way out with some simple two player thing but nooooo, I wanted to make a Blackjack table that supports up to seven players (and I chose seven only because of layout issues and because I like the number seven).

And these stupid SmartFox docs aren't getting me anywhere.
PhatSaqs
(04-04-2011, 01:05 PM)

PhatSaqs's Avatar
#189

Originally Posted by BigNastyCurve:
Comments are for poor coders. Really REALLY good code is self-documenting. Small functions. Good function names.
This is BS. I say code & comment as if the next dude to maintain the code is a Jr dev coming straight out of college no matter how "clean" you think your code is. Meaningful var/method/class names should be a given but comments should be there for complex (highly subjective which is why commenting is such a fine art IMO) operations.
Fafalada
Fafracer forever
(04-04-2011, 01:25 PM)
#190

Originally Posted by BigNastyCurve:
Comments are for poor coders. Really REALLY good code is self-documenting. Small functions. Good function names.
Try reading optimized code few months after the fact and then talk about it being self-documenting. Especially when it uses non-native language constructs or data-types.


Anyway speaking of comments, and good naming conventions - back when I was young and thought myself much smarter, I used to name all my work-in progress test-code along the lines of "popo" (or some variation of thereof, being easy to type and all).
This worked fine until one day I wanted to look at some stuff I wrote months ago and my source code folder looked like this:

popo.pas
opop.pas
popo1.pas
popo3.pas
popopop.pas
poponew.pas
popoold.pas
popop.pas
...
iapetus
Scary Euro Man
(04-04-2011, 01:40 PM)

iapetus's Avatar
#191

Originally Posted by BigNastyCurve:
Comments are for poor coders. Really REALLY good code is self-documenting. Small functions. Good function names.
Bullshit.

The only thing that code can self-document is what it's doing. In the real world, sometimes why it's doing it needs explaining as well. In addition, well-commented code can make it easier and quicker to see what it's doing.
Haly
One day I realized that sadness is just another word for not enough coffee.
(04-04-2011, 01:45 PM)

Haly's Avatar
#192

I like variable names to be as short as possible. But I also like variable names to be descriptive and unique. Sometimes I'd start with something simple like an int width, and then I realize I need to keep track of two widths. I change them to boxWidth or mbWidth. Afterwards I realize I need to name some parameters and local variables so I use newWidth, currentWidth, oldWidth, etc etc.

Eventually this starts getting out of hand and I kind of give up on trying to keep everything nice and neat.
The Technomancer
card-carrying scientician
(04-04-2011, 01:53 PM)

The Technomancer's Avatar
#193

Alright GAF, I'm mostly through my first C++ class now, and even though its not in my major, I really enjoy programming so its something I'll be doing more of. Give me some tips to not turn into the kind of programmer you hate?
Half and half
Banned
(04-04-2011, 01:58 PM)

Half and half's Avatar
#194

I agree that some optimized code (for speed or memory) needs comment.

Sometimes people need to lay out their data in peculiar ways to improve memory access. Comments are useful to tell other codes why they're doing it that way and don't try to change it for readability.

I try to write self-documenting code, but sometimes I'll add a comment just because it's easier on my eyes. It's down to personal preference at that point.
Fafalada
Fafracer forever
(04-04-2011, 02:14 PM)
#195

Originally Posted by iapetus:
In the real world, sometimes why it's doing it needs explaining as well.
This too. No matter how great the code it can't be self-explanatory to every possible dependency, especially the non-code ones.

Speaking of which - anyone ever tried programming drunk? :) I've had a case or two of great epiphanies realizing how "unnecessary" some code I wrote sober was and happily proceeded to delete it (making the next morning hangover all the more unpleasant).
volmer
Member
(04-04-2011, 02:25 PM)

volmer's Avatar
#196

Good programmer ethics 101:

- Adhere to existing code conventions when you edit other people's work.
- Seriously. Adhere to existing code conventions when you edit other people's work!
nickcv
Member
(04-04-2011, 06:42 PM)

nickcv's Avatar
#197

tomorrow i'll be interviewing a couple of people to fill a programmer position in my company.

Do you guys know any tricky question i could ask? (besides the fizzbuzz test i mean)
an evil suggestion is much appreciated :P
Wormdundee
Member
(04-04-2011, 09:04 PM)

Wormdundee's Avatar
#198

Here's something I'm looking at right now.

Code:
         final SwtSimpleBindableWidget widget = (SwtSimpleBindableWidget)evt.getSource();
         final Binding binding = reverseBindings.get(widget);
         final BindableDataProvider dataProvider = binding.getDataProvider();
         final Object source = evt.getSource();

         // Avoid endless loop where a datasource changes and then the 
         // widget notifies the datasource it has changed endlessly
         if (source != null)
         {
            final Object sourceOfEvent = source;
            if (sourceOfEvent.equals(dataProvider))
            {
               // the dataProvider to be notified initiated the change
               // so consume this event 

               return;
            }
         }
I have no clue how
Code:
sourceOfEvent.equals(dataProvider)
will ever return true. You can see that it casts the source to SwtSimpleBindableWidget and it would crash there if that weren't possible. SwtSimpleBindableWidget and BindableDataProvider are both interfaces and are not at all similar.

The thing is, this must have worked at some point because we're not getting infinite loops.

You can also have fun wondering why they made a new Object sourceOfEvent when they already had source right there.
BomberMouse
Member
(04-05-2011, 03:06 AM)

BomberMouse's Avatar
#199

Originally Posted by subversus:
My teacher praised Ruby on Rails today. Is it really that good?
Ruby is really good, RoR adds some nices helpers and conventions. I'll never make another web app in anything that is not RoR, Sinatra, etc.

Originally Posted by BigNastyCurve:
Comments are for poor coders. Really REALLY good code is self-documenting. Small functions. Good function names.

edit: Which is not to say the code ronito was scanning was anything but garbage.
This is partially true, doctesting is awesome though. IMO comments inside a definitions are a bad practice, comments in the method and class definitions are OK.

Originally Posted by Andrex:
So what's everyone working on? At work (if you're allowed to talk about it) or on your own time?
At work:
- Boring data processing with hadoop, hive, solr, etc.
- Some cloud based pdf digital signing stuff

While not really fun, it's way better than just doing a boring WS on PHP or coding something in C++. On my free time I like to do some more interesting stuff, like:

- Finishing an indoor positioning system for a M.Sc program
- Trying to finish a game in pyglet
- Toying with Android and some Lego NXT to make a nemesis for my cat


And now my pesonal rant, a long, long time ago I was a JavaME programmer. Sometimes instead of developing our own games we had to reskin some indian developped games to the local market (I'm not indian so the comments meant nothing and the code was a nightmare) and we even had to port that code to the unsupported handsets. It was hell.
Last edited by BomberMouse; 04-05-2011 at 04:44 AM.
jim-jam bongs
Banned
(04-05-2011, 03:38 AM)

jim-jam bongs's Avatar
#200

Originally Posted by nickcv:
tomorrow i'll be interviewing a couple of people to fill a programmer position in my company.

Do you guys know any tricky question i could ask? (besides the fizzbuzz test i mean)
an evil suggestion is much appreciated :P
I wrote the test for the last couple of shops I've worked in. My favourite question in the current one is a block of code which defines an abstract parent and a child, then a method call which would trigger a fatal exception due to an access violation. Currently out of the 200+ people who have done the test only two have correctly said "that will cause a fatal exception". I don't know if it's because they all assume that couldn't possibly be the answer or if they just don't see the bug.

Recursion and iteration are always good ones to test whether people have a lizard-brain or not, you would be surprised how many coders struggle with them. For recursion I have a method which divides, floors then adds to an integer until the integer is > 10 by calling itself, and the question is "if you pass a value of 4 what will be the return value?"

Also, depending on whether you use them a lot in your industry, regular-expression tests can be great for sorting the wheat from the chaff. It doesn't have to be anything too complex, but something like will testing the pattern "/^[0-9a-z]+$/" against the string "l33tsp3@k" return true or false?