Pages

Dec 30, 2008

There are a lot of people who go straight from denial to despair without pausing on the intermediate step of actually doing something about the problem.

Although he said this to urge people to act on the global warming issue, I think this statement can be applied to anyone who just likes to make excuses about their lives.

I like people who are trying hard to make something happen. I like people who truly believe only hard work can get them something. That might be why I like young ruthless people. On the other hand, it always leaves me a bitter taste whenever I see people who directly go to despair from denial.

Do something if you really want it, and don't ever bullshit if you haven't tried hard enough.

Dec 27, 2008

Merry Christmas! I'm happy to announce that Wolfgang Engel, Jack Hoxley, Ralf Kornmann, Niko Suni and Jason Zink have all worked hard and conspired to bring you Programming Vertex, Geometry, and Pixel Shaders. This book is intended for people that have some background in DirectX8 or DirectX9 programming and want to upgrade their knowledge to DirectX 10. It's also completely free and available on GDWiki!

This book can be considered a first draft, as the team of authors is working on a print revision that will focus on DirectX 11. In addition to using GDWiki to get the content of the book out to you, they also welcome comments and feedback and even Wiki edits so that they can prep the content for the printed and enhanced version. If you've ever wanted to see your name in that Acknowledgments section of a book, stop by and lend a hand!

Great job authors! You've all set a new precedent in terms of content publishing and we at GDNet are happy to have been able to support you throughout this process.

I haven't read this yet. Being a primarily next-gen console developer, I haven't had chance to work with DX 10 yet, so I guess it's a good change for me to skim it through, at least. However, I don't think DX 10 will ever become popular: I think DX 11 will be the next player.

Dec 26, 2008

We all know that magic numbers are bad, but it always surprises me whenever I found out even some programmers with several years of experience in this industry still use magic numbers. This is a code snippet that I had to debug some weeks ago. This code was originally written by a programmer at my work.

program code:

if ( info.packageID == -1 || info.layerID == -1 )

{

// do something

}

Okay, we all know -1 is a magic number here. For me, it did not take long to find out packageID of -1 means invalid package. Although using the constant -1 as an invalid index is very common in programming, I personally prefer some meaningful description even for this unless it's a code for a small tool which is meant to be modified by only a handful of programmers. But I can still live with it: we programmers all tend to get lazy time to time and it's pretty straight-forward anyways.

Then what about layerID of -1? I just assumed it would be also the invalid index, but this case invalid layer. It is a very reasonable guess since another -1 on the same line means invalid package, right? Wrong. It turned out to be not the case after I wasted hours of my "expensive" work hours digging other areas to fix the bug I was trying to solve. To my surprise, layerID of -1 means Still Loading. What? The same number on the same line means two different things? Even in English, we get confused if one word means two different things. Even Eminem implied "what you mean is two different things" is bad in his song, Say What You Say... Okay, maybe Eminem is not so much relevant here. Anyways, you don't wanna do that in a programming language, which tends to be more confusing!

No wonder why this is a very good, or bad, example why you don't want to use magic numbers, eh?

It's All About Coding Standards, Really

In fact, It's all about coding standards, which are pretty subjective to any programmer out there: there is no one coding standard all programmers agree with. The reason why coding standards exist is to make collaboration easier: if your code is not easily understandable by your coworkers, you are being inconsiderate, and you can't be more than a dungeon programmer. In other words, you don't deserve to work at any place other than your own basement suite. Having that in mind, this is the rule I go by:

When Not to Use Magic Numbers:

when a same constant value is showing up multiple times in code. So, if packageID of -1 is used more than once in the codebase, it's better to give it a meaningful name.

or when the number is just too magical, thus confusing people if not explained. layerID of -1 meaning Still Loading is out of normal usage of -1 in my opinion.

or when more than handful of programmers are editing the same codebase. If it's only a small tool which is edited only by only you. Who cares?

How Not To Be Evil
These are some of good alternatives you can use to make that code look better. All of these methods do NOT involves any run-time cost, so you should use them, if you are a programmer who cares about your coworkers.

My personal preference is the last method which uses unnamed enum in class.

1. Use #define:

You can use good old C-style #define to globally associate these magic numbers with meaningful names.

package.h:
#define INVALID_PACKAGE_ID -1

layer.h:
#define LAYER_STILL_LOADING -1

program code:
if ( info.packageID == INVALID_PACKAGE_ID

|| info.layerID == LAYER_STILL_LOADING )

{

// do something

}

The only downside of this method is name collision and making everything globally available does not really get along with OOP.

