Dec 30, 2008

Do Something

This is what Al Gore said in the movie,An Inconvenient Truth:
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

Free DX10 Shaders Book

I found it on recent news:
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

No Magic Numbers Please

A Real-world Example Why Magic Numbers Are Witchcraft

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.



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.


namespace pacakge
    const int INVALID_ID = -1;

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.

class pacakge
    // something else
    static const int INVALID_ID;

int package::INVALID_ID = -1;

class layer
        // something else
        static const int STILL_LOADING;

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.

class pacakge
        // something else
        enum { INVALID_ID = -1 };

class layer
        // 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

Unprofessionalism Pisses Me Off

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

NEVER Use PIPE with Python popen

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)
  • Instead, always use a tempfile. (see the code example below)

Code examples:
  • Not-so-good code:

    p = Popen(cmd, stdout=PIPE)


    out_lines = p.stdout.readlines()

  • Better code I ended up using (but was told a bad advice):

    temp_file = tempfile.TemporaryFile()
    d = temp_file.fileno()
    p = Popen(cmd, stdout = d)


    out_lines = temp_file.readlines()

p.s.1 You don't have to close temp_file. It'll be closed when garbage collector collects this. But still donig so would be a good practice.

p.s.2 This was done in Python 2.5.1. The reason why I'm saying this is because I just heard Python 3.0 is not backward-compatible.

Dec 12, 2008

New Download Page for Free ShaderX Books

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

Good Students Cost Less

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

Awesome Andrew Sheret

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

Fun of Learning

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)

Can we just be good at what we are doing, please?

Nov 22, 2008

The Art of the Reverse Engineering

Although I have been really keen on technologies, more precisely all the naughty programming behind any software, I have never tried to reverse engineer, or crack, a program. It's not because of my ethics: just cracking other people's software have never interested me.

But yesterday, I downloaded a trial version of a small Windows application, and it said I can only execute it only a certain number of times. Oh boy, that really got me curious: I have seen a number of "trywares" which allows you to use them for a certain period, but not for certain number of executions. I always thought time-limited software can easily check current time against first install time, or something similar to that, to determine whether the trial period is expired or not. But to make software with limited number of executions, it should keep the execution count somewhere, I figured. And the information should not be easily visible. Otherwise, anyone can easily delete or modify the information to unlock the full featureset. So, I decided to find out what smart things this program is doing with the info. (By the way, I won't reveal the name of application here since I don't want promote anyone to crack this program, which is not just illegal, but also making the creator unhappy, or out of business)

First, I kept executing and exiting the program, and it really stopped working after the specified numbers! OMG!

Second, I tried to look for any new file, which was written during my crazy launch-and-kill session. I was not able to find any suspicious files.

Third, I tried to find some registry entries which the software might have written There were some registry entries associated with this application, but didn't see anything that can be deciphered as a count number.

So, I was stuck, but i was still curious. And I'm always a curiosity-driven programmer. I like to find out answer when it can be found with logical thinking. That's when I finally decided to reverse engineer the application. And after 4-hour wrestling training with disassemblers, I was managed to find the answer I was looking for, how to store the count in a secure manner, and I was not really looking for, all the thousands of valid licence keys the creator encrypted and embedded in the executable file. And again, I'm not gonna disclose any license key here because that was not my intention.

Through this reverse engineering, I learned these things:
  • how to set usage limit on sharewares, which might become useful if I ever decide to release a shareware utility.
  • embedding valid licence keys as encrypted string might not be a really good idea, but I'm not sure if there is any better way without using Internet validation.
  • reverse engineering is pretty darn easy if you know how to read all the low-level programming languages.
And thanks god! Bill C-61 has not been passed yet. I heard this kind of activity is also copyright breach under that bill, which is one of the biggest jokes I have ever heard of. Although I don't think I would do it again, this kind of practice should not be illegalized when the intention is purely on learning.

Hmmm, but I'm not sure if what I heard from other people is really valid because often people without legal education tend to overreact. Maybe I should start to read the bill to figure out what exactly the bill wants to achieve. Oh, did I tell you I also have a LL.B degree?

Nov 19, 2008

You Suck

