I could never understand why people keep asking me this one stupid question. A question with an answer so obvious it made no sense why everyone kept asking. EVERYONE.
"Hey Swiz, how do I structure my project?"
"Hey Swiz, where do I put this code?"
"Hey Swiz, do I use folders or not?"
"Hey Swiz, how many components in a file?"
"Hey Swiz, where do I put my styled components?"
It. Doesn't. Matter. Put your stuff wherever! When it feels untidy, tidy it up.
I keep structure flat for small projects. When projects get big I group things in folders. Stuff that works together goes together.
But I get it now, I get it
But I get it now. I understand why everyone asks this.
Last week I inherited a Kotlin project at dayjob.exe. I knew it was coming, I just didn't prepare :P
Kotlin, by the way, is a programming language that compiles to Java bytecode. Runs on the JVM. Often used for Android development, we're trying it for AWS Lambdas.
Got tired of Ruby and its loose approach to types, don't want to write raw Java because it's meh, consider Scala to be too much of a mess. That leaves Kotlin.
NodeJS with JavaScript or TypeScript got disqualified I'm not sure why. Python too.
¯\_(ツ)_/¯
The time has come for me to learn Kotlin. Because reasons
— Swizec Teller (@Swizec) March 5, 2019
First surprise: It takes 700MB of space just to install the language. No IDE or anything.
node_modules ain't got nothing on this
So here I am trying to learn Kotlin
So here I am trying to learn Kotlin and ... ho boy it's been rough. Took me two days just to get my code to run locally.
Being in a Lambda environment doesn't help.
You install Kotlin and set up VSCode with Kotlin support. I tried IntelliJ's IDEA environment. Hated how it looks, hated how clunky it felt, didn't wanna use it.
I'm told using VSCode will punish me in the future. It's already missing the jump-to-definition stuff it can do in JavaScript and even Ruby.
Statically typed languages like Kotlin and Java are supposed to make that feature easier to implement ... ¯\_(ツ)_/¯
Syntax highlighting doesn't work great either. Oh well.
Ok so I get that set up and after a painful run at installing Java I can run small examples right in my editor. Wonderful!
O oh ... pic.twitter.com/nXGppnelUK
— Swizec Teller (@Swizec) March 5, 2019
Ah yes. The popup modal links you to the wrong thing, you need JDK, not JRE, whatever that is. How absolutely obvious why didn't I think of that
— Swizec Teller (@Swizec) March 5, 2019
Thanks StackOverflowhttps://t.co/yZ4Q1XSP2m
How was I supposed to know the popup gives you the wrong thing?
Blogs and articles about Kotlin don't tell you this because they all assume you're coming from a Java background and have everything running. Not me :D
And then it gets worse
Then my instructions, from the lady who started this project, say that I have to run ./gradlew
. Gradle is some sort of better compiler for Kotlin. Using kotlinc
directly is too hard?
Gradle itself also isn't good enough so everyone uses gradle wrapper called gradlew
.
It's a bit like having npm
. You specify dependencies and stuff in a build.gradle
, which is written in Groovy, and when you run ./gradlew
it installs dependencies then compiles your code.
Oh except running gradlew
doesn't work because it needs a .jar
file that is supposed to be part of your repository. But .jar
files are in .gitignore
because obviously you don't want compiled files in your git.
Jar files are the compiled result of Java programs. It's like a package with compiled code and some other stuff.
I forget what I had to run, but I had to compile my compile tool before I could compile my code.
And then I learned about something called SAM – Serverless Application Model. It's an Amazon tool that lets you run cloud functions locally.
Except it didn't work.
Complained about Docker. Don't need to set up Docker, just have it on my computer. SAM uses that to simulate lambdas ... I think.
Then SAM complained about my AWS configuration. Not that it told me this, Twitter told me this after seeing my error screenshot.
AWS uses local config files in ~/.aws
to get your AWS credentials and stuff. I set those up as per my predecessor's instructions. Didn't work.
Googled around and I needed some sort of awscli
that has a configure
command. Used two different ways to install, both succeeded, neither worked.
Trying to install the aws cli so I can properly configure stuff. Thanks @NejcRavnik for the idea
— Swizec Teller (@Swizec) March 7, 2019
Tried 2 ways to install: running a bash command and with pip3
Both succeed.
Neither installs aws-cli. It's literally not in the only Python path I have on my computer pic.twitter.com/m7QC2vrLON
Rebooting my computer made it work. No idea why. Yes I tried restarting terminal to pick up new binaries.
By now it's been two days and learning Kotlin feels a lot like running through a brick wall.
But I could run my code locally 💪
IT LIVES pic.twitter.com/xFa2ZWjPJs
— Swizec Teller (@Swizec) March 7, 2019
And then ... I didn't know where to put my code 🙈
I could run my code, I could deploy my code, I couldn't run my code in production because some Lambda wasn't giving permissions to another Lambda and it breaks.
So I figured I'd start with unit tests.
My predecessor didn't set that up and you want your backend code thoroughly tested. Manual QA only goes so far.
I searched the internets. My results were bad.
Training Google to give good results is a big part of learning a new language or technology. Takes a while. Takes a while to learn what to search for too. All the key phrases, technology names, the good websites ...
Learning completely new tech is an eye opening experience.
— Swizec Teller (@Swizec) March 9, 2019
I know everything about Kotlin unit testing. I know what the good libraries are, I know how to write tests in the one I picked, I even know how to configure them.
But I don't know where to put files or how to run them.
After much reading and investigating I learned of a thing called KotlinTest. It's a powerful framework for testing Kotlin that supports many different styles.
One of them looks like Ruby RSpec tests I'm used to. 👌
KotlinTest it is!
Okay ... where do I put these files? How do I run them?
Every guide and blog assumed I already know this. Oh you're trying to test your Kotlin code? Obviously you know how to write a valid Kotlin file, where to put it, which imports to use, and how to run it.
Yeah no I had no idea.
This was an example in docs:
class MyTests : StringSpec({
"length should return size of string" {
"hello".length shouldBe 5
}
"startsWith should test for a prefix" {
"world" should startWith("wor")
}
})
The file you actually need to write looks like this:
package your.stuff
import io.kotlintest.specs.StringSpec
import io.kotlintest.shouldBe
class MyTests : StringSpec({
"length should return size of string" {
"hello".length shouldBe 5
}
"startsWith should test for a prefix" {
"world" should startWith("wor")
}
})
Banged my head against that wall for an hour. Such a small thing, so hard to figure out on your own.
Like, I resorted to reading KotlinTest source files to figure this out that's how bad all the guides are.
And I still didn't know where to put it or how to run it.
Figured that out after many more frustrating hours of banging my head through this damn brick wall. You put files in src/test/your/stuff/test.kt
and run them with ./gradlew test
.
After you set up a new test {}
area in build.gradle
of course. Super obvious.
At least the guides told me how to configure Gradle ...
😑
So yeah I get it now, I understand why video courses are so popular (you can see what's happening and where things go), I see why people ask seemingly obvious questions.
Learning very new stuff is hard. Everyone assumes you have background knowledge that you don't have. sigh
Sorry if I ever do that. Please call me out on it.
Cheers,
~Swizec
PS: yes it's a balance. Otherwise you might as well explain how 1+1 works in every article ... 🤔
Continue reading about Learning a new field is super hard, I get it now 😅
Semantically similar articles hand-picked by GPT-4
- TypeScript for serverless lambda backends 👌
- Sucking is the first step
- 25 lessons from 25 years of coding
- Different worlds
- Why senior engineers get nothing done
Learned something new?
Read more Software Engineering Lessons from Production
I write articles with real insight into the career and skills of a modern software engineer. "Raw and honest from the heart!" as one reader described them. Fueled by lessons learned over 20 years of building production code for side-projects, small businesses, and hyper growth startups. Both successful and not.
Subscribe below 👇
Software Engineering Lessons from Production
Join Swizec's Newsletter and get insightful emails 💌 on mindsets, tactics, and technical skills for your career. Real lessons from building production software. No bullshit.
"Man, love your simple writing! Yours is the only newsletter I open and only blog that I give a fuck to read & scroll till the end. And wow always take away lessons with me. Inspiring! And very relatable. 👌"
Have a burning question that you think I can answer? Hit me up on twitter and I'll do my best.
Who am I and who do I help? I'm Swizec Teller and I turn coders into engineers with "Raw and honest from the heart!" writing. No bullshit. Real insights into the career and skills of a modern software engineer.
Want to become a true senior engineer? Take ownership, have autonomy, and be a force multiplier on your team. The Senior Engineer Mindset ebook can help 👉 swizec.com/senior-mindset. These are the shifts in mindset that unlocked my career.
Curious about Serverless and the modern backend? Check out Serverless Handbook, for frontend engineers 👉 ServerlessHandbook.dev
Want to Stop copy pasting D3 examples and create data visualizations of your own? Learn how to build scalable dataviz React components your whole team can understand with React for Data Visualization
Want to get my best emails on JavaScript, React, Serverless, Fullstack Web, or Indie Hacking? Check out swizec.com/collections
Did someone amazing share this letter with you? Wonderful! You can sign up for my weekly letters for software engineers on their path to greatness, here: swizec.com/blog
Want to brush up on your modern JavaScript syntax? Check out my interactive cheatsheet: es6cheatsheet.com
By the way, just in case no one has told you it yet today: I love and appreciate you for who you are ❤️