2. Use const int in namespace
To limit the scopes of these unmagical numbers, some programmers embed const int into namespace.

package.h:

namespace pacakge

{

const int INVALID_ID = -1;
...

}

layer.h:

namespace layer

{

const int STILL_LOADING = -1;
...

}

program code:

if ( info.packageID == package::INVALID_ID

|| info.layerID == layer::STILL_LOADING )

{

// do something

}

I don't particularly disagree with this method, but I have never preferred this method because it essentially stores these const ints separate from classes.

3. Use static const int in Class
Instead of wrapping const ints with namespace blocks, you can simple define the same const ints as static variable in a class.

package.h:
class pacakge

{

public:

// something else

static const int INVALID_ID;

}

package.cpp:
int package::INVALID_ID = -1;

layer.h:
class layer

{

public:

// something else

static const int STILL_LOADING;

}

layer.cpp:
int layer::STILL_LOADING = -1;

program code:

if ( info.packageID == package::INVALID_ID

|| info.layerID == layer::STILL_LOADING )

{

// do something

}

It's an okay way, but still having to define each variables in a separate .cpp file is not so desirable.

4. Use Unnamed enum in Class
This is my preferred way, which works pretty much same as the last method, but keeps everything in one place in a clean way.

package.h:
class pacakge

{

public:

// something else

enum { INVALID_ID = -1 };

}

layer.h:
class layer

{

public:

// something else

enum { STILL_LOADING = -1 };

}

program code:
if ( info.packageID == package::INVALID_ID

|| info.layerID == layer::STILL_LOADING )

{

// do something

}

What do you think? You feel like it is much cleaner, and hopefully less evil?

Dec 17, 2008

I'm known, or notorious, for getting pissed at unprofessional people. My definition of professionalism doesn't involve acting nice, or fake, or always wearing big grin on the face: this kind of people are just super unprofessional, so they have to pretend professionalism in that way.

Real professional people are who own their stuff. In other words, they are experts at what they are doing, so making other people's life easier. And the Utopia I'm dreaming of is where everyone is so good at what s/he is doing, and voluntarily helping out other people with their specialities. If everyone does so, the world would be super nice to live. (Well, this world is already darn nice to live though)

However, there are so many people who are just too sloppy at what they are doing, so burdening, or bothering, other people with their own responsibilities. Whenever I see this type of people, I get pissed. If I find out I have to fill in their sloppiness, I flip out.

Dec 13, 2008

I do use Python at work time-to-time, mostly for build tools and pipelnie stuff. This is the problem I ran into a week ago, and thought I should let other people know too. (I assume a lot of game programmers use Python? Well, not in game code, though)

This is basically a short summary version of this article, which I got my answer from.

If you use redirect stdout of a children process through PIPE, it will hang when the size of output is bigger than 64KB. (And it does not give you any meaningful error message. You might see some deadlock deep into some file handling functinos in ntdll or so)

My advice is NEVER use PIPE with popen. Even if your current subprocess never outputs more than 64K, other programmers can change this shallow assumption sometime later. (This was my case)

Dec 12, 2008

This seems to be new home for free ShaderX books. While I'm not sure if these many-years-old books are still useful, it's awesome that the series editor, Wolfgang Engel, and the publisher made them freely available.

Dec 7, 2008

Yesterday , I've just finished my marking job for this term at BCIT. Whenever I mark, I keep thinking that current tuition structure at any institution is somewhat unfair to the students who are kicking ass, thus not creating much headaches of instructors and school.

Okay, here is the story. As a computer programming assignment marker, we do certain automated testing in which we collect outputs and errors from students' programs and compare the results to the "answer keys." So if a student does an excellent job on perfectly conforming to the requirements, this automated test can be done in 2 seconds. Then going through his/her code to mark on his coding style or class design quality is the last part. Very painless, thus "priceless"(as not costing much).

On the other hand, sloppy students' programs generate wrong results, if not crash, so I have to actually do more manual testing to find out what the problems are: without doing it, I cannot give them partial marks. Then coding style and class design comes after too. So it takes minutes, or sometimes about 30 minutes.

In short, marking sloppy students' assignments takes 10+ times more time than doing kicking-ass students'. And who pays the marker? Directly school does it, but indirectly it's from every student's pocket. (and government, but very little under Liberal government in power) And I'm not aware of any institution which charges sloppy students more and ass-kickers less. So by paying same amount money, hardworking students are actually overcharged, or in nice words, they are paying for those students who need more attention. How nice of them?

Yes there's some kind of scholarship that pays money back to excellent students, but seriously only less than 1% of ass-kickers get the scholarship and the amount is way less than what they initially paid for. Also there are more other bullshits to get scholarship, so at the end of day, students with needs take more scholarship than simple ass-kickers.

