Eight tips to Write Functions like a Senior Developer

Dhruba Dahal | Software Engineer
3 min readMar 29, 2022

A Function is a small segment of a story telling about a system

Photo by Joan Gamell on Unsplash

According to Robert C. Martin, while writing code we should always think of it as a story telling and our goal should be telling it as beautifully as possible. It makes not only the code readers happy but also helps developers to address the issues like: readable ,less prone to error, easy to change, scalable, testable, fault tolerant etc.

Today, I am going to discuss some of the useful tips that make your functions better in several ways.

1.Do one thing and do it well

Your function should do a single task. But some time while doing a single task we indirectly do other sub tasks also. So the question is are we breaching the rule in that case? The answer might be No if we have maintained the same level of abstraction inside that function.

2.Hide switch statements inside a low level class

Switch statement always does N things and we can not always avoid it. So what we do in that case is that we should hide it somewhere inside the base class or a low level class so we do not have to repeat it. We can achieve it through polymorphism.

3.Keep arguments minimum

--

--