Jon is not a spartan

My last boss just loved the movie 300. Not because of the sheer awesomeness of the Spartans (although I guess that did play a part) but, I believe, because of the idea that through total dedication to your work you can stand against a full army. This philosophy did in fact permeate his whole life, even getting to call himself a “spartan coder”. That description, I must say, totally fits him.

He is a lone coder developing a full-blown product that competes against companies with more than 50 programmers. And he’s still alive and kickin’. He lives in a simple flat with almost no furniture (just like spartans did), and he works nonstop to have the best product he possibly can. If I hadn’t seen him work, I’d have said it was totally impossible for him to program all those things on his own.

One day, about a year ago, he sent me a test program to check some issues I was having with his UI rendering code. This program was his UI test suite, which tested all UI routines by showing all kinds of images, text and UI elements in a single window. And, you know how programmers use whatever comes to their mind when they have to input some test data? Well, on that test suite, he had written the text “Jon is not a spartan”. Somehow, reading that made my brain click. He was right. I was not a spartan.

I had been working from home for 2 years at that point, and it was taking its toll. The lack of direct interaction with any other human for days; the inability to separate work from personal life; the huge frustration of being stuck with a problem for hours and having no one around to ask. Any psychologist would have been able to see the symptoms: insomnia, lack of motivation, guilt for not working enough, irritability, fatigue…

I was totally depressive.

I did actually realize this, but none of the things I tried seemed to help much. My boss tried a few things too, like establishing a Google-style “do-what-you-want day”, but that only helped for a couple of months. In the end, what woke me up was that simple fact: “Jon is not a spartan”.

That’s when I knew it: “This is the life of a spartan. I’m not one, and it’s killing me. I have to quit”

I told my boss I wanted to quit, I spent the next 2 weeks trying harder than ever to force myself to work, I did a horribly half-assed work at leaving my job ready for the next employee, and I quit. My boss will probably hate me forever for those last 2 weeks, but I promise I did the best I could.

What did I learn from all this?

First, working from home is nice. It gives you a great deal of freedom and it can be just awesome if done right.
Second, working from home is a nightmare. If you’re alone for days on end and work on a potentially very frustrating area, it can crush you.

So how do you work from home and stay happy at the same time?
I have no idea, but I guess you need to be a bit of a spartan. Unfortunately, I’m not.

02. December 2012 by Jon Valdes
Categories: Uncategorized | Leave a comment

Thinking about teamwork

When I was a kid, I hated “teamwork”. In my world, it usually meant “I get to do the work of 4 people while 3 others sit back and watch”. I hated it so much in fact, that I’ve avoided working in a team as much as I could for years. Yet now I’m working on a nice team and I love it! So thinking about that, I believe I’ve found what I hated so much and what I love now. Let me explain.

When you’re a kid in school, teachers create “team tasks” by getting normal homework and just piling a lot of it, until there’s more than is reasonable for a single kid. Every part of the task requires the same set of skills and knowledge, and thus every kid in the class should be able to do any part of it. I guess that avoids lots of problems, but it also removes everything that can make teamwork a nice thing.

See, a team is not a collection of individuals with the same skills and experience. A team is heterogeneous. Even in school! There’s the guy who’s awesome at computers but has horrible social skills. There’s the girl who has incredible blue-sky ideas but has no idea how to execute them. There’s that weird kid in the corner who’s always drawing dragons and stuff. And there’s also the charming guy who could sell a fridge to an eskimo. Now you put them in a team, and make them… do a report about prokaryotic cells? Come on! That’s the perfect team to do awesome stuff!

The great part of teamwork is when nobody in the whole team could do the task on their own, even if given enough time. In my current job, the designer does graphics I could only dream of; the backend guy works magic I don’t understand; the systems guy controls dozens of systems scattered across the world, and the marketing guys do absolutely amazing campaigns and events. Could I ever replace any of those guys? Not in a million years.

So this is what needs to happen in schools too! If any kid in the team could do the team task all by himself, either the task is crap or that kid is a genius. Either way, none of the kids in that team will learn anything useful about real-world teamwork. Team tasks should make kids understand that they need each other’s input and skills, and that they’ll get nowhere without them. And if they do get the task done without working together, there’s something terribly wrong with the task.

