Swizec Teller - a geek with a hatswizec.com

    Learning a new field is super hard, I get it now πŸ˜…

    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.


    Swizec Teller published ServerlessHandbook.dev avatarSwizec Teller published ServerlessHandbook.dev@Swizec
    The time has come for me to learn Kotlin. Because reasons

    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!

    Swizec Teller published ServerlessHandbook.dev avatarSwizec Teller published ServerlessHandbook.dev@Swizec
    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

    Thanks StackOverflow

    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.

    Swizec Teller published ServerlessHandbook.dev avatarSwizec Teller published ServerlessHandbook.dev@Swizec
    Trying to install the aws cli so I can properly configure stuff. Thanks @NejcRavnik for the idea

    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
    Tweet media

    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 πŸ’ͺ

    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 ...

    Swizec Teller published ServerlessHandbook.dev avatarSwizec Teller published ServerlessHandbook.dev@Swizec
    Learning completely new tech is an eye opening experience.

    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:

    <code class="kotlin">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:

    <code class="kotlin">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 ... πŸ€”

    Did you enjoy this article?

    Published on March 11th, 2019 in Back End, Technical

    Learned something new?
    Want to become an expert?

    Here's how it works πŸ‘‡

    Leave your email and I'll send you thoughtfully written emails every week about React, JavaScript, and your career. Lessons learned over 20 years in the industry working with companies ranging from tiny startups to Fortune5 behemoths.

    Join Swizec's Newsletter

    And get thoughtful letters πŸ’Œ 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. πŸ‘Œ"

    ~ Ashish Kumar

    Join over 14,000 engineers just like you already improving their careers with my letters, workshops, courses, and talks. ✌️

    Have a burning question that you think I can answer?Β I don't have all of the answers, but I have some! Hit me up on twitter or book a 30min ama for in-depth help.

    Ready to Stop copy pasting D3 examples and create data visualizations of your own? Β Learn how to build scalable dataviz components your whole team can understand with React for Data Visualization

    Curious about Serverless and the modern backend? Check out Serverless Handbook, modern backend for the frontend engineer.

    Ready to learn how it all fits together and build a modern webapp from scratch? Learn how to launch a webapp and make your first πŸ’° on the side with ServerlessReact.Dev

    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 ❀️

    Created bySwizecwith ❀️