Monthly Archives: September 2013

Whoa… and we’re back!

Bah, the last couple of days almost made me die at HabitRPG, mostly because I must complete tasks before midnight (!) and I’ve got used to updating before going to sleep… and that was already late. I had something like 5HP left to avoid losing my beloved belongings, but tonight I made up and the experience gave me a new level (which restores all health), so I’m saved! 🙂 In a boring note, I could still have bought and used a potion, had the money to.

Been quite entertained with the new project, now I’m getting along with method encapsulation and developing resources as I need to. JAWS is awesome, but it lacks some features, such as hitboxes, and correctly being able to tell if a given element is partially inside the viewport … but I’m already implementing them, or didn’t look further into its code (the documentation is not as helpful as I need). JavaScript, in all its freedom, is a nice language but can be a pain sometimes too. Kudos to the guys that develop such great VMs to run all sorts of things, that must indeed be quite a challenge!

That’s it for today, just wanted to put some things out. Still gotta check Evernote everyday to get new blog subjects. I have so much to write about, but the lack of posts exists because I sometimes lack motivation to start the post… once I start writing, words flow nicely. 🙂

More on JavaScript classes, function warzone

Just like Python, JavaScript tends to create things once you mention them and they don’t yet exist. In my opinion, that’s a bit more harmful than useful, because there’s danger in accidentally creating new variables and values when you assumed it would be already holding a known value. Coming from a C/C++/Java background, I would expect some kind of error for the operation:

<html>
<body onload="testFunction()">
<div id="content"></div>

<script>
function testFunction() {
    function Test() {
        var somevar=1;
    };

    var test = new Test();
    test.somevar += 10;

    document.getElementById("content").innerHTML = ""+test.somevar;
}
</script>
</body>
</html>

In this context, somevar might not exist yet, and still, you’re adding 10 to its value! By printing it is possible to check that this var is a NaN, and no errors are issued. To properly (as I eventually found out by trying) get and set its value, one must create getter and setter functions, to “publicly interface” in other contexts:

<html>
<body onload="testFunction()">
<div id="content"></div>

<script>
function testFunction() {
    function Test() {
        var somevar=1;

        this.getSomevar = function() {
            return somevar;
        };

        this.setSomevar = function(value) {
            somevar = value;
        };
    };

    var test = new Test();
    test.setSomevar(test.getSomevar() + 10);

    document.getElementById("content").innerHTML = ""+test.getSomevar();
}
</script>
</body>
</html>

But hey, be careful when using “this”, its context is related to the current function, not the “class”, as one would think coming from a Java mindset. Using “this” inside class functions can cause undesired effects, such as defining new variables inside the “method” context and again we’ll run into the NaN problem:

<html>
<body onload="testFunction()">
<div id="content"></div>

<script>
function testFunction() {
    function Test() {
        var somevar=1;

        this.getSomevar = function() {
            return this.somevar;
        };

        this.setSomevar = function(value) {
            this.somevar = value;
        };
    };

    var test = new Test();
    test.setSomevar(test.getSomevar() + 10);

    document.getElementById("content").innerHTML = ""+test.getSomevar();
}
</script>
</body>
</html>

Pushed some updates to the game on github. 🙂

Classes in JacaScript? There’s a way

I was messing with my game prototype when something came along: how do I create objects in this thing? Many of the examples I’ve seen were quite weird, with functions creating new instances of things and being used to define objects. But what about real classes? Inheritance? After all, is there a standard in JavaScript?

Looks like it doesn’t, and many approaches seem to consist in implementing custom sugar functionality or using some weird techniques (from a C++/Java/Python developer’s point of view). I still want to check the examples to establish a memory footprint, because, apart from “static” (in JavaScript, prototype) functions there is no such thing as static beside a “global variable” (that might even contain a function). JavaScript is indeed an easy but weird language. 🙂

Anyway, my project was pushed to GitHub today, there is some basic functionality but not much beside some test bench. I’m working now to reach an architectural model for my objects with shallow inheritances to assure it “stays small” and following some best practices. The JavaScript/HTML5 Netbeans plugin is awesome! Also took some time to try jVI again, I’m more productive with it even with its performance penalty.

 

DVenn: venn diagrams with a cup of coffee

Long time ago, at one college night class, I was quite amazed that my teacher would have to draw over and over again Venn diagrams to explain logic problems and exercises. That class had a projector that was mainly used to display PPS slides. Since I was already quite proficient at Java and Swing development, I started to develop an application to help him by rendering the diagrams based on a logic expression without the need to draw the whole thing on the blackboard.

dvenn

That application was called DVenn and I guess it still helps him on classes. It can present up to 4-way diagrams and automatically adjust the render based on the number of variables. We published a paper about it and presented at some event. I’ve put it on github. I guess it’s still in portuguese, but there’s not much to translate even, so it should be easy to port around.

Looking at the code right now, it seems quite bulky for what it does, but I’m OK with it. Perhaps some day I’ll do some refactoring and call it done.

Don’t break the owl

Well, I’m struggling to create original content for the blog, but I’m doing my best to write every day (okay, not my best, it’s not the plan to kill myself for it… for now :). Seinfeld’s “Don’t break the chain” is a nice perseverance exercise, and here I am, trying not to break it.

I’ve also been dedicating at least a lesson everyday on Duolingo, and its awesome Android app. HabitRPG says I’m “green” with a score of 1.6 at it, so I guess it’s been ok. Plan to finish the English module, which I’m halfway through, and then starting a different language (perhaps German or even Spanish, to improve some of my beginner level). I highly recommend it if you’re interested in studying new languages, since it can evaluate some of your spelling (at the Web app), has reminders to bug you to study everyday (and avoid hurting the owl’s feelings) and is gamified, so you can actually compete with friends while studying. 🙂

I’ll put some subjects at my Keep so I don’t need to just write about something on the spot. I can do it, but lacks quality… anyway, baba, the chain lives to see another day.

Blogging from my ancient Android tablet

Hey there, this is the first post I’m attempting to deliver from one of my cheap tablets (this one being written from an Eyo net-tab, I guess, the name may vary, also looks nothing like the picture), through the amazing WordPress app. I’m typing at one of those mini USB keyboards residing on an imitation leather cover, and I must say that it’s not that bad…

Lately I’ve been playing with some JavaScript engine called JAWS, and a game is starting to take some form. >:) It’s being hard to blog, sometimes due to lazyness, other times to being quite busy (thank HabitRPG for that), but I’m trying… trust me! 🙂

Also been using Hibernate at a Java SE application, and I can’t say bad things about it (aside reproducing some JPA bugs with floating point numbers at MySQL, but nothing directly related to Hibernate), in fact, it indeed made my life much easier with the Netbeans plugin that does all the “low-level” SQL work leaving you with ready-to-use objects from database tables, and that’s simply wonderful! No need to re-invent the wheel everytime you start a new application. This way I can focus more at UI level programming and doing a much more polished job.

For tonight, that’s it. I’ll be back later.

PS.: The WordPress app sucks at dealing with links at edit level I’ll put the text links later.

Update:  even the wordpress admin panel is not hanling links correctly at WYSIWYG editor, had to place links directly into the post’s HTML.