I am an amateur developer and bounce back and forth between Go and Typescript. Since I code in my free time, I usually do a week of Go, then maybe a few days of Python, and then back to Typescript.
I find it difficult to switch between the grammar of the languages (especially ones that are rather close such as Go and TS) and spend a day pondering over bugs which are an extra colon, or a dot in the wrong line.
Do you have any tricks/hacks to make the switch easier?
---
Note: by "close" I mean "visually close": "func" vs "function", stacked chained methods that either have their dot at the end of the previous line, or at the beginning on the next, single vs double quotes, types prefixed by a colon or not, ...
Is this a problem that is having a significant impact, or just an annoyance?
If you aren’t using an IDE, then you definitely should start. Any good IDE for the languages you mentioned will provide lots of help with incorrect syntax. Be sure you have it properly configured so that it can give you as much help as possible.
I program in many different languages and I always have to search for things when switching to one I haven’t used recently. I view this not as a bad thing. Google exists for this very purpose, and there isn’t too much benefit to intentional memorization.
Lastly, the book The Programmers Brain touches on how to remember syntax among other things. It might be useful.
And the advice here in this comment chain is spot on:
1. Know the underlying concepts, all programming languages are “same” after awhile (ex: object.prop, function calls, global vs non-globals, lambdas/anon funcs.
2. Use a compiler and or linter to catch syntax errors and don’t worry about memorizing it - knowing how to read the output/error msg and solving the issue is more important
Linters are useful in general, but in your case they can help you write better code when you aren’t as familiar with the language. Go has a project called golangci-lint, while TypeScript has eslint.
The second thing is code formatters. Every language has its own formatting style, so it can be nice to have a program that does the formatting for you. Go has gofmt, and TS has Prettier (among others).
These tools add some complexity, but if you set these up you’ll have some extra guard rails as long as you remember to run them, or even better run them as a GitHub Action.
Instead of starting with a empty file, I copy an existing file in the language that I'm using. Simply by seeing examples of syntactically correct code, I assimilate. It's only a 90% solution. For example using single quotes on strings in C and putting a ';' at the end of lines tends to creep into my Python code.
Of course, if you have a style guide, you should stick to that.
Then there are the small differences where trial-and-errors + immediate IDE feedback give me the answer. For example, is it 'len(foo)' or 'foo.len()?' Is it 'int foo' or 'foo: int'? Is it 'let foo = ...' or just 'foo = ...'?
The more you code, the better you get at 1) adapting faster, 2) accepting that you need to "land". "Landing" can take hours or days, if you measure by how simple things you have to search for.
Your two concrete examples are "dangerous syntax"; another one (although not language-specific) is forgetting to close a parenthesis: They're the kind of errors that give poor error messages in many languages, and so take unproportionally long to debug considering how banal the mistake is. I think that over time, you learn to be more careful in the places where you've wasted the most time.
I just fuck up in small ways, a lot, and accept that I'm gonna do so thanks to context switching. func/function/fn, var/let/auto/wait I don't even have inference in this language, etc. It just happens, and there's some idiom bleed too.
Luckily IDEs are usually real fast to squiggly red line things now and boot me back into whatever the current context is going to be, and for the code I get reviews on, idiom bleed can be called out.
Assuming you don't want to install multiple editors, perhaps different colour schemes might produce something similar in your brain.
I would only say I'm an advanced-to-expert user of one of them. The others I'm just an intermediate user.
When switching languages there's always a period of about 10 minutes where I'm adjusting to the syntax. Then there's a period of up to a few hours to get my head back into the correct space. For example, moving to a functional language like Erlang requires me a bit longer to get comfortable again.
I've pretty much always got the docs open when I move over to my less comfortable languages for the first few days.
I write Typescript at work atm (quite unfortunate, in the process of campaigning for something more suitable) but program all of my personal projects in a combination of Java/Kotlin or Rust. Previously I wrote Java/Kotlin professionally and still maintain some OSS and personal projects in Python, Perl and Ruby despite not using those languages regularly anymore.
I would say the tougher part is if you need to switch IDEs. I was originally doing Typescript in IntelliJ which was fine but after needing to adopt Visual Studio Code for team alignment reasons it's more annoying to switch, not because of syntax but because of keyboard shortcuts and IDE capabilities I'm used to.
So I guess I would suggest using a common IDE if you can but otherwise it will just come with time.