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.
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.
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.
One simply trick I do is use different Editors/IDEs for each lang, with distinct themes.
So for example, I associate work on python with Sublime, json/js with VS Code, Rust with IntelliJ, Android with Android Studio (yes, I know I could do both in IntelliJ!), Swift with Xcode.
It super handy this way because one big trouble of do all in the same UI is that "switch" bring everything at once, instead when all is their focused UI have things side-by-side with different themes/fonts let everything be distinct.
Weirdly, I can't like the same theme/font across everything, I suppose some stuff look nicer here than there :)
One minor thing that helped a lot was to have custom IDE settings for each (different code fonts, different background colours, etc.).
I found it helped get into the mindset of a language a bit quicker by having them differentiated (e.g. I can switch to window and know what language I'm dealing with without having to read any code).
While I do sometimes almost write “nil” instead of “None” in Python, it’s rare enough not to be an issue.
Maybe it helps that I also use three human languages in my daily life, and mixing up words just isn’t something that happens (although forgetting does).
For my main three, these days I use the jetbrains IDEs, and they are helpful enough that I tend to switch mode fairly quickly with their suggestions.
Back when I used to use gedit with a shell open underneath for basically everything, it was a bit harder. I was mostly coding in C and C++ then, and python felt really different and was harder to flip into.
That said, the more frequently you do these sorts of context switches, the better you're likely to get at them.
While it might not help with something as specific as semicolons, the same shift helps to focus on typical solutions in the problem space for that particular language. I'm more likely to install dependencies and use classes in Python than Go, or try functional programming paradigms in Javascript. Switching archetypes somehow helps to switch paradigms and dialects of even similar languages.
Where it goes wrong though is to be thrown as a consultant in several different projects at a time, where different code bases use different styles – such as semicolon versus no-semicolon Javascript. I've come to rely on tooling for those things, which is likely the best solution anyway when a project has a lot of different or external contributors. In the grand scheme of things, and especially these days, it's OK to rely on the computer telling you it didn't quite get something because you missed a semicolon, and to focus on the higher logic as a human being.
That said, I used to write Kotlin and to this day I still occasionally, mistakenly use its syntax when writing Swift. I may not be the best one to provide advice.
Keep each programming language with its classical IDE, the more visually different one another is the easy the switch is.
For example I use Zend for PHP, Delphi for Object Pascal, Visual Studio for C# and for rare occasions I need same Visual Studio for C++ I have it differently configured both with colors and with menus arrangements to be strongly different than the C# one. Also I employ the strategy of each project in its own virtual machine. Nothing runs in the host OS, everything is in virtual machines.
Having this kind of development process is very easy to switch to that part of my brain dealing with that programming language, even when multiple virtual machines are running and I am switching between them.
Hope this helps and good luck.
It is useful as a cheat sheet.
In addition: if you have experience in multiple "imperative" language (read: non-functional / non-prolog / etc) it's easy to pick up another language using that site alone.
Nowadays I mostly work with Java, Node.js (JavaScript/TypeScript) and Rust. I have been programming professionally for about 15 years, and I have been paid for work in C++, C#, Python, PHP in the past, not to mention a gazillion languages that I used on my side projects.
> I find it difficult to switch between the grammar of the languages
I have similar issues that you describe (wasting a few minutes, in my case, because of some syntax error) if I start off from an empty file or if a few days have passed from the last time that I used a certain tech. If I am continuing work on an on-going project I first do smaller tasks in existing codebase to get "into it", If I am starting a new project I sometimes copy an old one to get started and I edit it (delete most of the code, modify the config etc.)
Also, a lot is gained if you make yourself aware that you just switched to a different tech.
Obviously (is it?) I use an IDE and that helps _a lot_.
Each language's syntax depends on the design choices of that language, and the wider your knowledge, the better "feeling" you have for why does a language use a certain syntax, and switching between them starts coming naturally.
[1] https://medicalxpress.com/news/2020-06-language-brain-scans-...
The same goes for tooling, frameworks, and libraries.
You probably want to have extended deep focus on as few "things" at a time as you can afford now, given that you are experiencing issues.
Look up spaced repetition and other techniques - IME much of what goes for learning human languages apply to programming languages as well.
Just like it's counterproductive to start taking beginner classes in French, German, and Spanish at the same time... Get to base level with one and then adding more gets a lot easier.
Over time, as you get practice, code switching will become second nature, especially if you do it more. I might be even advice more senior devs to do more of what you should do less of right now, if that makes sense.
Like "do you have any tricks to better distinguish red and green color?"
You have to become an expert in the tools you're using. Study the languages in depth at their specification level, not just tutorials.
If you know several languages well enough to write parser almost entirely from memory, and you still get mixed up when switching between them, then it's down to some cognitive difference between you and people who don't have that problem. Maybe some mild form of dyslexia or something along those lines.
Your brain will stay confused until it learns language “instincts” to the level when you just know how to write in it and don’t have to think about it, like riding a bike. This only comes with experience, ime. I’d advise you to isolate your time more, e.g. a week in go, another week in ts, to allow experience to sink in and form two distinct “wells”, but not sure if that’s actually required or feasible.
I also like a comment about having different IDEs. I’m using a similar technique for ssh and rdp, where critical servers have a distinct background or prompt, so I don’t fool around when it screams production A or production B.
I still can see specific colors when thinking about C (08), BASIC (18) and Pascal (1E).
He was well-known for starting to illustrate something in Java or C (or whatever the nominal language for the class was), then, about 5 whiteboards later, he'd be writing in Lisp or FORTRAN, then go back to Java to wrap it up.
Awesome professor, though. Language wandering aside, he gave some of the clearest explanations I've ever encountered.
The biggest challenge is switching from one array language to another, they are very similar but have subtle differences that I forget. Mostly because I am still not proficient at any of them.
Switching between a mainly imperative OOP langauge to a functional language is always very smooth, especially since my preference is lisp so the syntax and patterns are completely different, although modern Java has taken on a lot of functional goodness.
But I never really think about the switch, it has all become second nature to me.
I never thought about it but maybe it is related to being multi-lingual? E.g. I can switch between Danish and English no problem as well.
If you have a decent editor it should mark syntax errors as you type which is super helpful. I’ve absent mindedly typed “func” when I meant “fn” or “function” countless times and seeing it not get highlighted correctly or having the next line indented incorrectly usually tips me off before I run/compile it.
I programmed in JS for a year before picking up python. I would struggle with python’s syntax for a while but over time it just worked out. Same thing now with clojure.
I think it’s the same as being bilingual. Your brain just switches effortlessly given enough practice
The language is never important... it's an implementation detail and something that you pick based what is best for the job, library support etc. Software engineering principles are universal.
It comes with time, you get used to switch context, and to ignore the speed bump that occurs when switching.
Additionally getting some quick references for the languages, or personal notes, helps a lot.
Then you only need to search for concepts like "open a file" get the snippet and hop into the next problem.
Naturally the "Jake of all trades, master of none" does apply to some extent, but what matters is delivery, pretty code that isn't delivered doesn't help business.
Pick an IDE that you like. I really like PyCharm but vscode is also quite great.
To that extend you might even go further and have some specific visual clues per programming language. Whether that's different editors, editor profiles / themes depends on you.
Since two of the languages you've mentioned are compiled, they should be giving you specific line/column/error information on syntax errors. If it's taking you a day to de-cipher explicit error reports from the compiler, it's probably time to better familiarize yourself with compiler lingo (most people recommend "the dragon book").
Other than that, I think it's just a matter of experience. The more you use them, the more you switch, the easier it gets.
I recently had to switch to Java after years of mostly doing js and typescript, and though I'd done lots of Java in the past, it was a frustrating experience because there are a lot of things that ts/js just do better than Java.
Go and TS(js\java\c++ etc) may look similar now but they won't after some time.
I program in more languages that I care to enumerate and some are just so in-grained in me that I don't make mistakes with 'close' naming. I'd be more efficient in a single language if I only programmed in that, true, but I think I'm more efficient overall because I bring a wide variety of solution sketches with me that can be applied depending on scope and primary, secondary, tertiary (and more) concerns. Once you have the first half-dozen to dozen languages under your belt, ideally with different paradigma (OO, FP, logic, old-school structural/procedural, bare-metal, VM/script) the next dozen dozen will be a piece of cake and your biggest problem is the warm-up of the language keyword and stdlib name cache. Hence b), above.
When your programs are small, switching between languages is very easy.
?? ?: ?. .? &. || and more ascii salad
Also the semicolon or access of ivars with arrow, this, self or directly is a gradient transition every time.
Tricks and trips for you: no hacks there mate, you just keep doing it till you get used to it. So the tip is to just keep going. Time is your ally.
For example, iteration is so different in TypeScript and Python and I sometimes must remind me about brackets in TS/JS. So I finally resort to a cheat sheet.
Highly recommended!
My trick is to use different editors with different color schemes. IntelliJ for Scala, VSCode for Python. My brain switches immediately.
When I occasionally write Perl, I wonder why perl -c kicks out error messages, then remember I'm supposed to use "sub", not "def".
2. install language runtime support extension for first language
3. Install language runtime support extension for second language
4. RFTM #1
5. RTFM #2