And after so much “team”, I had to put this here :-P

03. July 2012 by Jon Valdes
Categories: Uncategorized | Leave a comment

The value of being stuck

If you see me traveling alone in a bus, train, underground or plane, it’s more than likely you’ll find me completely absorbed, writing on a small notebook. My father says I look like a paranoid schizophrenic, and he might have a point. However, that habit has given me the best ideas I’ve ever had. For example, I developed 90% of the techniques I used in my masters’ thesis in those small notebooks, while trying to keep my balance in the Madrid underground.

Having half an hour a day where I have no internet connection, no TV, no books and nobody to talk to gives my brain the opportunity to give shape to any small idea I might have had in the last days. Basically, I need to be stuck in a place where I can do nothing else but think. Some people use the shower for that, but I have a terrible memory, so I need to write things down to remember them later!

From late 2009 to late 2011 I worked from home, and lately I’ve come to realize that staying at home all day meant I didn’t really have any time to think. I was always online, always reading some article, blog post or documentation, writing code or watching a TV series. I learned a terrible amount of things in that time, but in the end all this meant that my brain was acting only as a data storage system, recording every little fact it could, but never thinking about them.

Now I have at least 30 minutes a day of “alone time”, and I always use that time to think about any interesting projects I have in mind. And let me tell you, I’ve never had so many good ideas in my life.

So, find a way to be stuck in one place for a few minutes every day, and think!

12. April 2012 by Jon Valdes
Categories: Uncategorized | Leave a comment

Motivation in games

Lately I’ve been thinking about games, and what is it that makes them work. Most likely, everything I’ll write here has already been said by somebody else, but I find that putting things down in paper (or blog) is useful to get my thoughts clear.

So, my last realization is that most games revolve around the concept of control or domination. The purpose of a game is for the player to try to control the game world itself, to change it at will. For example, in an FPS, you try to control the game, following its rules, to defeat enemies and meet objectives. In Tetris, you try to control the set of pieces you’re dealt.
Of course, the beauty (and fun) of it comes not in the control itself, but in the struggle to get it. A game where you have absolute control over everything wouldn’t be much of a game, really. Conversely, a game where you cannot control anything would scarcely be a traditional game, but something more similar to a film or an “interactive experience”.
And this is something that got said about the Amnesia game, that it wasn’t very game-like. It really doesn’t allow you to control much, apart from the direction to run away in terror, yet it was very well received by game critics and sold quite a few units. How is that possible? I believe it has to do with the human desires it tries to instill in the player to fuel his/her motivation to play. Let me explain.
There’s a psychological theory that says there are 16 different desires that motivate people into action. They are (copied verbatim from the wikipedia page):
  • Acceptance, the need for approval
  • Curiosity, the need to learn
  • Eating, the need for food
  • Family, the need to raise children
  • Honor, the need to be loyal to the traditional values of one’s clan/ethnic group
  • Idealism, the need for social justice
  • Independence, the need for individuality
  • Order, the need for organized, stable, predictable environments
  • Physical activity, the need for exercise
  • Power, the need for influence of will
  • Romance, the need for sex
  • Saving, the need to collect
  • Social contact, the need for friends (peer relationships)
  • Social status, the need for social standing/importance
  • Tranquility, the need to be safe
  • Vengeance, the need to strike back/to win
If we look at the list, the element for what I’ve been calling “control” would be “power”. Also, games generally use some other element from the list, like curiosity (adventure games), order (puzzle games), physical activity (dexterity games) or tranquility (plain survival would fit in here). The main motivator however, from Sim City to Bejeweled, is almost always to exert control in the game world to meet certain objectives.
But not in Amnesia! That game substitutes the control motivation with a terribly strong survival (tranquility) motivation. The game makes it very clear from the start that you’re powerless to control almost anything in the world. You can explore, and if you find something nasty, the only thing you can do is run or hide. You’re not trying to “beat” the game and come out triumphant feeling you achieved to “change something”. You’re just trying not to die the next time you open a door!
And now the question is: could this same thing be done with a different main motivator? Could we create a game where the main motivation is independence? Or idealism? Or even vengeance? It most likely wouldn’t fit the traditional definition for what a game is, but it would surely be interesting!
If somebody gives a shot at it, I promise you’ll get my money!
Oh, and if somebody hasn’t seen Amnesia in action, check out this video. Turn down the volume, by the way, the player gets quite scared. Also, there’s quite a lot of f-word in the video…
Skip to 2:00 if you want to get to the really intense (and fun) stuff ;)

