Crappy Programming Examples

I have been looking at an NVidia demo for a while: http://developer.nvidia.com/view.asp?IO=Bump_Mapping

I found a few funny things.

  1. This function (not written by NVidia) is in tga.c.

int
gliVerbose(int newVerbose)
{
int oldVerbose = verbose;
verbose = newVerbose;
return verbose;
}

I think the above function is a little…
verbose.

2.) The demo is 3000 lines in one file. It’s 38 pages when printed out. So you can imagine that it takes some time to piece everything together. My advice is to delete the 7 functions that are never used: doughnut, add_matrices, drawTorusAsPoints, drawTorusAsQuads, FreeTorus, invertMatrix, and transposeMatrix.

3.) You can also delete:
GLUquadricObj *quadObj;
quadObj = gluNewQuadric();
gluQuadricTexture(quadObj, GL_TRUE);

'coz quadObj is never used.

4.) You will probably want to clean up the main function and divide all the other functions into about 3 files.

Other than that, this was a wonderful demo that really showed me how to become a better programmer. It reminds me of my wonderful blind, one-legged ski instructor.

[This message has been edited by lucidmm (edited 11-24-2002).]

So how much did you pay for this demo?

There’s gratitude for you…

Have you ever complained about a stupid commercial, a bad song on the radio, or a horrible TV show?

One could say that since DX7 we only paid for demos

Originally posted by lucidmm:
Have you ever complained about a stupid commercial, a bad song on the radio, or a horrible TV show?

Yes, because someone will be making money out of those things - but that isn’t true here, so silence your protestations.

NVidia is a non-profit corporation?

No, that’s not the point. NVidias demos are part of their developer relations, not a direct play for money. Most of the knowledge imparted by their demos and documents can be applied to most cards, nvidia or non-nvidia.
You have no right to complain, but suggestions are fine.
I’m not one to defend big corporations like nvidia, but your criticisms seem a little churlish.
Complain about such things as nvidia-specific extensions instead of supporting cross-vendor standards, by all means.

But dont developer relations employees get paid? So technically, they get paid to produce such work.

And where do they get the money? From ppl buying their graphics cards.

Any why do ppl buy their graphics cards? Cos developers used their features.

And why did developers use their features? Cos the developer relations ppl showed them how.

So basically if the dev rel. ppl make the demos nice and easy and clean, then developers will learn, and use their features which in turn makes the public buy nvidia graphics cards, which in turn pays the dev rel ppl

Nutty

Just to clarify - you’d be right to complain if NVIDIA didn’t support a cross-vendor exension while supporting its own vendor-specific version.

NVIDIA will expose all our hardare’s capabilities through extensions. We favor cross-vendor extensions where available, but we use vendor-specific extensions as necessary.

Vendor-specific extensions are not a bad thing. They are how we prove the usefulness of extending OpenGL in a specific away.

NV_vertex_program begat ARB_vertex_program which begat ARB_fragment_program. That’s a Good Thing.

Thanks -
Cass

PS Edited stupid spelling error.

[This message has been edited by cass (edited 11-24-2002).]

I’d hope that nVIDIA’s job is to teach you how to use their hardware, assuming you’re already a good programmer. It’s some college or professional school’s job to make you a good programmer. Well, that, plus a year of actually doing it with people who have done it before :slight_smile:

When I go through a demo or try to dive into any code, I use Find/FindInFiles a lot, and I usually start at main() and trace through the program to figure out what it’s doing. That means I only get to read the parts I care about, and it doesn’t really matter if the program puts each function in its own file (horror!) or puts all functions in one file (horror!).

Their examples are long and complex looking, but a good number of them (all) are easy to understand.

Do you know what the trick is? Dont look at the irrelevent parts of the code. Who cares what’s in the tga or png loading file. Who cares how they are loading their models. Who cares how they loading extensions.

All those programs have a main, diplay, init, mousemove, mouseclick, keyboard, … functions

