Rogue Coding | precision is futile, you will be approximated

Sep/10

22

JavaScript is cool – Basics

On public demand (of a friend and collegue) I will start to write a little step by step why JavaScript is cool. This post is ment for people who do have little to no experience with JavaScript but do know the basic concepts of programming. You have to know what a variable is and understand basic concepts of syntax.

Any example in the following article is intended to be runable, unless stated differenly. So if you’ve got a browser with a console at hand you should be able to try them for yourself.
All WebKit Browsers (Safari, Chrome) have one, so does Firefox (with Firebug-AddOn) and if you really really cant evade it even the Internet Explorer (8+)
Just look for Debugger or Developer-Console in your menus.

I’m not going to bother with what JavaScript’s history is, nor what it’s really called or who invented it. If you’re eager to lear that take a good book or a look at JavaScript on Wikipedia.

The following part will cover some of the basics of JavaScript, followed by the exlanation why Everything is an Object is cool.
If you’re certain to know them, you might as well skip to the advanced parts.

(more…)

No tags

Jul/10

19

NativeJS

Got my first real OpenSource Project hosted at github.
Have a look at NativeJS

More information to come, soon … :)

Tharabas

No tags

Jan/10

21

PHP list with Cocoa

This post demonstrates how the PHP list(...) = ... language construction can be used in Cocoa. You do not need to know PHP for this, but you should have some knowledge about Objective-C Categories and C-Preprocessor macros. Whether or not you do meet these requirements, I’d recommend my previous posts about Categories and Macros anyway ;)

There is a language construct list(...) = ... in PHP that can be used to assign several values on the left side of an equation with values from the right side.

list($a, $b, $c) = array('a cup', 'coffee', 'morning');

This comes in handy if you do not have an ad-hoc defined array on the right, but the result of a method.

$sentence = "Henry took a trip to London";
list($head, $tail) = explode(' ', $sentence, 2);
// $head => "Henry"
// $tail => "took a trip to London"

(more…)

No tags

Jan/10

19

Better late than early

This post deals with the benefits of late binding in Objective-C, especially the so called categories. There is a short theory and reason part first before you will encounter some really helpful categories.

Note: In the following part some examples from my own Cocoa-Framework will follow. Currently I intend to release it as soon as the work for my diploma is done. For now, there will be just some snippets.


When coding in a rather strict language, such as Java, with a heavy focus on being object oriented and, you will occasionally run into an unary method, that is used very often and the one argument is a basic datatype. An example of this might be some kind of internationalization method:

String translated = TranslatorUtil.translate("source string");

As the TranslaterUtil itself might be a Singleton you might want your piece of code to be like this:

String translated = "source string".translate();

Where .translate() would call the TranslatorUtil internally, but the result would be easier to read.
(more…)

No tags

Jan/10

7

Fun with macros

This post deals with the risks and benefits of defining and using C-Precompiler macros in Cocoa.

For those who do not know what a macro is and how it is defined, simply read on.
The rest may skip the introduction and continue with the real fun


“Macros of the C-Precompiler are a seed of pure evil and must not be used in any good C program. They lead to errors and will cause code that cannot be debugged properly.”

This is a common belief about the neat little text-replacement feature, called a macro. Even though the part about leading to errors can’t be refuted entirely, they can come in handy betimes, even in Objective-C.

They are used within Cocoa itself. Just think of the MIN/MAX macros. But one at a time.

First let’s have a recap of what a macro is:

10
#define NAME(ARG_ONE, ARG_TWO) ARG_ONE + ARG_TWO

Defining a macro is simple and straightforward. We start with the #define keyword. The Hash indicates, that is is handled by our precompiler.
Then we’ve got the macro signature which consists of a NAME followed by a number of arguments, separated by a comma each and wrapped in parenthesis like (ARG_ONE, ARG_TWO). Whitespaces can be omitted within the parenthesis, however, after the right parenthesis the macro body follows.
The body will end at the end of the line, unless there is a backslash \. In that case the macro will continue until the next line that does not end with a backslash.
Remember that a macro is noting but a coded search and replace. Having that in mind the body is the replace part, even though it can do a little more.
(more…)

No tags

Nov/09

8

What’s in a name?

This post deals with some thoughts around how a coder could choose the name for anything written and hopefully a glimpse of what should be done and what should be avoided.

When you’re writing code, you have to consider a name for every variable, object, function or method. Finding the right name for it is a vital part and not always as easy as it may seem.
You will have to write and read those names a lot of times. So when you think about names for anything in your code keep this in mind:

Naming is a trade of readability against writeability

Let’s have an example with some sort of java/c-like code, that I assume you’re at least a little familiar with:
Supposed we have written a method that takes message string as input and displays it at the next line of our console.
How could we entitle those two?
(more…)

No tags

Nov/09

6

This will be the first …

… post in my blog. Hurray *cheer*

But wait a second … what exactly is this blog and why should you read it?

Hi, I’m Ben, nice to meet you here.

Thanks to Mario, this now appears to be my blog, where I can write about my thoughts on coding.

Coding is what most people like me refer to when they talk about the process of designing and implementing computer programs.
Those Programs are usually written with a lot of text files containing stuff like

echo "Hello World";

These files are called code as they code the information the computer has to execute to run a program, and thus the process is named coding.

Lots of people do that, and some even earn money with it or like it. There are rumors that those sets aren’t disjoint, but I heavily doubt that ;)

Anyway, currently I do not know what I will write about in the near future, so stay tuned.

No tags

Theme Design by devolux.nh2.me