Why bother with money?

Nowadays, I feel like money business is stinking. I can't help but have this idea to get rid of it, and start a whole new thing based on real values. I'll explain my concerns below.

For your money, you should get value. At least this is what I think when I go and work hard everyday. At the end of the week, when I'm on my shopping duty I see sad things though. I see GMOs everywhere, I see no-flavor-at-all fake chicken products came out from stressful, tiny cages. I see veggies and fruits that shouldn't be there, because it is not their season, however we make it profitable by the blessing called "Greenhouse".

But wait... if I produce value (by working) why don't I get this value back? Is it because we tend to forget the time of Barter? That was about exchanging values, right? Everytime I watch films like Super Size Me, Trainspotting, Fight Club, I'm more convinced in that market is just producing things to make you spend your values. Because that is what you do. Everytime I buy food, I spend some values of mine. Some time, some energy, some brainwork, some creativity of mine. So why I should spend all of these for low-value products?

Instead of giving alternatives, I just leave here questions that bugging me day to day.

  • Is money a real thing? Can we measure someone's performance, time, and experience in money?
  • Why we work 40 hours a week in average?
  • How the fact would influence people's everyday life if we work less, say 2 days a week, and produce the rest for ourselves?
  • That would make connections stronger in our society?
  • Is DEGROWTH an answer?
  • Why do we generate more and more work? Isn't development meant to be work less with the better tools we have?
Feel free to comment.




Configurational programming

When I faced YUI's programming style 2 years ago, somehow I was amused by its elegance. I refer elegance as the configurational approach, that you have to explicitly configure things up, instead of writing down the steps of a process.

For example, here is how you state your column definitions for a DataTable widget instance:

var myColumnDefs = [
 {key:"Title", label:"Name", sortable:true, formatter:formatUrl},
 {key:"Phone"},
 {key:"City"},
 {key:"Rating.AverageRating", label:"Rating", formatter:formatRating, sortable:true}
];

and later on you can say:

