DEV Community

Cover image for How to Produce Readable Code

How to Produce Readable Code

Jaff Parker on June 17, 2019

This is the first installment in a series of articles of indefinite length. Throughout the years of working in various teams and building one, I h...
Collapse
 
vlasales profile image
Vlastimil Pospichal • Edited

actions on objects: user.get(), user.add(), post.modify(), post.delete()

user = new User(id)
print database.get(user)

posts = new Posts()
print database.get(posts)

post = new Post(data)
database.update(post)
Collapse
 
jaffparker profile image
Jaff Parker

Yeah, that works too! I prefer a more functional approach though, that's pretty much what I described :) this is more OOP.

But as long as you and any person who hasn't seen your code can read it, anything works!

Collapse
 
metalrain profile image
Otto Martikainen

I agree about use of English and naming things clearly, but having function that gets all posts just to filter one by author and modify it's title seems quite inefficient.

Also in last example variable posts is not actually defined and example before that posts is a function so posts.filter is also undefined.

I'm trying to say that details do matter in code.

Collapse
 
jaffparker profile image
Jaff Parker

Oops, thanks for pointing that out, I fixed it :) I'm used to the editor showing me wrong references.

This example isn't real and was just written for demonstration of all principles mentioned. If it were a post about efficient code, I definitely wouldn't have done that 😃

Collapse
 
nikolicstjepan profile image
Nikolić Stjepan

Thanks for the useful tips and easy to understand examples. :)

Collapse
 
gabrielfellone profile image
Gabriel Fellone

Great post, Jaff
Thanks! :)