Hate your job? Happier times are within your grasp


As is common this time of year, I took some time to reflect on life and work. And a few different things reminded me of how incredibly fortunate and happy I am to be working at Basecamp.

But I bet you can guess the punchline — yeah, it wasn’t always like this. The year before I landed at Basecamp, things were pretty rough and I was miserable at work.

I know this feeling isn’t unique. In fact you might be feeling today how I did years ago — coming home from work tired, uninspired, unhappy, and even angry. It’s not a good look.

But change is within your grasp. It won’t be easy, but you can be damn sure it’ll be worth it. I speak from personal experience.


When I eventually reached my job-hate breaking point, the first order of business was to quit said job. I have to admit it was kind of exciting and liberating. But it was also intensely scary.

I was walking away from a good job working at a stable, respected company — a company where I could’ve had a prosperous (albeit miserable) career. I voluntarily went from having a very generous salary to one of literally $0.

Oh and by the way, as I took on this adventure of rebuilding my career I still had some huge responsibilities back at home: namely my twin infant sons and all the adulting required to keep them happy and healthy.

So you can imagine the unsettling feeling of self doubt I felt early on. More than once I wondered, “Did I make a huge mistake??”

But ultimately I realized what scared me the most was the long-term prospects of doing nothing — not just being unhappy for one year, but allowing that misery to fester over three, five or even ten years.

We spend an inordinate amount of our life at work — somewhere between 20–30% of our waking hours. How could I standby and let all those hours be filled with misery, only to bring that misery home with me every day to my family? No, if I was going to spend that much of my life doing something, those hours better be happy ones.

So I pushed aside that doubt, put my head down and got to work. I joined The Starter League and got my brain and attitude in the right space. I was learning tons and meeting great people. I felt professionally energized and excited for the first time in a long time.

I finished up my classes there and soon after I mustered up all my courage and took a long shot: I reached out to Jason Fried to ask if there was anything I could help with. We got to talking, and a few months later he invited me to join 37signals.

What an unbelievable turn of events. Going from the the worst job I’d ever had to working at my dream company wasn’t anything I’d ever expected. Fast forward 4+ years and I’m doing the best work of my career and I’ve never been happier at a job.

Now look, I’m not recounting this story as some kind of humble brag or to make myself look like hot shit. Anybody who knows me I am the furthest thing from hot shit. I’m ice cold shit.

I bring it up because I hope it shows the kinds of crazy, unexpected, wonderful things that can happen to anyone’s career if you take a chance.

I’m not special — all I did was acknowledge my unhappiness, embrace the uneasiness of change, and got to work. Yes, there was some luck involved, but even if I landed somewhere other than Basecamp, I still would’ve been happier and better off for having tried.


Of course it’s really important to remember that everyone’s situation is different, so don’t take my story as gospel.

I was fortunate to be in a position to take a chance like I did. I had years of work experience to help me recognize when to get out of an ugly situation. We were financially secure — it was a moderate risk, but I never put ourselves in any kind of precarious lose-it-all situation. And most importantly I had wonderful, incredibly supportive people around me — family, friends, teachers, colleagues, and so many others. I recognize not everyone gets the deck stacked in their favor like this.

It’s also worth noting that life wasn’t all roses and sunshine afterwards either. It took a long while to get everything back up to speed — to rebuild our finances, to re-establish my career direction, and even smooth out our family life and routine.

But in the end was it worth it? Absolutely, positively, hell yes.

If you hate your job, I’d really encourage you to consider taking action. But first you’ll need to evaluate your career situation, then decide what’s best for you and your family, now and in the future. It’s natural (and healthy) to feel scared, worried, and hesitant. Take your time, consider deeply, and take action when it’s right for you.

But no matter what your situation is, if you’re in a rough patch in your career I hope that my story gives you a spark of hope, something you can hang onto — the belief that better times await you when you’re ready.

There’s something great out there for you and your career. You absolutely deserve the happiness it can bring — go on and get it. 🤜🤛


If you enjoyed this post, please do hit the 👏 button. Thanks!

Programming languages aren’t a zero sum game


Stop me if you’ve heard these before when people get to talking about programming languages…

“These features are copied this from <superior language>.”

“Nothing new here. <superior language> has done this for years.”

“This language has nothing on <superior language>, but nobody realizes it.”

<superior language> does the same thing, but better.”