init, display, keyboard are the core of those demoes. So use your Find function often.

PS: thanks to the software rasterizer, you wont be forced to upgrade if you’re short on money and are dying to run those next generation extensions. Is Nvidia nice or what?

V-man

Those developers are too busy getting on with the next demo to worry about assing around to eliminate 4 lines of code here or there. They’d rather spend the time writing another 1000 lines in their next demo. Keep it in perspective. What would you rather have, anal-retentive code or more examples of the next cool thing?

P.S. this is a good example of how you should write code if you want to be productive. Grab a library from here or there and use it. Don’t worry about the unimportant details and don’t even look at the code if it works and you can trust it.

[This message has been edited by dorbie (edited 11-24-2002).]

I’m not complaining about NVidia extensions. I think NVidia is a awesome company that is a key player in the world of computer graphics. I will learn and have learned a tremendous amount from their website. I will continue to buy NVidia cards.

With that having been said, the programming style in the bump mapping demo is horrid. It looks like Spaghetti Code-And-Fix to me. But who knows, maybe I’m just a crappy programmer.

I hope that the NVidia Developer Relations does not mean, “We put a some code on a website. But don’t tell us what you think about it.”

Here are two final questions:

Why is the demo in one 3000 line file with seven unused functions?

Does anyone at NVidia care that programmers have a hard time figuring out how their demos work?

You show a couple of simple and easily understood pieces of code that are completely unambiguous, one is even designed to clarify readability and you complain about spaghetti code. It sounds like you don’t have a clue what real spaghetti code is.

Some code is necessarily complex because it does difficult things.

[This message has been edited by dorbie (edited 11-25-2002).]

Nutty: and just how are you related to Kevin Bacon? ( http://www.cs.virginia.edu/oracle/ )

lucidmm: To be honest, I’m not even sure if that bump mapping demo is meant as a “programming-bumpmapping” teaching aid, I would say it’s more of an interactive presentation of perpixel lighting, meant to be watched rather than disected - so try not to be too harsh…ever been up against a deadline? Noticed how your coding gets uglier and uglier the nearer to crunch time you get? I imagine that was the case before they presented it at some show or other…

I have no idea what you are talking about Dorbie. Please be more specific.

If the demo was written as just a demo to show off NVidia capabilities, then I would like to hear that. All of you have been talking about deadlines, but it has been proven that Code-And-Fix takes MORE time.

I am all for code re-usability, but the way to reuse code is to encapsulate all common code into the one file. Cutting and pasting individual functions is a mistake.

The way I see it bumpdemo.c should have been split up like this:

main.c (glut stuff)
bumpMapTextures.c (normal maps and textures)
combiners.c (set up register combiners and check for extensions)
matrix.c (matrix operations)
torus.c (rendering a bump-mapped torus)

bumpMapTextures.c, combiners.c and matrix.c would all be highly reuseable.

If this code wasn’t on NVidia’s site, I’m sure many of you would see it for what it is.

Have you actually programmed in a commercial environment, lucidmm?

I was referring to your post that started this thread.

If you want code structured the way you like online how about providing it. There’s nobody stopping you.

When you’ve done as much as NVIDIA to offer free code and training maybe I’ll rate your complaints.

Nutty: and just how are you related to Kevin Bacon? ( http://www.cs.virginia.edu/oracle/ )

eh ?!

Wow, an entire thread devoted to what a crappy programmer I am. I don’t know what to say.

Sure, bumpdemo.c could have been divided up into more than, say, one source file. Sure, there’s some dead code sprinkled here and there (think: bonus code). But neither is the worst failing of bumpdemo.c…

Why has no one mentioned the biggest failing of bumpdemo.c – that it only bump maps tori (and only one at that)?

That’s great if you want to write Sim Krispy Kreme or Bagel-mania 3D, but a bump mapping demo that just bump maps a torus is pretty lame if you ask me.

  • Mark