12. January 2012 by Jon Valdes
Categories: Games | Tags: , | Leave a comment

New year, new me

Today’s officially my last day working for RandomControl.
In these last two years I’ve learned a lot. Chema Guerra is the most proficient C++ programmer I’ve ever seen, with his almost obsessive dedication to clean code and design, and he’s certainly passed lots of that to me. When I began here, I thought of myself as a pretty good C++ programmer. Now I’m a lot better and I know I still have a long way to go before I really get to be “pretty good”. Thanks for the humility lesson, Chema xD
Also, in this job I’ve had to work in C++, C, Objective C, python, ruby, javascript, lua and a couple of small scripting languages, filling my need to learn new things all the time. I really need to shake my brain a bit every few days to keep me interested, and that helped a lot.
I also have to thank Chema for giving me so much freedom with working schedule, holidays and work objectives. Another great thing is that, as I had to move from one side of the country to the other, the fact that we’ve been working from home was a real godsend for me.
To the RC testing team, I have to say you are one of the best CG artists I’ve ever seen, and your renders are so great it’s usually impossible to tell they’re CGI. Keep up that amazing work! And most importantly, you’re great to work with, always giving great feedback and making our work feel valued. I’ll miss working with you, guys!
But it’s now time for me to move to new things, so best of luck to the RandomControl team, the most hard-working guys I’ve seen in my life. I really wish your amazing work really pays off, you sell like pancakes and become trillionaires or something. As for me, it appears I’m going back to my old hobby: games development!
Stay tuned ! ;)
P.S: With a bit of luck, I’ll be able to update this blog a bit more often. Most likely I’ll just post updates in twitter, but I’ll try to post something here too. Btw, my twitter is @jon_valdes :)

31. December 2011 by Jon Valdes
Categories: Uncategorized | Tags: , | 1 comment

Trip to Kenya

I didn’t tell most people, but on April 1st I went on a 10 day trip to Kenya. I’m planning to upload here a good portion of the nearly a thousand photos we made during the trip, but until then, here’s a good one to show that IT-related services is never the best paid career. Not even down there ;-)

IMGA0061_2.JPG
And here’s an image of an absolutely beautiful place on the delta of the Ramisi river, south of Mombasa. The guy in the image is me, running in that crystal clear, mildly-warm water. That beach is an island that disappears when the tide comes up. All white sand and no-one else but ourselves in the island. I just loved that place.
IMGP1330.JPG
When I have some more time, I’ll create a gallery with loads and loads of photographs of that extremely beautiful country.

16. April 2010 by Jon Valdes
Categories: Uncategorized | Leave a comment

GPU Raymarching with Distance Fields

These last two weeks I’ve been pretty distracted with personal issues, and to get back on track it always helps me to start a small personal project in which I experiment something I’ve never done before. So here we go: GPU Raymarching using Distance Fields.

This project is completely based on the work of Iñigo Quilez, the great IQ from rgba. He put some slides in his website explaining how to do this kind of rendering, and after reading them I just had to try it for myself.
If you want to read more, just go here: 
http://www.iquilezles.org/www/articles/raymarchingdf/raymarchingdf.htm
And now, time for some videos:





 

I already have another build with more shapes and weird things, but it’ll have to wait until I get distracted again ;-)

26. March 2010 by Jon Valdes
Categories: Graphics, OpenGL, Programming | Tags: , , | Leave a comment

On C++ performance: The Evil Mr. Branch

Here’s a simple problem . For some reason, you’ve got to select between two types or values: smaller (or equal) than 50, and bigger than 50. And you need to do that fast using one core (no multithreading). ¿How do you do it?

For our example, we’ll have an array called data where all values are stored, and an array called results, where an integer value is stored, indicating if the input was bigger or smaller than 50.