I bring it up because I’ve been reading and writing a lot about Kotlin lately. And invariably someone posts a snarky comment like one those above, carrying with it a clear innuendo: my preferred programming language is better than yours.

And every time I see those I leave with the same reaction. Who gives a shit?

Now I’m not talking about people who are having constructive conversations or even just poking fun. Hell, I may have been known to take a jab at Java every once in a while. 👊

I’m talking about a subset of programmers who treat languages like it’s a zero sum game — that for one language to succeed, another (or all others) must fail. It’s like they’re on some strange crusade to prove how they were first and best at everything.

But why does it matter if a language takes the best ideas from another language and implements them? Why does it matter if another language had some feature for years and your favorite just got it? What the hell does “better” even mean when everyone has different preferences and styles?

To me programming languages are simply about doing good work, building success, and if you’re lucky, finding happiness. Many people have achieved those with Ruby, Swift, Javascript, Java, C#, Python, Go, and dozens of other languages.

I’ve been lucky enough to find that with Kotlin. It makes my work genuinely enjoyable. I find it fun and exciting to work with, and that makes me happy. But I’m no programming linguist — for all I know, every other programming language is technically “superior” to Kotlin.

But who cares? There can be many different languages that make many different people happy in many different ways. If I’m happy and having fun with a language, why do others feel the need to shit on it? Are we so insecure and unhappy that we need to tear down another language to make our favorite look better? It’s a negative, petty stance to take that has a disheartening effect on others.

Just because a language doesn’t do something brand new conceptually doesn’t mean it shouldn’t exist. If a language takes ideas and inspiration from another language, that’s a wonderful compliment to the earlier architects. And if your favorite language is “better” than mine, believe it or not, I’m super happy for you — it’s awesome that you’ve found something great!

Programming can be hard. Finding joy in work can be hard. If people can achieve success and find joy in any programming language, that’s a wonderful thing. Why not celebrate every language that can help people achieve great things (especially their own happiness!) instead of making everything a showdown?

If you really believe in your favorite programming language, focus on its merits, not the demerits of others. Avoid the temptation to make snarky comments or tear down another language. Instead, keep it positive. Spread the word on why your language is awesome. Compare and contrast fairly. Have strong opinions and challenge each other respectfully.

Trust me, there’s plenty of room for all our favorite programming languages — even Java. 😜


If this article was helpful to you, please do hit the 💚 button below. Thanks!

We’re hard at work making the Basecamp 3 Android app better every day (in Kotlin, of course). Please check it out!

Kotlin makes me a happier (better) programmer

What’s Kotlin’s best feature? Creating programmer happiness.


There’s been a lot of action around Kotlin lately. So one question you’ll often hear is “What’s your favorite Kotlin feature?”

And while there are many wonderful things about the language, for me it isn’t about any single technical feature.

My answer? It makes me happy.

Writing code that’s concise, clear, and expressive makes me happy. Focusing on creative solutions to business problems, not boilerplate and ceremony, makes me happy. Feeling an intense motivation to learn, which was missing in the Java days, makes me happy.

And that’s super important. Because being happy isn’t just good for the soul. It’s great for your programming skills too.

As DHH astutely pointed out many years ago in Getting Real:

Would you truly be happy working in this environment eight hours a day? This is especially important for choosing a programming language.

Happiness has a cascading effect. Happy programmers do the right thing. They write simple, readable code. They take clean, expressive, readable, elegant approaches. They have fun.

Imagine extrapolating that feeling over an extended period of time.

The more capable and friendly your language is, the happier you are. The happier you are, the better code choices you make. The better code choices you make, the better habits you build. And the better habits you build, the better programmer you become!

This is exactly what’s happened with Kotlin and me over the past year. And I’m a better programmer because of it.

DHH continues:

We found programming bliss in the language Ruby and passed it on to other developers with our framework Rails. Both share a mission statement to optimize for humans and their happiness.

In summary, your team needs to work with tools they love. Choose the fuse that gets people excited. You’ll generate excitement and motivation and a better product as a result.

This is absolutely true for Kotlin— it fits my brain and optimizes for my happiness. Working with it is just flat out fun, exciting, and motivating. It makes the quality of my work better and it makes me better.

I’ve never been a happier (or better) programmer. 😍


If this article was helpful to you, please do hit the 💚 button below. Thanks!

