Sitemap

Member-only story

Every Junior Android Developer’s Dilemma with Function Design

5 min readOct 11, 2024

--

Junior Developer Priyank, fresh out of coffee and ideas, stares at his code. He’s stuck. His function works fine, but something just doesn’t sit right with him. Should he check for nulls? Should he inline the function? With no answers in sight, he turns to Senior Developer Sarah for wisdom.

// Priyank's Code

class UrlUtils {
companion object {
fun addProductTypeToUrl(productType: String, url: String): String {
if (url.isEmpty() || productType.isEmpty()) return url;

val uri = Uri.parse(url).buildUpon()
.appendQueryParameter("productType", productType)
.build();
return uri;
}

}
}

Here’s a special treat for our non-Medium members: we’re offering free access to this blog! Just follow this link — because your curiosity and passion for coding should never be limited! 😉

Priyank:
“Hey Sarah, got a minute? I’m stuck on something and could use some advice.”

Sarah:
“Of course, Priyank! What’s bugging you?”

Priyank:
“So, I have this function that adds a productType to a URL. It’s being called from only one place, and I’m sure that productType is never going to be null or empty. Should I still check for nulls or empties before proceeding?"

Sarah:
“Ah, the classic ‘should I add a check even if I don’t need it’ dilemma! Let’s break this down, shall we? First of all, are you 100% sure…

--

--

Android Dev Nexus
Android Dev Nexus

Written by Android Dev Nexus

Your friendly neighbourhood developers working at PayPal, turning Android fundamentals into concepts you’ll actually understand. A new post every Tue and Fri.