I respect people's honesty. And my definition of honesty is speaking up the truth in a super straight manner even if it's brutally harsh to someone. I'm kinda known for being bluntly honest, especially at the school I'm teaching game programming students.

I always say good things about other good teachers, and don't hesitate to bitch about other horrible teachers. And as I always say, one good thing about working at the Art Institute of Vancouver is they don't have any contract term or condition which prevents me from commenting on other instructors' competencies. Woohoo, my mouth is not zipped here. How wonderful is it?

But teachers are not someone I want to talk about here: actually it's about students, well certain students. I have some students who, in my brutally honest opinion, won't be able to get a job in this industry in million years, if not trillion years. I always want to tell them the truth so that they can switch to a right career for them before wasting 10 to 20 thousand dollars of money as well as 2 years of lifetime at this school.

But here is one funny thing. Most people are not really good at accepting criticism. I'm no exception, either: It takes time for me to accept criticism unless I ask for their criticisms first. Knowing that, I don't really tell them "You Suck Superly Duperly" unless they ask my opinion on their bright future in this industry. So how often do you think they come to me and ask? NEVER... never from those suckers. Only students with at least decent, thus employable, skills ask me to evaluate himself. I believe their intention is to get better and better. Then why those suckers never try to get my "invaluable" opinion? This is my theory... I think they already know they suck, but they don't wanna accept it, so they just avoid, or deny, it. You know when people are afraid of something, they tend to fall into the realm of ultimate freesbee...... I mean, ultimate denial...

But you know what? If you don't accept it, you won't get better... you won't be out of it forever...

I'm always ready to give you my two cents. Just ask me a simple question: "Do you think I can get a job in the gaming industry?"

Nov 11, 2008

Yes, I Have Vancouver Game Company List

I was surprised when Charina, a career service advisor at the Art Institute of Vancouver, where I'm teaching HLSL classes at night, told me she's been using my own list of Vancouver game companies for a while.

I started the list when I was looking for a job in Vancouver area, and then I decided to share it on the net for those people who are dying to get into this industry, as I did. But after years, I was not sure if anyone is actually checking out the page, so I was kinda slacking off at my-own-self-made duty.

But apparently, someone is still benefiting from this list. So I decided to keep updating the page.

You can find the list at

Enjoy, if you are really serious about being a game developer.

I Am Blind Renderer

Okay.  Since it's my first post, I figured it would make the most sense to explain why I picked up the name, Blind Renderer.

Sadly, it's my identity.

First, I'm a renderer, which is another name of graphics programmer(in the gaming industry), but for some reason, I like to be called as a renderer than graphics programmer.  So there goes the first(or second) bit.

Second, I am really blind.... Well sorta... I'm actually colour blind.  People do ask me which colour I cannot see.  Sorry, but I can see all the colours.  Actually I have a mild form of colour blindness, which is called Anormalous Trichromacy, I believe.  Accordnig to Wikipedia:

Anomalous trichromacy is a common type of inherited color vision deficiency, occurring when one of the three cone pigments is altered in its spectral sensitivity. This results in an impairment, rather than loss, of trichromacy (normal three-dimensional color vision).
  • Protanomaly is a mild color vision defect in which an altered spectral sensitivity of red retinal receptors (closer to green receptor response) results in poor red-green hue discrimination. It is hereditary, sex-linked, and present in 1% of all males. It is often passed from mother to child.
  • Deuteranomaly, caused by a similar shift in the green retinal receptors, is by far the most common type of color vision deficiency, mildly affecting red-green hue discrimination in 5% of all males. It is hereditary and sex-linked.
  • Tritanomaly is a rare, hereditary color vision deficiency affecting blue-yellow hue discrimination.

When I say, "I'm colour blind.  And I'm a renderer", people thinks I am lying because they think colour blinds cannot do the work.  But as I said above, I am not complete colour blind, so I can do my job (and I love this job) although having weaker colour sense is a bit unfortunate.  And trust me, I have even seen a colour-blind environment artist lead who's kicking ass in his job. (well minus texture works)

So long story short, I'm a colour blind and a renderer, which makes me Blind Renderer.  Such a cool nickname, eh?