And if you’ve caught the Kotlin bug, you might like our other posts:

Getting real with difficult emotions at work

Photo by Michael Keen /creative commons— Art by Banksy

“Happiness” — it’s a coveted and much celebrated state of being. A lot of companies advocate for the power of positivity to create a company culture and environment where people can thrive and “be happy.” The belief is that encouraging positivity while discouraging negativity will cultivate an environment that is positive. Negativity = bad/sad and positivity = good/happy — right?

It’s not that simple, though.

The positivity myth

It’s an idea that has good intentions on the surface — research suggests that working in positive environments can bring about more productivity, harmony and certainly, happiness — but when positivity is forced or mandated, a culture built upon real, authentic happiness is not likely to be cultivated. Maria Konnikova’s piece in the New Yorker “What Makes People Feel Upbeat at Work” discusses forced positivity in the workplace:

“Alicia Grandey (an organizational psychologist at Penn State who studies emotional labor) cautions that it is incredibly difficult to impose positivity from the top and actually exert a positive effect. ‘When anything feels forced or externally controlled, it doesn’t tend to be as beneficial as when it’s coming from the self,’ she said. ‘The irony is, when you’re trying to get people to do something positive, you can’t do it. Once it’s required, it’s fake and forced.’ What you create instead is a negative backlash. ‘It feels like Big Brother.’”

Making room for constructive negativity

Requiring or forcing positivity in the workplace flips its intention. It can be silencing as well. When positivity is the only option, there’s not space to experience the breadth of human emotions that come into play day in and day out (yes, even at work — we don’t stop being humans with complex emotional needs from 9am-5pm).

The absence of this space can lead to the bottling and suppression of all those other emotions that are not seen as ‘positive’. Bottling emotions can lead to emotional leakage, outbursts, breakdowns and it might even make you sick. Suppression can facilitate a general state of being out of touch with one’s feelings. The School of Life touches on this below:

I’m not arguing that genuine positivity is a bad thing — nor do I think it’s constructive to enable brooding, downtrodden or negative behavior constantly or to share all feelings at work — but when positivity is the only option, there’s not a space for constructive negativity. Yep, I said constructive negativity. Susan David discusses this in her book Emotional Agility:

“Trying to impose happy thoughts is extremely difficult, if not impossible, because few people can just turn off negative thoughts and replace them with more pleasant ones. Also, this advice fails to consider an essential truth: Your so called ‘negative’ emotions are actually working in your favor. In fact, negativity is normal. This is a fundamental fact. We are wired to feel ‘negative’ at times. It’s simply part of the human condition. Too much stress on being positive is just one more way our culture figuratively overmedicates the normal fluctuations of our emotions.”

Constructive negativity is born from sadness, fear, disgust, anger and all those other difficult emotions. These ‘negative’ emotions are just as important and normal to feel as happiness and joy — so called ‘positive’ emotions. Comedian Louis C.K. talks about embracing those uncomfortable feelings below:

https://www.youtube.com/watch?v=ZhtI-_NNXy8

Using negativity in a constructive way involves processing uncomfortable feelings and emotions. A process that can include acknowledging and naming the emotions you are feeling, accepting that they are present and part of this ‘being a human’ thing, learning from them, then putting them to the side and moving forward.


So, what does constructive negativity look like at work? It can take many forms and can be personal or shared, but here are some examples:

Acknowledging and processing ‘negative’ emotions: This can be personal or shared (with a trusted colleague or friend) and it’s a good place to start, because it’s a process you can dictate, direct and control. Brené Brown (a researcher, storyteller and expert on vulnerability) offers these tips to reckon with uncomfortable feelings. This involves engaging with your feelings, acknowledging them and accepting them. Ultimately, it’s up to you to figure out the best way to process through difficult emotions — you can choose the speed, the method and if you want to keep it to yourself or share the process.

Using negative emotions to bring about more clarity and strengthen relationships: This is shared and involves another person, so it can be a bit scary to work through at first. It’s examining ‘negative’ emotions and then using them to clarify misunderstandings/miscommunications and strengthen interpersonal relationships. For example, if your boss keeps emailing you during your off hours or scheduling meetings that you are expected to attend on your day off — you might assume that’s because they don’t respect your time. This can lead to resentment, stress or anger. That might not be their intention, though. They might just be disorganized and unaware of your work hours/day or think you are totally fine working on your time off.

