Cover Image

Contents

The Problem

You’re a 10x developer until the language changes.

print("Hello world");

Nope…

console.log("Hello world");

No…

System.out.println("Hello world");

There it is!

Programming in Tongues

Because I wasn’t careful, I recently found myself programming in 3 languages, each with its own accents and inuendos:

  • Dart: For my day job. I’m working on a Flutter app for Android, iOS, and the web. I’ve been working with Dart for almost 4 years so this is my happy place.
  • TypeScript: For landing pages and various other React-based web interactions. I’ve dabbled with JavaScript, HTML, React, and the like but I only have a few months of experience under my belt.
  • Swift: For the Apple Vision Pro. I couldn’t resist the siren call of spatial computing. There’s only 1000 apps on the store so the competition is small, right? I’ve never written Swift code before.

Everyone will tell you that trying to learn multiple programming languages at the same time is ineffective and they’re not wrong. You instantly recognize the similarities between languages, making it faster for you to understand how the code works, but the syntax differences absolutely slow you down. Sure, Dart, TypeScript, and Swift all give you the ability to create a variable that can later change, but they all do it a little bit differently.

Dart

var name = "Joseph";

Pure, simple, and easy to understand.

TypeScript

let name = "Joseph";

Now we’re using let instead of var. Remember that.

Swift

var name = "Joseph"

Back to using var…but without the semicolon.

Its possible to remember each of these syntax rules. Its also possible to cut your grass with scissors. The issue is that you don’t just need to remember variable instantiation. You need to remember syntax related to variables, constants, data types, flow control, commenting, debugging, and everything else that makes programming what it is.

In Practice

GitHub copilot eased the pain of transitioning back and forth between Dart and TypeScript but writing TypeScript still felt slow because of my inexperience.

Simple things like untyped variables were layups for copilot:

let //...copilot finishes the statement with something that makes sense

The more layered the request however, the more wait time. For example, if I wanted a nullable String, I’d type out this comment and let copilot figure out the next line:

// nullable String variable

When you’re attempting to get the code out of your head and onto the screen, any waiting feels like too much. Waiting just a few seconds to let copilot think was frustrating. Plus, typing out a comment for such a simple request was admittedly awful.

The old school advice would be to learn the syntax and use it without relying on copilot. My response would be that using copilot to program is effectively learning the syntax on the fly and its faster than repeatedly googling basic syntax questions. After copilot politely showed me how to create a nullable variable a few times I didn’t need the extra comment. I had remembered.

When you introduce a third or fourth language however, the difficulty of remembering the individual syntaxes is multiplied (by 3 or 4 times, actually). Another language, another specific pattern. Static typing here, dynamic typing there. Semicolons only in languages that have the letter “T” in their name. Printing, logging, printing lines, logging lines? If you’re actively using multiple programming languages, you’ve had to feel the sting of forgetting something basic.

Copilot definitely helps but if you use it regularly, you’ll always be a bit slower than the alternate universe version of yourself that remembers all syntaxes perfectly.

And then there are days when you need Xcode and your trusty copilot is AWOL.

What If It Was Easy?

It was during this dark time of my life when I asked myself why it had to be this way. The syntax of every language was different but I was asking them each to do very similar things.

  • Create a variable
  • Construct a class
  • Set up a switch statement
  • Print this thing so I can look at it

And thus the idea for Code on the Rocks (COTR like “coder”) was formed.

What if there was a unifying language I could take everywhere and use to code confidently as a beginner?

The cotr-snippets extension is a simple extension for VS Code that maps about 40 snippets to their implementations in a bunch of different languages. For example, the snippet cotrPrint generates the following code depending on the file type you currently have open:

Dart

print('My message');

TypeScript

console.log('My message');

Swift

print("My message")

Rust

println!("My message");

Go

fmt.Println("My message")

In total there are 14 supported languages with more in the works. In addition to the cotrPrint snippet, there are also all of these:

NameDescription
cotrStringThe language’s string data type
cotrIntThe language’s integer data type
cotrNumThe language’s numerical data type
cotrBoolThe language’s boolean data type
cotrBoolTrueThe language’s value for true
cotrBoolFalseThe language’s value for false
cotrDateThe language’s Date data type
cotrNullThe language’s null data type
cotrNowHow the language represents the current time
cotrVarCreates a variable
cotrVarTypedCreates a statically typed variable
cotrVarNullableCreates a nullable variable
cotrVarStringCreates a string variable
cotrVarNumCreates a number variable
cotrVarBoolCreates a boolean variable
cotrVarDateCreates a date variable
cotrVarListCreates a list variable
cotrVarMapCreates a map variable
cotrConstCreates a constant variable
cotrStaticVarCreates a static variable
cotrMapCreates a map/dictionary variable
cotrGenMapGenerates a map/dictionary with a specific number of key/value pairs
cotrListCreates a list/array variable
cotrGenListGenerates a list/array of a specific length
cotrPrintCreates a print/log statement
cotrForLoopCreates a for loop
cotrForInCreates a for-in/of loop
cotrWhileLoopCreates a while loop
cotrSwitchCreates a switch stament with default
cotrFuncCreates a function
cotrLambdaCreates a lambda function
cotrCommentCreates a single-line comment
cotrMultiCommentCreates a multi-line comment
cotrThrowThrows an exception
cotrTryCatchCreates a try-catch block
cotrIfCreates an if statement
cotrIfElseCreates an if-else statement
cotrTernaryCreates a ternary statement

The extension was designed with the Pareto Principle, or the “law of the vital few”, in mind. The snippets above don’t provide 100% coverage of each language but with them you can build something substantial and feel confident in any code base.

What’s Next?

While the extension is already super handy for multilingual coders, I think it could be especially useful for people that are new to programming. Each snippet could come with an optional explainer comment or alternative approaches. Rather than simply printing out brief statements or for loops, the extension could be packed with factual snippets about each language.

  • cotrTypes -> List out all data types
  • cotrPackages -> Prints primary package management site
  • cotrDetails -> Prints classification details about the language

I’m also working on a frameworks variation of the extension for different frontend frameworks like Flutter, React Bootstrap, and SwiftUI. A few examples of the snippets:

  • cotrText -> Text widget, div with text, Text view
  • cotrButton -> ElevatedButton, Bootstrap Button, SwiftUI Button
  • cotrColumn -> Column widget, Flex Grid Col, Swift VStack

Frontend frameworks are a bit tricker to standardize so this idea needs to be baked a little longer.

Try It

The open source GitHub repo can be found here: https://github.com/CodeOTR/cotr-snippets

The VS Code extension cotr-snippets is available on the marketplace: https://marketplace.visualstudio.com/items?itemName=CodeontheRocks.cotr-snippets

Feel free to make contributions or submit issues/feature requests to the repo. Happy coding! 🍹