Category: Languages

Martin Fowler webinar, new Refactoring book

Martin Fowler webinar, new Refactoring book

These may well be the notiest notes I’ve ever published, but just in case they’re of any use to anyone… if nothing else they may whet your appetite for the new edition of Martin Fowler’s Refactoring book.

I confess I never read it first time round (not on purpose, just there are so many books in the world and so little time…), so I’m looking forward to reading it this time. It hasn’t come out yet in the UK but should be some time in the next few weeks. Mine is already on order [drums fingers impatiently].

So anyway, Martin did a webinar today on the topic of his new book, and here are my notes:

Refactoring should be done via small changes

  • v small semantics-preserving changes
  • So small they’re not worth doing on their own
  • String together small changes to make a big change

When adding new functionality:

  • Alternate between refactoring and adding functionality
  • Often it’s easier to add new functionality if you refactor first
  • Balance between adding new functionality and refactoring – it’s a matter of judgement

V1 of Martin’s Refactoring book vs v2

  • Some things that were included in the first book he decided not to include I the second
    • Eg Unidirectional vs bidirectional – not important
  • Some things he thought were too trivial for the first book, he has now changed his mind about and included
    • Eg moving statements within a function
  • Most notable changes = no longer centrally object-oriented
    • “Extract function” used throughout instead of extract method
    • One of the refactorings is around the choice between OO and non-OO
    • The most visible thing here is the choice of language (javascript)
    • But language is not necessarily relevant anyway
  • OO vs functional
    • He doesn’t see that as a huge shift
    • OO should still have functional elements – referentially transparent
    • They are overlapping paradigms, not distinct

Favourite refactorings?

  • “Split phase”
    • Hunk of computation which can sensibly be divided into two phases with a data structure communicating between them
    • Eg parsing – separate the tokenising out – deal with a series of tokens instead of a stream of text
    • But if you split a loop, what if you are introducing performance problems? See below…

Performance and refactoring

  • Split loop is something people often worry about because it will run the loop through twice
  • Most of the time it doesn’t matter – a push for clarity will not change the performance of the code
  • Most of the time by refactoring you open up an opportunity for performance improvements you would never have noticed otherwise
  • Then again you should run performance tests frequently
  • Not necessarily with every build, but every day or two
  • But most micro-changes have no impact on performance
  • You will only find real performance impact by performance testing

Recommendations for other books?

Refactoring architecture:

  • Always have to ask, how do you make the smallest possible change?
  • Eg extracting a data-intensive microservice from a larger system
  • Most of the moves are happening within the monolith BEFORE you start firing up the external system
  • Then you move stuff in really small pieces
  • Things that change for similar reasons should be together – you need to see the relationship between them

Branching / trunk-based development

  • Develop on a branch and merge at the end, with branch being long-lived – days, weeks or months
    • Still a really common pattern
  • But if something has been refactored, you don’t find out until you merge – this can blow up on you
    • It means you become scared to refactor! There’s a disincentive.
  • Continuous integration: Integrate with each other fully at regular intervals – at least once a day
  • Every day you receive everyone else’s code changes and push your own changes back
  • Removes the big painful merge problem – not saving up for a big horrible crunch
  • Adage of Apollo – it hurts if you do it more often (?)
    • Sorry, I wrote this down but I’ve since Googled it and I don’t really know what it’s about – I may have misheard!
  • Open source development:
    • Actually this CAN be a good place to use branches, because everyone working separately and you can’t guarantee all changes should be merged
  • People call it trunk-based development but “continuous integration” is a better name because that’s what it’s really about
  • People worry about continuous integration but it’s less painful than they think
    • If you do integration every day it becomes easier and less painful until you stop even noticing

Responsibility

  • Keep code base in healthy state
  • If not you are stealing from colleagues, clients and employers!
  • But no point saying you should do it for moral reasons, that won’t motivate people to do it
  • It’s economic: Want to get more changes out more quickly
  • It’s professional: We’re being paid to produce features rapidly
  • It’s not up to managers or business: They don’t know how to keep code healthy – that’s what they pay us to do