var myDataTable = new YAHOO.widget.DataTable("json", myColumnDefs, ...

I'll try to explain why I find this topic so important that it has already influenced my style of programming.

Expectations instead of steps
A configuration like this is a contract between the programmer and the API. The programmer writes down it's expectations from the program and not the exact steps of how to reach that goal. As I came from C# I see this style as an interface. I like interfaces because they are clean, and hiding implementation details.

Config objects vs. parameters
I think there is a huge difference between giving configuration for something versus giving parameters (at least for me). I see parameters as a superset of configurations because parameters can contain not only expectations but details demanding you to understand the code behind the function.

For example, consider this function:

function rangeLowerCase(from, to, elements){
     var els = [];
     for(var i = from; i < to; i++){
        els.push(elements[i].toLowerCase());
     }
     return els;
}

rangeLowerCase(0, 5, ["H", "E", "L", "L", "O"]); //-> ["h", "e", "l", "l", "o"]

When we call rangeLowerCase above we have to give the beginning of the process explicitly with the "from" parameter. But that's pops up lots of questions. Where the implementation starts? From zero or 1? At the end of the day, we have to read the code or documentation to understand what's going on.

So the "from" is not a configuration but a parameter. In my vision a configuration would be like

rangeLowerCase({ "take-first" : 5, "list" : elements});

Here you don't need to read the implementation but you know what will happen... okay that's not true, but at least you can expect it. You don't have to know where we want the first index to start. It's totally upon the developer of the API.

Elegancy

How many lines of code do you have to change when you want to modify its behaviour? I always ask this question when talking about elegancy and I try to hold that number very low in my solutions. Considering the previous example, it is self-explaining how many lines you have to change to take the first 10 elements instead of 5.

To sum it up, a configuration should improve the understanding of the code at first glance so improving the maintainability and clarity. It's more about expectations rather than implementation, so it's closer to the customer's thoughts, and easier to maintain.

Why don't they teach these things?

After university, it's hard to get on with LIFE in capital. What I can tell from my experiences, schools didn't teach me important know-hows but interesting theories. However I find very challenging and hard to fit in everyday life. See the details below.

Time

It's not a common or easy task to manage your time. I mean I work 8 hours a day of course, but what about the rest? Questions bugging me on what to do after my duty, beside sports. I have a lot of ideas about projects and what to learn next, but how should I priorize them? For me, a day just not enough to do everything. Yes, you can say, maybe I'm an overachiever but that's how I work.

So nobody told me at university that there is a course on time-management. Because there wasn't. If I had known back then about Getting This Done, maybe I would have entered in this area with more confidence. So, I highly recommend GTD along with these productivity tools.

Money

Okay so money is unavoidable in everyday life. So you should at least keep track of it and plan with it. It's not too suprising when I say nobody taught me that. Especially when we talking about how to do it. I'm still in the experimenting phase. For example, there are bills what you should store and track, and also there are expenditures what you should not track but limit, say.. for a month. I did not found any usable books on a system like that, but let me know if you do.

However, one thing I actually learned during school. To ask and experiment. Asking questions is the most important part of my life, literally. For me, it means that I will have answers and I strongly believe in that. I haven't regretted this so far.

So if you are learning in school right now, keep asking questions. Whether you are interested or not. Because this is the way how you will learn, generally. You have to excercise that so many times that it will be a part of you without realizing it.

Recent JS challenges

Heck, JavaScript is a vast universe, and I always come across some examples that I have never dealt with before. I'll share two now.

Task


I had a TR an element with a BUTTON inside. I attached an eventListener for the TR, and the task is to decide whether someone clicked on the button (inside the TR), or another element... How should I write the listener?

Solution


function(e){
 var parentTr = e.currentTarget.id,
     target = e.target.tagName;

 if(target.toLowerCase() === "button"){
   /* react for the button */
 }
 else{
   /* another element in the tr */
 }
}
This is a very easy task when you know the difference between currentTarget and target. The latter is always the thing you touch on the screen (for a click event listener, the element that you click) or interacting with, and the former is the element what you assigned your listener to. In this case the TR. That's why I emphasized it with a 'parentTr' variable.

You don't even need a DOM traversal/search to perform this task. Okay, next.

What's wrong with this code?


var allDivs = document.getElementsByTagName("div");
 
for(var i = 0; i < allDivs.length; i++){
  allDivs[i].appendChild(document.createElement("div"));
}

Okay, so the intent is to append a DIV in each DIV already on the page. The problem is that allDivs is a DOM reference, so every time we append a new DIV to the page, this reference will update itself, and the length will grow... so yes, we end up in an infinite loop.

That's enough for today :)

VIM challenge

Nowadays, wind blows me in a very strange direction. Two weeks ago I felt a strong need to learn vim. Now, I can't say I'm a vim ninja, but I can feel that someday I will fully replace my eclipse setup with it. Maybe it's just sexier to program from console, but as I get more confident on a daily basis, I can see what is capable of, whereas it isn't easy to forget these good old keys: Ctrl-C, Ctrl-V and arrows.

Just to note, I'll write my learning steps here:
$ sudo yum install vim
Then I went through vimtutor. Just type it in your console. It's really useful. It will be hard. Very hard to navigate with hjkl but when you reach the motions part it'll be clear that you won't use often these just the jk.

Then for specific programmer tips, I read Why, oh WHY, do those #?@! nutheads use vi?, then Learn Vim Progressively. These two even good when you did not fully committed to learn vim and you want to just see some light.

I share some tips now which I use day-by-day.

Replace line endings

Because I often work with Kendo templates, I have to replace my line endings with a \. This sugar will solve the problem:
:%s/\n/\\\r/g

WRAP lines

If you have a bunch of lines with the same pattern, and you want to wrap every line with a specific text:
http://www.url1.com

http://www.url2.com

http://www.url3.com

http://www.url4.com

http://www.url5.com
:%s/\(.*\)\n/\<a href=\"\1\" target=\"_blank\"\>Some link!<\/a\>\r/
(Okay, here escaping is not a big help for newbies, but it's worth the result)
<a href="http://www.url1.com" target="_blank">Some link!</a>

<a href="http://www.url2.com" target="_blank">Some link!</a>

<a href="http://www.url3.com" target="_blank">Some link!</a>

<a href="http://www.url4.com" target="_blank">Some link!</a>

<a href="http://www.url5.com" target="_blank">Some link!</a>

Show line numbers / turn off

:set number / :set nonumber

Show relative line numbers / turn off

:set relativenumber / :set norelativenumber

At that point, maybe you're wondering, why on earth should one use relative line numbers?
I just tell you one (command) reason below.

Replace from this line through 5 lines

:.,+5s/foo/bar/g[c]
Yes, this is it. You'll exactly see how much lines you should replace with 'bar' when your relative numbering is on.

Open a new pane (split vertically)

:vsplit /tmp/a

Save all panes / Quit all panes

:wa / :qa

Switch between panes

ctrl+w+w
But that isn't it. What can make VIM a fully working IDE (I think) is that you can use linux commands while working with it. So if you fire up vim in the project root, you can always search for files with "foo" content with
:!grep -FR '*foo*'
I don't go into details here, I think you just want to read the Unix as IDE blog series by Tom Ryder. Wonderful tips there.

Okay, enough VIM for now, I'm out.

Easter links

In the last few days I've seen somey very interesting links what I'd like to share.

Badass JS is an interesting concept, showcasing the capabilities of the language
http://badassjs.com/

JS1K is similiar, but it's more like a competition than a blog. If you can do something interesting <1K in JS, then share it! (Funny, but this actually reminds me for C style competitions though)
http://js1k.com/

Derek Siver's entry about learning JS
It's a brief view of the best books available considering JS.
http://sivers.org/learn-js

Learning with Spaced Repetition
From Siver's entry, we can get to here, this is a very exciting learning method. I think the Quantified Self concept is intriguing too.
http://quantifiedself.com/2012/06/spaced-repetition-and-learning/

RED language
RED is a nice concept whereas this one slide catched my eye (click).

It actually says what I think; every language is good for a specific task. (But RED will be a universal solution?). Reach the full slide here.

Have a nice Easter!



Image from http://greatinspire.com/happy-easter-2012/

With or without an IDE?


I've been working on JavaScript projects for 2 years now, and in the beginning, I found it very frustrating to work without a proper IDE, as I came from the C# (.NET) world. But things have changed (?).


Your IDEas?


One can say working with C# (or VB, whatever) in Visual Studio is like a dream. You can find the references of nearly anything, refactor and debug your code easily, in addition there is IntelliSense. This tool is a very strong factor when it comes to development. A few years ago I gave speeches and presentations about C#, .NET, and Visual Studio, and I started my programming career with C# so I can say I like this world.


But things have changed, and nowadays I write a lot of JavaScript code on a daily basis. I use Eclipse now, nothing really fancy. This is a really nice open-source environment, though it's not as good as Visual Studio. Moreover, when it comes to JS it's not so strong at all.


However, this situation has more pros than cons for me. I started to realize when I don't have a really clear view of my "classes" because Outline view starts to fail, or can't see a variable's value just a few clicks away, I start to think about my code. I analyze it, think about it, and critisize it.

"This class shouldn't be so huge. I can't manage it very well."
"I can't see the role here, should I put these into separate files?"
"This variable name isn't good."

So I reckon that I write more manageable code when I don't have such a good support with my IDE, because  I can't see through my classes/functions if they are too big. Moreover, I can't debug so easily so I pay more attention on naming things, especially on variables, thus I write cleaner code.

This post is not about why I don't use NetBeans (which is evolved to a nice tool for a HTML5 dev.) or Aptana Studio (though this one has some serious performance issues I think). It's more likely about why I don't feel the need, and why I can understand hardcore emacs/vi/vim guys.

You have to face it!



In regards to JavaScript there will be a point when you’ll have to face the lack of your IDE, and that time will come fast. Maybe you have a full support for native JavaScript expressions (however some anonymous functions will be enough to confuse any IDE, not to mention the module pattern), or jQuery but when one will start to use other libraries like underscore or BackBone, no IDE will provide any good help.


Okay, the situation is not that bad, because these libraries generally have clear and nice API documentations, but all in all you'll have to give up some of your comfort when you want to write JS codes.

p.s.: If you are wondering about the second picture: that was the first match on Google Search for Eclipse... :)