Instead of making up a story by filling in the blank space between what your boss might mean (the story you make up) and how that makes you feel (your feelings) — speaking to them directly about how their actions affect you and make you feel, will give the other person in the situation the chance to tell their side of the story. It could be that they do expect you to be available all the time, they don’t respect your time or they might not be open to talking it through at all. At the very least you will have more clarity surrounding a situation than you started with and you can make more informed decisions about how to proceed.

Embracing constructive criticism and feedback to open communication channels: Making space for and embracing constructive criticism and feedback involves turning this sometimes uncomfortable activity into something more normalized. Then, using these opportunities to make changes and improvements — if possible — but more simply, allowing for the sharing of dissenting viewpoints, perspectives and opening communication channels where they might not have been before.

Leaders can take the reins and lead by example here — opening up communication channels by encouraging and embracing feedback and constructive criticism, being transparent about issues a team is facing (positive as well as negative), tweaking or being aware of their mindset surrounding employee feedback/criticism and the intent behind why an employee is speaking up about something — constructive negativity usually has a positive intent and is not meant to be an attack against leadership.

Being human

Constructive negativity is not complaining, yelling, punching a wall, venting by ranting to a colleague or engaging in ‘brooding’ behavior — becoming closely attached to the feelings that are being felt, thinking you ‘are’ the feelings you feel and holding onto them tightly. For example, brooding thoughts sound a bit like this:

  • “When I share my dissenting viewpoint, I’m immediately shut down. I’m not going to voice my opinions and needs any longer, because they don’t matter and no one listens to me anyways. I’m resentful about this now and I’m going to stay resentful and show how resentful I am.”
  • “I’m not good at support, because I get upset and feel apathetic towards customers sometimes. I’m not good with people and I don’t see a way to change how I feel. I’m going to be passive aggressive and negative about this to show how upset I am when I’m asked to help with support or speak with a customer.”
  • “This is terrible — it will never get any better. I don’t see any solutions down the line for this problem. We are doomed!!!”

These are exaggerated examples, but you get the point. Brooding behavior does not just affect the person exhibiting it — it’s contagious. If a colleague is displaying signs of intense stress, anger or any other destructively negative thoughts/actions (without trying to work through them), you can inhale those dark feelings like second hand smoke. Sherrie Bourg Carter Psy.D. wrote about this in her Psychology Today article entitled Emotions Are Contagious — Choose Your Company Wisely”:

“Just as second-hand smoke can have the same or worse effects on the health of nonsmokers, second-hand emotions (*the destructively negative kind) can have significant, long-lasting effects on the health and well being of those experiencing them. The negativity keeps pounding away at you and ultimately results in significant second-hand stress, which as you might expect, has the same effects on your mind and body as direct stress. The body experiences and interprets it as one in the same.”

Awareness surrounding how constant destructive negativity affects others as well as yourself, could be effective motivation to encourage positive change — by flipping the script and using those negative feelings in a constructive way. Although, it’s OK to feel this way and react in ways that are not constructive at work sometimes — we are all human. No one is perfect. Working through emotional pitfalls, examining feelings and learning how to process emotions in a way that works for you as an individual is not easy. It’s hard and it is a process, after all!

*It’s important to note — if you are feeling incredibly stuck — like there’s no way out of those dark thoughts and feelings, you feel like you are drowning in them, anxiety has taken over your life or you are exhibiting signs of depression — it might be time to ask for help. Here’s how you can find it.*

Getting real

The next time negative emotions pop up at work, I want to suggest getting real with them— instead of pushing them aside or covering them up with metaphorical or literal smiley face emojis.

Again, from Susan David:

“Once we stop struggling to eliminate distressing feelings, or to smother them with positive affirmations or rationalizations, they can teach us valuable lessons.”

Examining and processing through negative emotions can lead to more opportunities for:

Hope in a situation where there was none seen: Instead of jumping to conclusions, feeling hopeless or quitting when something gets hard— examining and naming the distressing emotions that are being felt can create hope that there’s space for change or development. There’s an opportunity to use those negative feelings to figure out solutions to problems you are faced with — sparking curiosity surrounding your work and opening up space to job craft. You might also find this space does not exist at your current place of employment (and quitting might be the best option), but the addition of hope helps to expand viewpoints that were once more narrow.