Refactoring and design patterns – are they incompatible?

  • With a lot of patterns, you shouldn’t introduce them right away cos they’re not appropriate and you don’t require the full strength of them yet, particularly the more complicated ones
  • Introduce patterns as a result of refactoring: Refactor towards them
  • This was recognised by the original Design Patterns authors (Gamma, Helm, Johnson, Vlissides)
  • Also Josh Kerievsky: Refactoring to Patterns

Code smells

  • Code smell of the week!
    • “This week we will look at long methods” – whenever we find them we try to refactor them

When not to refactor!

  • Code that is never touched
    • Sitting behind an API, working quite happily, doesn’t need to change – doesn’t matter if it’s a mess!
  • Don’t clean code all in one go – just a little bit more every time you go in
    • Over time that will concentrate your efforts where they are most needed – ie areas modified most frequently

Refactor as a step in the red-green-refactor cycle

  • You should only refactor when tests are green
  • Sometimes that means you have to remove a failing test, refactor, then put the failing test back in again
  • Ralph Johnson, John Brant, Don Roberts wrote the first Smalltalk refactoring book (A refactoring tool for smalltalk?)

If you don’t have tests you can’t refactor?

  • “Probably safe” refactorings? Interesting route to go? Not a great thing for most people to focus on, requires a lot of expertise
  • For most people you should have tests as well – after all, how do you know whether you’re breaking what’s currently there?

Final takeaway:

  • Small steps, commit frequently.
  • Then you can always roll back.

Greek: Don’t Confuse Genitive Definite Articles with Possessive Pronouns

I got confused after using the word “his” to explain the genitive case of the definite article (here).

It’s especially confusing because the possessive pronoun for 3rd person plural (ie “their”), is the same word (“τους”) as the accusative form of the definite article for male plural (here), but NOT the same as the genitive form of the definite article for male plural (which is “των”).

Anyway, just to note that the definite article and the possessive pronoun are often, but not always, the same.

Full explanation here on the DuoLingo forum.

Basic Rules of Modern Greek – Some, a, the (Cases, definite articles, indefinite articles)

Basic Rules of Modern Greek – Some, a, the (Cases, definite articles, indefinite articles)

I’ve been learning Greek!

This is one in a series of cheatsheets. Full list here.

THE (NOMINATIVE / SUBJECT)

Singular masculine ο ο άντρας = the man
Plural masculine οι οι άντρες = the men
Singular feminine η η γυναίκα = the woman
Plural feminine οι οι γυναίκες = the women
Singular neuter το το παιδί = the child
Plural neuter τα τα παιδιά = the children

 

CASES

Nominative The Subject of the sentence She
Genitive Possessive His
Accusative The Object of the sentence Him
Vocative Calling someone Calling someone

 

A/AN/ONE

MASCULINE FEMININE NEUTER
NOMINATIVE ένας μία or μια ένα
GENITIVE ενός μίας or μιας ενός
ACCUSATIVE ένα or έναν μία or μια ένα

 

THE – CASES

MASCULINE FEMININE NEUTER
Nominative singular ο άντρας = the man η γυναίκα = the woman το παιδί = the child
Genitive singular του άντρα = of the man της γυναίκας = of the woman του παιδιού = of the child
Accusative singular τον άντρα = the man τη γυναίκα = the woman το παιδί = the child
Vocative singular άντρα = man γυναίκα = woman παιδί = child
Nominative Plural οι άντρες = the men οι γυναίκες = the women τα παιδιά = the children
Genitive plural των αντρών = of the men των γυναικών = of the women των παιδιών= of the children
Accusative Plural τους άντρες = the men τις γυναίκες = the women τα παιδιά = the children
Vocative Plural άντρες=men γυναίκες=women παιδιά = children

 

SOME

MASCULINE FEMININE NEUTER
NOMINATIVE μερικοί μερικές μερικά
GENITIVE μερικών μερικών μερικών
ACCUSATIVE μερικούς μερικές μερικά
VOCATIVE μερικοί μερικές μερικά

 

Basic Rules of Modern Greek – Phrases

Basic Rules of Modern Greek – Phrases

I’ve been learning Greek!

This is one in a series of cheatsheets. Full list here.

PHRASES

