Miguel Costa
"A serious and good philosophical work could be written consisting entirely of jokes."
(regarding variable names) If you can't pronounce it, you can't discuss it without sounding like an idiot. (...) This matters because programming is a social activity.
-- Bob Martin (Clean Code, chapter 2)
Variable names should be
PRONOUNCEable and SEARCHable
Don’t be afraid to make a name long. A long descriptive name is better than a short
enigmatic name. A long descriptive name is better than a long descriptive comment.
Clean Code, chapter 3, section "Use descriptive names" (page 70)
Don’t be afraid to spend time choosing a name (...) Modern IDEs like Eclipse or IntelliJ make
it trivial to change names.
"There can be no worse reason for using the name c than because a and b were already taken" -- Bob Martin, chapter 2
Anything that forces you to check the function signature is equivalent to a double-take. It’s a cognitive break and should be avoided.
Functions should either do something or answer something, but not both. Either your function should change the state of an object, or it should return some information about that object (command query separation)
Functions should do one thing. Error hand(l)ing is one thing
(...) if the keyword try exists in a function, it should be the very first word
(...) there should be nothing after the catch/finally blocks
public void delete(Page page) {
try {
deletePageAndAllReferences(page);
}
catch (Exception e) {
logError(e);
}
}
private void deletePageAndAllReferences(Page page) throws Exception {
deletePage(page);
registry.deleteReference(page.name);
configKeys.deleteKey(page.name.makeKey());
}
private void logError(Exception e) {
logger.log(e.getMessage());
}
Make programming appealing on many levels (beginner and intermediate)
('b' + 'a' + + 'a' + 'a').toLowerCase()
Hints
('b' + 'a' + + 'a' + 'a') // baNaNa
('b' + 'a' + + 'a') // baNaN
('ba' + + 'a') // baNaN
('a' + + 'a') // aNaN
( + 'a') // NaN
Answer: "banana"
new Array(16).join('wat' - 1) + ' ??????'
Explanation
'wat' + 1 // 'wat1'
'wat' - 1 // NaN
'wat' - 1 + 'wat' - 1 // 'NaNNaN' (string)
new Array(4) // [, , ,]
new Array(4).join('wat') // 'watwatwat' (3)
new Array(4).join('wat' + 1) // 'wat1wat1wat1'
new Array(4).join('wat' - 1) // 'NaNNaNNaN'
Answer: = 'NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN Batman'
[] + []
{} + {}
explanation by
Answer: "" and NaN
[] + {}
{} + []
explanation by
Answers: "[Object object]" (string) and 0
Explanation
# with 'a' undefined...
a = a
explanation by
Answer: Nil (error not thrown)
VERY SIMPLE
... in a weird programming language
He is a developer
Done is his limit
While he is not Done
Build He up
Shout he
What's this output in Rockstar?
Inspired by Sara Vieira's talk, "Build dumb sh*t"... and by Tim Holman, and ???, and myself!
VERY SIMPLE
... in a weird programming language
Midnight takes your heart and your soul
While your heart is as high as your soul
Put your heart without your soul into your heart
Give back your heart
Desire is a lovestruck ladykiller
My world is nothing
Fire is ice
Hate is water
Until my world is Desire,
Build my world up
If Midnight taking my world, Fire is nothing and Midnight taking my world, Hate is nothing
Shout "FizzBuzz!"
Take it to the top
If Midnight taking my world, Fire is nothing
Shout "Fizz!"
Take it to the top
If Midnight taking my world, Hate is nothing
Say "Buzz!"
Take it to the top
Whisper my world
FizzBuzz in Rockstar (up to 100)
By Miguel Costa
It's easier to keep learning if you're having fun doing it!