Strengthened communication channels and increased trust within a team or company: Cultivating space where it’s possible to be heard and to listen to dissenting views can lead to more strengthened and open communication channels. Once you know you won’t face dire consequences for really talking through hard issues, giving/receiving tough feedback, sharing dissenting viewpoints and giving/receiving constructive criticism — trust within a team also grows.

Increased feeling of ‘belonging’ vs ‘fitting in’: When you don’t need to mute yourself, hold your ideas back or ‘fake it’ to fit in, increased trust that ‘being yourself as you are’ in a company culture, builds and this can lead to a more solidified sense of belonging.

And, yes…it can also lead to more overall happiness at work. So, don’t force that frown upside down — instead, start small by first acknowledging those difficult emotions when they pop up — then, you can experiment with processing through them and see how that makes you feel — you might be pleasantly (but, not too pleasantly 😀) surprised!


If you are interested in learning more about emotional agility & how to process through negative emotions which is something I did not touch upon too much above, check out Susan David’s book Emotional Agility here — for a brief version, her popular Harvard Business Review article on the same topic is here.

If you liked this post, please hit the ❤️ button below & feel free to connect with me on Twitter here.

I went on vacation and a funny thing happened — I didn’t do any work

Many vacations are broken, filled with the stress of work. Help me bring back the work-free vacation.

My family and I just returned from a 12 day vacation to the San Diego area, where my brother, mom, and dad all live.

We had a wonderful time. We did all the typical vacation stuff — Legoland, beaches, pizza, beer, excessive ice cream eating — and my kids got to spend a bunch of time with their grandparents and uncle. 😍




What made this vacation truly wonderful wasn’t just the fun activities and family, but that I got to enjoy every second of it without a single bit of stress from work.

Work was the furthest thing from my mind. I was focused solely on relaxing, recharging, and spending time with my family.


The sad state of today’s “vacations”

You might be thinking — what’s so special about that? After all, vacation is a time when people unplug from work, relieve stress, and let go of all their worries, right?

Sadly — no, not really.

Search Google for “people working on vacation” and a disturbing amount of negative results come up — a worrying trend of unused vacation days, people who constantly work on vacation, and even life hacks on how to do work while on vacation. ☹️

The American “vacation” in today’s work environment is in pretty bad shape. How bad?

U.S. respondents receive less paid vacation time than any of the countries surveyed — 18 days in the U.S., compared to the average of 24.

— TripAdvisor

They found that among employees with access to paid time off, nearly five days went unused in 2013, and 1.6 of those days did not carry over to the next year. That totals to 169 million days of lost vacation time for Americans

Time

Fears of keeping your job, being passed over for promotions or lead projects, coming back to a staggering pile of work, or feeling like you’re the only one who can do your job all push Americans to stay at the office…

Money

This trend was strongest among millennials: 35 percent said they worked each day while on vacation, and 21 percent said they returned to work less productive.

Money

Not that this is always voluntary. … 24% say they were contacted by a colleague on a work issue, 20% by a boss. And while 20% gave up part of their time off because they were in pursuit of a promotion, nearly the same number (17%) stayed connected because they feared for their jobs.

Money

So, to recap:

  • We get fewer days off than many other countries
  • Even though we get fewer days off, we still don’t use them all
  • When we do use them, we’re so worried about the remote possibility of getting fired or missing out on a promotion, that we just keep on working anyway
  • And even if we get past all that, the jerks at our office contact us about work while we’re on vacation

Wow, American vacations sound fucking horrible!


Take control of your vacation

While these statistics are damning, we’re all adults here. Much of this is under your control, so it’s up to you to take action.

First and foremost, use your vacation days — all of them. Sounds obvious, but this should not be difficult. I don’t care how much your love your job. Find a way to use them. You’ve earned them and they’re part of your overall compensation, and you’re flushing money down the toilet if you don’t.

