Monday, November 30, 2015

Shopping list or how to name a function parameter

- Hunny!
- Yes, hunny!
- Can you please run to the store and get few things?
- For sure, hunny! What do you need?
- I need bread, eggs, cheese, milk, apples and pears. Get 2, a dozen, a pound, 2 litres, a bag and 4 or 5!


Funny eh? This is how some language define the functions. Luckily, Objective C and Swift are different. You can use named parameters that makes the life easier.

Here are some rules for naming the parameters:

Friday, November 27, 2015

Whacha doin' or how to name a function?

While the variables are the nouns of the coding (as we've seen), the functions are the verbs.

To be sure they have a correct name, ask them:

"Whatcha doin'?"

"I [function name]" should be the answer.

"I createDatabase" - is good.
"I sortArray" - is great.

"I user" - not that much.
"I database" - nop.

Thursday, November 26, 2015

How to name your variables and your kids

Story one

Some time ago, I travelled in India and one of things that amazed me was that, after I was introducing myself, everybody was asking: “What does your name mean?”

"What do you mean what does it mean, it is a name, names mean nothing", I was thinking.

Of course I was wrong. Most of the names mean something:

John means gracious
Mary means sea
Will means of course will, desire
and so forth

Even my name Dragos, comes from Drag which means loved in Romanian. My Indian friends were amazed when I was telling them that.

Looking for the meaning of a name might help choosing a name for your kids.  Even if it is nicer to find out after you've already chosen one.


How about the variable we use in our code?

Wednesday, November 25, 2015

Refactoring the evil i, j, k

For the sake of argument, consider you have the following input data:

let userIds = [1,2,3,4,5]

let userNames = [
    1 : "John",
    2 : "Mary",
    4 : "James"

let userAges = [
    2 : 30,
    4 : 40,
    5 : 25



If you think you knew how to compute 5x3, well, after reading this, you will not be that sure

Tuesday, November 24, 2015

The Programmer's Oath

Read here the Programmer's Oath by Uncle Bob

And this is a shorter version: As I love my programming activities, I will always write code that I love.