The problem does not end here. Most schools also offer free tutors when requested by students, and how much do those students pay for it? None, Nada, Zero. Then do tutors work for free? No. School pays them again. And where do those money come from? Everyone's pocket. (and government, but still very little because the political party in power did not change while I'm writing this post.)

Nonetheless, It's always fun to watch that certain dog-fucker students like to blame kick-ass students on something stupid, while those generous people are giving out their pocket money for the dog fuckers.

Sidenote: So where did I belong to? Good students or bad students? I belong to both groups. I did belong to good students group in grade 1~2, 10~12 and computing school, and belong to dog fuckers in grade 3~9 and lawschool.

Dec 6, 2008

My little cutie boiler have been acting up for a while, thus making me sleep in the cold room quite a while. This 15-year old baby had some gas-shutoff problem and then flame sensor problem, which were all fixed about a month ago or so. That's all good. My plumber all took care of it. I think I could have easily replaced the flame sensor, but not the gas valve. I'm totally a chicken when faced with gas-related problems. It just stinks...... :P

About 2 or 3 weeks this troubled kid's brain, aka control circuit board, is fried. Yum... frieeeed. This time, I decided to fix it by myself instead of calling a plumber who wanted me to pay $260 for this. I'm not really afraid of electronic stuff, given that I've been dealing with that kinda stuff, including computer assembling, for more than like 15 years now. So why not. But the first challenge I ran into was that most heating appliance parts stores don't really open late, especially during weekends.

I went out for part hunting last saturday, which I intially thought a success, but turned out to be a failure. I bought this Super Hot (yum... hoooooot...) zone control board at $190 from Milani but the part was not working, so I had to return it because they did not have any more in stock. By the time I returned it, 12:30 PM, the next store I wanted to go, Andrew Sheret, was closed already. They only open from 8 to 12 on Saturday and closed on Sunday. Also they close at 4PM during weekdays, and the earliest time I can get off from my work is 5PM. Booooo~ So I had to sleep in my cold room for a week.

Fianlly I had chance to visit Andrew Sheret today, and bought the same part, but not broken this time and only at $156.32! It's 21.5% cheaper than Milani and 66% cheaper than the plumber! Hell ya!

I will definately re-visit Andrew Sheret next time I need another part.

Dec 1, 2008

I like new things. Or should I say I get bored at shit so quickly? Maybe... Anyways I like to know more about new things and learn. Whenever I say I like to learn, some people take it as I wanna go back to school. Hell no, that's not what I meant.

Although I highly value some of my formal eduction, I've never been a big fan of school. I've always liked to learn by myself. And I truly believe the only way you really learn something is by trying to solve problems that you ran into and have been stuck with for a while. Sure, I guess you can teach all the answers for all the problems beforehand, but I don't think people are able to remember all those perfect answers for potential future problems. At least I know I can't.

My way of learning is more like research. Whenever I'm curious, I google a lot, I try to find books or research papers on it. Well, basically I do everything I am capable of to collect enough information to satisfy me. In my honest opinion, teachers are only useful as mentors who can answer my questions. And sadly enough, only 20% of teachers are able to do so. The other 80% are basically repeating what they read from books right before classes. Ah, just to make it clear, I'm not a complaining student. I'm not a student at this moment at all: I'm instead a college instructor, so I guess I'm a teacher.

Hmmm.. I've written a lot and I didn't say what I really tried to say yet. So my new interest nowadays happened to be investment. I'm a beginner investor who's been investing only for 3 months or so, but I really enjoy getting more investment knowledge through my research everyday. I don't have any financial advisor, and I don't invest in mutual funds, where funds managers do everything for ya. Well, I kinda lied here. I do actually invest in mutual funds through company RRSP plan, mainly because my company matches what I contribute there up to 3% of my salary. Free money wouldn't hurt, eh? That's why I invest only 3% =D

Anyways, I have another buddy who's been investing for like 2 years. He has his own financial advisor, so his investment scale is much heftier than me. (although most of them is loaned) But you know what's funny? He doesn't really know anything about investment. He just buys what the advisor told him to buy, and it happens to be almost all mutual funds. I think that's what you get by not really learning, thus not owning your stuff. Actually it's quite fun to watch a 2-year investor asking questions to a 3-month noob investor. Maybe I'm just cocky....

There are two advantages at my way of learning:

You save money because you don't have to pay tuition or consulting fee.

You really own your stuff, so it's more fun! (especially if you are a control freak)