And when you do take those hard-earned vacation days, you need to turn on your internal work can wait mode for the entirety of your vacation by…

  • Recognizing that dedicated time away from work is actually what makes you more productive. Working on vacation (including compulsively checking your email and other work apps) might feel productive, but you’re only sapping your long-term strength.
  • Letting go of the idea that you have to know everything that’s going on. If you’re at a moderately sized company, there’s always going to be a lot going on — far more than you can keep a pulse on. Relieve yourself of the idea that missing out is a bad thing and not only will your vacation be more pleasant, you’ll be more focused when you return to work.
  • Being realistic about your status. Think about it — your huge promotion isn’t going to magically disappear while you’re on vacation. I guarantee if you’re in the running for a promotion before your vacation, you’ll still be in the running when you return. And if it’s not, you’re working for a ridiculously bad company.
  • Stop thinking that you’re a special snowflake — that you’re the only one who can do a certain job, and that the company will come crashing down without you. It’s just not true, and once you realize this, you’ll feel liberated and everything will be just fine while you’re gone.
  • Planning. Don’t leave your coworkers and your company in the lurch. A tiny bit of setup not only makes everyone around you comfortable, you’ll be able to mentally check out knowing you’ve done your due diligence.

Sadly, there’s one thing that is kind out of your control. And of all the stats I read through, this one bothers me the most:

24% say they were contacted by a colleague on a work issue, 20% by a boss. — Money

Holy shit! Who are these sadists that contact coworkers when they know full well they’re on vacation?!

Look, I’m sure there are very rare cases where someone’s life is literally on the line and you need to be contacted. And if you’re the brainiac who left a bunch of half finished work right before a deadline, you deserve to be bothered during vacation.

But more likely this is a sign of blatant disrespect by the person making the call. So let’s just be crystal clear: if your coworker is on vacation, leave them alone. Deal with it. 😎


Building companies that respect vacations

Beyond what each individual can do to make their vacations work-free, it’s important for business owners and CEOs to encourage that behavior and weave it into the company’s culture.

Why should work-free vacations be a priority for businesses? Speaking from experience, when I come back from a work-free vacation, I’m…

  • Refreshed and mentally sharp. Vacations have a way of clearing big piles of junk out of my brain. When I come back to work, I just feel sharper and think more clearly. Everything that seemed like a hard problem before vacation looks way easier when I return. (Good sleep has a similar effect, though on a much smaller scale).
  • Motivated and excited. I’m absolutely raring to go when I come back to work. Not programming or building for a couple weeks really ignites a fire in me and I apply that to my work. And I really look forward to catching up with my friends and colleagues.
  • Appreciative and grateful. When my time away from work is respected, it makes me appreciate the company that I work for. I’m grateful for all my coworkers that covered my work while I was gone. That appreciation ultimately turns into me putting my best effort into all of my work.
  • Happy. Sounds obvious and maybe a little corny, but of course I’m happy coming off a vacation. I’ve built memories with my family and enjoyed something new and special away from work. Happiness means good vibes in my work!

As a business owner, imagine multiplying those feelings across all your employees throughout the year. I bet you’ll have one hell of a productive workforce. 📈

We can’t fix the entire vacation epidemic across the country, but we can try to fix what’s within our sphere of influence. Both as individuals and as companies, let’s do our part by insisting our vacations be work-free.

We spend literally thousands of hours at work each year — let’s make those few hundred hours away from work really count! 🤘


When we’re not on work-free vacations, we’re working really hard to make Basecamp 3 as great as it can be. Check it out!

If this was helpful to you, please do hit the heart button below or let me know on Twitter. Thanks for reading!

Some of my favorite Kotlin features (that we use a lot in Basecamp)


Team Android at Basecamp recently passed a fairly big milestone — over 25% of the Basecamp 3 Android app code base now runs on Kotlin! 🎉

Github statistics for the Basecamp 3 Android app as of 5/27/16.

We’ve found that Kotlin not only makes our code much better, but massively increases programmer happiness. All of this ensures we’re making the best app we can for the tens of thousands of Android users we support.

Given our new experiences with the language, I thought it’d be worth sharing some specifics that make the language so wonderful to work with.


Unlike most articles that introduce you to a language, I’m going to avoid using too much programming lingo. Instead, I’ll try using plain English in the hopes that it’s more accessible to beginners. 🤗

Some notes about the code examples:

  • I am by no stretch an expert in Kotlin. Read, consider, and discuss!
  • They look better on a desktop browser. You can get by on the mobile app in landscape mode, but I’d recommend breaking out your laptop to read them.
  • They’re brief and simple on purpose. Long-winded examples tend to cause confusion. Take these simple examples and extrapolate them into your own potential uses, and you’ll see a lot more power.

Let’s get started with seven of my current favorites!


1. Replacing simple if/else if/else blocks with when