Καλημέρα Good Morning
Καληνύχτα / Καλό βράδυ Good night
Καλησπέρα Good evening
Όχι No
Ναι Yes
Ευχαριστώ Thanks / Thank you
Παρακαλώ Please / You are welcome
Λυπάμαι I am sorry
Συγνώμη Sorry / Excuse me
Αντίο Goodbye
Σ’ αγαπώ / Σε αγαπώ I love you
Γεια Hi / Hello
Τι κάνεις; How are you? / What are you doing?
Πόσο κάνει; / Πόσο κοστίζει; How much does it cost?
Εγώ είμαι ο / η ….. I am ….
Εγώ ζω (or μένω) στον / στην / στο …. I live in …..

 

Basic Rules of Modern Greek – I (you, she, etc), My (your, her), am, have (Pronouns and auxiliary verbs, conjugation)

Basic Rules of Modern Greek – I (you, she, etc), My (your, her), am, have (Pronouns and auxiliary verbs, conjugation)

I’ve been learning Greek!

This is one in a series of cheatsheets. Full list here.

PRONOUNS

If “they” refers to a group all males or male and female or its gender composition is unknown, αυτοί is used.

Εγώ I
Εσύ you (singular)
Εσείς you (plural)
Εμείς we
Αυτός he
αυτή she
αυτό it
Αυτοί they (male)
αυτές they (female)
αυτά they (neuter)

TO BE

Important note: the pronoun (Εγώ, εσύ) …is not always needed.

Εγώ είμαι I am
Εσύ είσαι you (singular) are
Εσείς είσαστε you (plural) are (or είστε)
Εμείς είμαστε we are
αυτή είναι she is (or he, or it)
αυτές είναι they (female) are

TO HAVE

Singular Plural
First Person I have – έχω (“echo”) we have – έχουμε, έχομε
Second Person you have – έχεις you have – έχετε
Third Person she has – έχει they (f) have – έχουν, έχουνε

First Conjugation Verbs

Many Greek verbs fall into this same pattern for changing their endings (or conjugating.)

We call this group of verbs the first conjugation verbs.

Here are a few more of them, given, as always, in the first person form:

I see βλέπω
I buy αγοράζω
I drink πίνω
I know ξέρω
I take παίρνω
I give δίνω
I eat τρώω

POSSESSIVE PRONOUNS:

Person Pronoun (own one thing) Pronoun (own many things)
1st person singular (Δικός/Δική/Δικό) μου (Δικοί/Δικές/Δικά) μου
2nd person singular (Δικός/Δική/Δικό) σου (Δικοί/Δικές/Δικά) σου
3rd person singular (masculine) (Δικός/Δική/Δικό) του (Δικοί/Δικές/Δικά) του
3rd person singular (feminine) (Δικός/Δική/Δικό) της (Δικοί/Δικές/Δικά) της
3rd person singular (neuter) (Δικός/Δική/Δικό) του (Δικοί/Δικές/Δικά) του
1st person plural (Δικός/Δική/Δικό) μας (Δικοί/Δικές/Δικά) μας
2nd person plural (Δικός/Δική/Δικό) σας (Δικοί/Δικές/Δικά) σας
3rd person plural (Δικός/Δική/Δικό) τους (Δικοί/Δικές/Δικά) τους
(masc/fem/neuter) (masc/fem/neuter)

EXAMPLES:

Ο άντρας μου=My husband 

Ο δικός μου άντρας= My own husband (emphatic).

WHAT’S THE DIFFERENCE BETWEEN Δικός, δική, δικό?

Δικός is used if the owned object is of masculine gender: Ο άντρας είναι δικός μου=The man is mine. 

Δικός becomes δικοί when the owned object of masculine gender is in plural. 

So, οι άντρες είναι δικοί μου=the men are mine.

Δική is used if the owned object is of feminine gender: Η γυναίκα είναι δική μου=The woman is mine. 

Δική becomes δικές when the owned object of feminine gender is in plural. 

So, οι γυναίκες είναι δικές μου=the women are mine.

Δικό is used if the owned object is of neuter gender: Το παιδί είναι δικό μου=The kid is mine. 

Δικό becomes δικά when the owned object of neuter gender is in plural. 

So, τα παιδιά είναι δικά μου=the children are mine.

THE DOUBLE ACCENT RULE

