- Developer from Bergen - Work at my own company Nicode - Work on cool and sustainable projects with Ilder
- It's a joke, but also kind of true - I've seen a lot of bad naming through the years - My goal is giving you a framework to improve naming
- We don't prioritize it - We forget that others should understand this - Tests run, compiles, nothing more needs to be done - We forget that code is read more than it's written - It's important that team mates understand each other - A bad name can be the difference between clear and cryptic code
- The code we write describes how it works and what it represents to other humans - Most of us don't think about code as communication, but it really is - The audience is your team, client or all developers in the world - I like to think about code as I think of writing - Take the analogy further, I like to cook and I like to write a cookbook
- My first version - I understand everything, I wrote it! - My editor don't understand anything - What are we making?
- I added a title - Everything should be clear now - As a programmer I like the short names, it's efficient - Editor still isn't happy - Don't expect your readers to decode the ingredient list - Ingredient names must be specific
- Now things are super specific - Scientific names all over the place - My editor is frustrated. - Readers heads will explode reading this
- Perfect - Now everything makes sense, easy to read and comprehend - Editor is happy - I've written a recipe for a target audience
- Context is like the title of the recipe - Gives the reader a mental model to understand the text/code - Stronger context is more understandable. - Stronger context let's you have short and consice names - Datamodel Car, have a property Engine - Car is the context engine lives in - If Engine was outside the context it would have to be more verbose - Car engine
- The function name New in package user makes total sense - It's short and clear because it delivers a user and lives in the user package - New in package utils doesn't make sense. - What do it do? What's a util?
- These are all different verbosity levels of the same concept - The context decides the level of verbosity - One letter variables is fine, as long as the context allow it
- Write code for an audience - How will they read and interpret the code? - Code will never be perfect in the first try - See your code from an outside perspective - Iterations, restructuring and renaming will improve the code. - How does it fit in the bigger story == codebase ?