One of my absolute favorites.

// Java
if (firstName.equals("Dan")) {
person.setTeam(programmers);
} else if (lastName.equals("Dihiansan")) {
person.setTeam(designers);
} else {
person.setTeam(others);
}
// Kotlin
when {
firstName == "Dan" -> person.team = programmers
lastName == "Dihiansan" -> person.team = designers
else -> person.team = others
}

when blocks are effectively the same as a simple if block, but look how much more readable that is!

There’s a similar convention when only one argument is being checked. Typically this would be a long, ugly switch/case statement in Java.

// Java
switch (firstName) {
case "Dan": person.setTeam(programmers)
break;
case "Jay": person.setTeam(programmers)
break;
case "Jamie": person.setTeam(designers)
break;
default:
person.setTeam(others)
}
// Kotlin
when (firstName) {
"Dan", "Jay" -> person.team = programmers
"Jamie" -> person.team = designers
else -> person.team = others
}

I swear, this alone is worth writing Kotlin.

2. Beautifying even the ugliest click handlers

Using Anko, a library built for Kotlin, click listeners are ridiculously easy.

I hate writing these in Java so much that I could barely bring myself to write an example here. But I soldiered on. 😭

// Java
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("This is horrible");
}
});
// Kotlin
view.onClick {
println("WAT")
}

3. No more view binding

By using the Kotlin Android Extensions, you no longer need to bind views to objects to start working with them. You can access them directly without any binding. Zero. None.

// Java
EditText composer = findViewById(R.id.composer);
composer.setText("Allo!");
// Kotlin 
view.composer.text = "Allo!"

That might not look like a big deal in isolation, but think about how much of your Activity/Controller code is the ceremony of binding a view to an object before you can start to work with that object. Kotlin bypasses all of that.

4. Functions in one line

One line functions can technically be written in Java, but you’d be going against generally accepted styles.

Kotlin’s inherent brevity makes one-liners (officially called single-expression functions) quite common, and they look great. No extra lines and no braces required.

// Java
public String fullName() {
return getFirstName() + " " + getLastName();
}
// Kotlin
fun fullName() = "${firstName} ${lastName}"

Bonus: the return object type is implied, so Kotlin will automatically know the method is returning a String without ever having to write “String” anywhere.

You may have also noticed in this example 1) no need for public and 2) string interpolation.

5. Convenience methods built on top of familiar objects

Kotlin has extended objects you’re familiar with and made them even better and packaged them into the Kotlin Standard Library.

Take String comparisons for example:

// Java
if (name.toLowerCase().contains(firstName.toLowerCase())) {
...
}
// Kotlin
if (name.contains(firstName, true)) { ... }

Not a huge difference, but enough to improve readability in many places. The standard library has tons of these kinds of tweaks. Perfect!

6. Reducing the need for`if (whatever != null)`

Null checking is so painfully common in Java that `if (whatever != null)` is probably in your recurring nightmares.

Kotlin has a number of impressive null safety features built in, and let is just one of those ways to achieve more readable code.

// Java
if (message != null) {
System.out.println(message)
}
// Kotlin
message?.let { println(it) }

Here if message is not null, Kotlin will let the block (what’s inside the braces) run. If it’s null, it just skips it.

There’s one other bit of awesomeness — notice the println(it) statement? The it keyword allows you to reference the object the let began from.

7. The Elvis operator

I mostly love this operator because of its name. It looks like this:

?: // Turn your head to the left, you may see someone familiar

Fun name aside, the real reason this is great is because it handles the common scenario of “if something is null, I want to give it a value, but otherwise just leave it alone”.

// Java
if (people == null) {
people = new ArrayList();
}
return people;
// Kotlin
return people ?: emptyArrayList()

Here if people isn’t null, it returns. If it is, it returns whatever is to the right of the Elvis operator.


So that’s just a brief look at some things that make my life better every day working with Kotlin.

If you’re interested in getting started with Kotlin, their documentation is very good, and you can poke around the interactive Kotlin Koans. I tend to struggle with things like koans (feels too much like school work!), so if you’re like me, I’d encourage you to try building something real.


We’re working really hard to make the all-new Basecamp 3 and its companion Android app as great as they can be. Check ’em out!

If this was helpful to you, please do hit the heart button below or let me know on Twitter and we’ll keep adding to this Kotlin series.