When μου,σου,του,της,μας,σας,τους comes after a word that is accented on the antepenult (second syllable from the end e.g. αυτοκίνητο), then it is accented also on the last syllable.

Example: 

το αυτοκίνητό μου=my car 

το ραδιόφωνό της= her radio 

η τσάντα του=his bag (no double accent here because the word τσάντα is not accented on the antepenult!)

Basic Rules of Modern Greek – The Alphabet

Basic Rules of Modern Greek – The Alphabet

I’ve been learning Greek!

This is one in a series of cheatsheets. Full list here.

Alphabet

Α-α Άλφα Alpha A as in Ant
Β-β Βήτα Veeta V as in Vase
Γ-γ Γάμμα (Γάμα) Gama g as in Good, or y as in Yellow
Δ-δ Δέλτα Delta TH as in THe
Ε-ε Εψίλον Epsilon E as in Element
Ζ-ζ Ζήτα Ζeeta Z as in Zoo
Η-η* Ήτα Eeta EE as in sEE
Θ-θ Θήτα theta th as in Thing
Ι-ι* Ιώτα (γιώτα) Iota EE as in sEE
Κ-κ Κάππα (κάπα) Kapa K as in Kitten
Λ-λ Λάμδα Lambda L as in Lemon
Μ-μ Μυ (μι) Mee M as in Mother
Ν-ν Νυ (Νι) Nee N as in North
Ξ-ξ Ξει (Ξι) Ksee X as in foX
Ο-ο* Όμικρον Omicron O as in Organ
Π-π Πει (Πι) Pee P as in Pet
Ρ-ρ Ρω (ρο) Row R as in Rhapsody
Σ-σ/ς* Σίγμα Sigma S as in Sit
Τ-τ Ταυ Taf T as in Table
Υ-υ* Ύψιλον Ypsilon EE as in sEE
Φ-φ Φει (φι) Fee F as in Fun
Χ-χ Χει (Χι) Chee / Hee H as in Hurry
Ψ-ψ ψει (ψι) Psee PS as in liPStick
Ω-ω* Ωμέγα Omega O as in Organ

 

Η-η, Ι-ι and Υ-υ have the same pronunciation (“ee”)

Ο-ο and Ω-ω have the same pronunciation (“o”)

Sigma has 2 types in lower case: Start of or inside word = σ, but end of word = ς

 

Diphthongs

ΑΙ αι sounds like E-ε, or “eh” as in element
ΕΙ ει sounds like Η-η, Ι-ι, Υ-υ or like ee
ΟΙ οι sounds like Η-η, Ι-ι, Υ-υ or like ee
ΥΙ υι sounds like Η-η, Ι-ι, Υ-υ or like ee
ΑΥ αυ sounds like “av” or “af”
ΕΥ ευ sounds like “ev” or “ef”
ΟΥ ου sounds like “u” as in “soup” .

 

Double consonants

ΜΠ μπ sounds like b
ΝΤ ντ sounds like d
ΓΚ γκ sounds like g
ΓΓ γγ sounds like ng
ΤΣ τσ sounds like ts
ΤΖ τζ sounds like tz

 

Accents

Modern Greek has only ONE accent.

It is placed above the accented vowels, like this: ά, έ, ή, ί, ό, ύ, ώ.

The accent goes on one of the three last syllables.

Accents help you give emphasis to the right syllable.

E.g. “βιβλίο” (veevLEEo), ”μιλώ” (meeLO) etc.

 

Punctuation Marks

The Period, or full stop, the comma and the exclamation mark are the same as English.

The Greek question mark looks just like the English semi colon ;

Basic Rules of Modern Greek

Basic Rules of Modern Greek

I’ve been learning Greek!

I’ve been using DuoLingo, which is great in some ways, but utterly bewildering in others. The app asks you to remember random sentences and words with no apparent attempt to explain any basic grammatical rules or word endings. In fact that info is available on the DuoLingo website, but is still a bit haphazard even there, so I’ve created some cheat sheets with some useful basic rules:

The Alphabet

Some, a, the (Cases, definite articles, indefinite articles)

I (you, she etc) am, have (auxiliary verbs and pronouns, conjugation)

Phrases

Don’t confuse the genitive definite article with the possessive pronoun