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

]

5x3=?

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.

Thursday, June 5, 2014

Sorting in Swift - elegant

let names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"]

reversed = sort(names, { (s1: String, s2: String) -> Bool in
    return s1 > s2
    })

reversed = sort(names, { (s1: String, s2: String) -> Bool in return s1 > s2 } )

reversed = sort(names, { s1, s2 in return s1 > s2 } )

reversed = sort(names, { s1, s2 in s1 > s2 } )

reversed = sort(names, { $0 > $1 } )

reversed = sort(names, >)