Readit News logoReadit News
Posted by u/BrandoElFollito 3 years ago
Ask HN: How do you switch between programming languages?
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, ...

shepherdjerred · 3 years ago
I think this is something you naturally get better at. You start to resize that languages have similar ideas, but different representations.

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.

bfung · 3 years ago
For OP, I switch between Java, Ruby, python, bash, read scala, rust, Haskell, go…

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

viraptor · 3 years ago
Same here, different set of 8 or so languages I cycle through. I stopped caring. From time to time I'll make a silly mistake like using "def" in rust instead of "fn". The highlighter or the compiler will shout at me, I'll fix it and move on.
shepherdjerred · 3 years ago
Two things I forgot to add. Most programming languages have ‘linters’. Linters analyze syntactically valid code for mistakes of different types. Mistakes can be something like you forgot to use a variable you created, to you’re performing some operation incorrectly.

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.

GianFabien · 3 years ago
I program professionally in C, Python and Javascript.

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.

EnderShadow8 · 3 years ago
Why not use double quotes for strings in all languages? It makes sense for a number of reasons. Single quotes are much more likely to be in the contents of a string than double quotes.

Of course, if you have a style guide, you should stick to that.

pabs3 · 3 years ago
In some languages double quotes have different meaning to single quotes, for example in shell variables expand inside double quotes but not inside single. So you need to know which your current language uses.
sshine · 3 years ago
I've gotten used to duckduckgo for even basic things for the first few hours after picking up a language I didn't use for a while. Here are some examples of things I searched for: "rust join two iterables", "rust impl sum", "rust tokio select macro", "rust impl bitand for bool", "rust convert pathbuf to path", "rust join paths", "rust check if file exists", "rust tuple windows", "rust rand gen_range", "rust generate n random numbers", "rust system exit".

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.

qdot76367 · 3 years ago
Thanks to having too many jobs/responsibilities, I currently am switching multiple times daily between Rust, Typescript, Dart, Python, and sometimes, god forbid, C/C++. Usually at a moments notice, because a lot of times I'm writing FFI between those languages so it's multiple at the same 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.

stevecat · 3 years ago
I switch between Ruby and C++ frequently. My trick, which I admit is complete unplanned fluke, is different IDEs. Sublime for Ruby and XCode for C++. They look so different that my brain just disregards the other language. I briefly tried Ruby in XCode and nothing made any sense.

Assuming you don't want to install multiple editors, perhaps different colour schemes might produce something similar in your brain.

Philip-J-Fry · 3 years ago
I move between 4 different languages depending on what I'm working on.

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.

jpgvm · 3 years ago
Unfortunately it just takes time until switching becomes easy/natural.

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.

duykhoa12t · 3 years ago
Before I start working on a project, I spend a couple of minutes to read and understand the logic of the current code base related to the change. By doing this, it naturally reminds me about the language syntax, the framework, the project convention, and the team's best practice. If you do it regularly, you will feel it more natural. Most of the modern languages' projects are easy to identified the scope of changes. Don't pay too much attention to the languages syntax, but rather to the logic.