So, this is the straighfoward way to do it.

And most of us (and myself 2 days ago) would say: “you won’t get much faster than that!”. Well, in fact you can. How?

By not branching!

In school they show you that branching can make the processor flush the data it has in the pipeline and start over. They also tell you that today’s general-purpose processors do not generally take a big hit when branching, but that hit still exists (I’m talking x86 PCs, here. Consoles DO have serious problems with branching).

So, how do you do this without branching? With a small trick ;-)

If condition has all bits to 0, the second half of the computation will be 0, so result ends up being x. On the other side, if condition has all bits to 1, the x cancels out, and we get result=y.

So we get a function like this (code shamelessly taken from here):

If a is positive, it returns x, if negative, returns y.

So using this function, we can get our array sorted out just like this:

It works just as well… the only question is performance. What will run faster?

Well, in my machine (a Core 2 Duo at 2.4GHz), for NUM_DATA=10000, and 200000 iterations of those loops, I get:

- Using GCC with no optimizations:

- Using GCC with -O3:

The difference is not that big without optimizations, but with them, it’s clear as day: not branching gets you further. More than a 20%, in this case!!

And this goes to show you what some people might already have told you: compilers inline the hell out of your code if set to high optimization values, even if you don’t explicitly ask them to. This code is faster using a function call inside the main loop than without it!

By the way, GCC is NOT generating MMX, SSE, or any instructions like that. This is the disassembly for the main loop in the branchless version (the text on the right is my interpretation for the asm):

The process is heavily optimized by GCC, but it’s all there in normal, honest-to-fsm, everyday-life instructions.

I do still have some doubts about this, however, as the GCC optimization for the branching loop doesn’t use a j(n)le or jz instruction, but setnle. And I can’t find out if this instruction does in fact flush the pipeline or not. Anyway, it still results in a faster processing when using the isel version.

For comparison, here’s the optimized branching loop:

And, well, here’s the whole testing code if anyone is curious about it:

26. December 2009 by Jon Valdes
Categories: C++, Programming | Leave a comment

C++: Could you please code cleanly? Pretty please?

One of my little things when coding is that I always feel ashamed when my code is not clean.

This means I try very hard to make my code simple and easy to understand. I don’t always succeed (not even close), but I try.

I wasn’t always like that, mind you. As a teenager, my code was just a horrible mess of spaghetti code. But Pablo Orduña showed me long ago the value of easily understandable code, and since then I always try my best to code in a clear and non-hackish way.

Anyway, these days I’ve found myself working with code from other people. And, at that, people that didn’t try to create readable code. I’m sure they did know how to do it. They just weren’t in the mood. You can just read it in the code: “if it works, ship it!”

As a small example (there are much much worse things than this), here’s a slightly modified version of a function I found the other day:

Now, did anyone notice something odd? The nested ifs and loops? They make it unnecessarily hard to follow the program flow and they don’t buy us anything in return!

In fact,the whole structure of the function allows us to remove most of the 9 (yes, 9) indentation levels in that code. We just have to reverse the ifs and return early. Like this:

Max indentation: 3 levels.

It takes less than a minute, it’s safe to do, the meaning of the program is exactly the same… and it’s much cleaner and easy to understand! And as a bonus, it isn’t even longer than the previous version!!

There are even clever people that have said this before me several times!

So please, do try. I know it seems easier and faster not to, but it’s only in the short run. Some day (when you have to go back to try to understand your own code) you’ll regret it.

Still unconvinced? Now try imagining this with 700 loc functions (and yes, I have a few like that one here…)

21. December 2009 by Jon Valdes
Categories: C++, Programming | 8 comments

New job!

Tomorrow monday is officially my first day working for RandomControl as the fryrender plugins subsystem developer and maintainer.

By the way, I’ll be telecommuting from home, so I’ll avoid cubicle-work once again (yay!)
And, well, I hope this job leaves me some time (and it doesn’t eliminate my coding-mood) so I can keep on posting some weird stuff here!
And now, I’m going to bed. Gotta get up early to go to the office tomorrow in the morning :-P

22. November 2009 by Jon Valdes
Categories: Blog | Leave a comment

← Older posts