[HN Gopher] Ask HN: How do you switch between multiple programmi...
___________________________________________________________________
Ask HN: How do you switch between multiple programming languages
while coding?
Whenever I'm coding in multiple languages, I end up mixing the
syntax and making syntactical errors. For example, I would end up
writing "def" in NodeJS or "function" in Python. (Same with
manipulating arrays and so many other basic things) Does it happen
to you too? How do you ensure you're able to switch quickly and
effectively between programming languages while coding? Any tips
or tricks are appreciated.
Author : paraschopra
Score : 8 points
Date : 2024-05-06 04:52 UTC (18 hours ago)
| theGeatZhopa wrote:
| Hey yes that happens too here. Actually, it's a good sign, that
| you mix up. It means both languages are "learned" by your brain.
| It also might be like "I don't even remember how function
| definition is done ..."
|
| So, it's just a "lack of practice" which doesn't mean you're a
| freshman at coding.
|
| Our brain works in "rooms" or in "departments". Have you ever
| make the experience of wanting to do something and therefore go
| to another room. Arriving there, you've forgotten what you
| actually wanted? That's experienced by, I would assume, all of
| us. You just won't remember, what you wanted to do from one
| second to other .. BUT, if you go back to the room you had the
| initial thought in and in which you walked out from, then,
| suddenly it strike's you and you suddenly remember what you
| wanted to do. Just because our brain is working "in rooms". In
| each room we have our concepts (compare TV vs kitchen).
|
| So obviously you have "learned two languages in the same brain
| room". What you now need is to separate this both rooms again. It
| just can be done by explicitly provoking that situation. For
| example, take a python code and translate it purely to JS while
| live coding. Or code different languages in different workspaces
| or even locations. You need to introduce a brain room separator
| somehow. Then it's just a thing of brain & thinking in rooms.
|
| The same problem is faced by language translators, people
| speaking more than one language. All of them exercise and train
| to use different 'rooms' while learning to translate. Another
| example is the live translation of spoken to sign language. You
| have to explicitly train how to move your hands by hearing
| certain words. And even more, you have to explicitly train how to
| hear, think and make movements of hands, while/with the
| information coming in linearly/steadily with future context one
| might need to understand coming, well, in the future.
|
| So it's just practice. You need to provoke such situations so
| your brain get used to fast context switching.
|
| (My experience with that, although not coding:
|
| I speak Russian as mother language. German is my second mother
| language. English is okay, I think. Learned 3 years French
| language. Spoke a little French on daily basis. Then started to
| learn Chinese. One French guy asked me if i can understand what
| he's talking about, I said yes of course and gave him
| instructions how to go to the place he wanted - in Chinese. I
| didn't even notice it. That guy didn't understand a word, while
| I'm being sure to communicate with that guy the same language.
|
| Later, i went to China. Spoke fluently Chinese. But I needed like
| 10 minutes to switch from Chinese to English, when I wanted to
| talk to foreigners in English. Words just didn't come out. After
| some switching time of like 10 minutes, English has been coming
| out fluently, more or less. I decided not to speak it anymore
| that time.
|
| After that, my girlfriend wanted to exercise English. So we had
| to speak Chinese mixed with English. Mix up the grammer. Mix up
| sentence by sentence. Which, actually needed fast switching
| capabilities that she nor I did have. After 1-2 months of daily
| talking on the phone - my and her brain got used to it. I
| noticed, I just could switch and use both languages mixed
| simultaneously. Even the grammar of one with the vocabulary of
| the other was possible without a problem. I tried to use other
| language combinations and it was possible too.. now I can switch
| my 4+1 natural languages JIT)
|
| So there's not much you can do, except provoking such situations,
| doing translation and ... Actually ... It's training.
| miravmehta wrote:
| Takeaway : Coding Lanuage matters, even though industry says
| `its all about problem Solving`. this is pure BS
| pawelmurias wrote:
| This depends. A deep knowledge of a language and fluency are
| underrated but you will be still more productive with good
| programming skills and literally zero knowledge of an
| language looking stuff up then someone who sucks at
| programming but has memorized all the syntax.
| joehx2 wrote:
| > Does [mixing the syntax] happen to you too?
|
| Yes. I switch between Java and JavaScript/TypeScript frequently.
| Probably the biggest syntax typo I make is switching the arrow
| functions: -> vs =>. Also, switching between the various
| `.includes`, `.contains`, `.size`, and `.length`.
|
| Since my IDE catches it immediately, it doesn't really have any
| long-term affects.
| smegsicle wrote:
| that still doesn't explain what language you're switching from
| where 'affects' is used like that
| kevindamm wrote:
| *affects* ( _noun_ )
|
| - a set of observable manifestations of an experienced
| emotion : the facial expressions, gestures, postures, vocal
| intonations, etc., that typically accompany an emotion
|
| - the conscious emotion that occurs in reaction to a thought
| or experience
|
| I suppose the IDE doesn't show any emotion from these context
| switching hiccups.
| atomicnumber3 wrote:
| I switch between Java, go, Ruby, python, and js. And yes I'm a
| mess. The worst is which versions of "strip" vs "trim" each
| language uses to remove white space from the sides of strings.
|
| I dread the next time I have to interview because I'm going to
| look silly, accidentally adding or removing semicolons and
| parens around if statements and etc.
|
| Honestly aside from those, I don't notice it too much and
| there's kind of a muscle memory for it eventually where the
| switching becomes mostly unconscious.
| aristofun wrote:
| This is why I don't yet see alternatives to jetbrains which
| perfectly assists you with proper autocomplete, hints and
| suggestions.
| jemmyw wrote:
| I take issue with your use of the word "perfectly". I've tried
| their products many times (and even won a personal licence a
| few years ago). They are far from perfect. If they afford you a
| productivity gain then all power to you, I personally find them
| a slight hindrance.
| noashavit wrote:
| IDE linters can help detect formatting errors as you code.
| https://megalinter.io and https://trunk.io can help
| wruza wrote:
| Is that a problem? One learns by making mistakes, just wait until
| your mind gets bothered enough to remember to separate contexts.
| If your editor allows it, try making one filetype background
| different from the other to help with identification.
| matt_s wrote:
| Syntax errors are easy to correct. Its when you are working in a
| language that is fundamentally different like a functional
| language and then also an object oriented language where there
| could be large potential issues. Editors and linters aren't going
| to know enough to point out that you're "doing it wrong".
|
| My concrete example would be Ruby and Elixir. There are
| fundamental differences in how you design your solution because
| the languages are that different. It really messes with your
| brain for a while until you can context switch.
|
| A tip if its causing issues larger than typo's or syntax is to
| time-box your work in the different languages, only focusing on
| one at a time. Like mornings doing X and afternoons doing Y. Give
| your brain a break in between.
| err4nt wrote:
| Some ideas: use different editors for different languages, or
| different color themes. Or another is to format code visually
| differently, for example when I write HTML I use double quotes,
| and when I write JavaScript I use single quotes, both are
| acceptable in both languages, but I feel like it helps keep them
| separate if I lean different directions within the expression
| allowed in the languages.
| lokar wrote:
| I still tend to switch back to vanilla vi when writing ANSI C.
| runjake wrote:
| I think the ease of switching between multiple programming
| languages comes with experience.
|
| I used to have similar issues with it, but now it's a relatively
| seamless compartment/context change. I sometimes forget super
| basic function names or something and need to Google/ChatGPT it.
| Stupid stuff like len() for Python after working in JS all
| morning.
| fidotron wrote:
| My current project[1] is a mix of JavaScript, go and Java. The
| key to keeping this together is to use the right tool for the job
| and have the interlanguage communication generated. In this case
| that means grpc, protobuf and vs code for go and JS but IntelliJ
| for Java. Automate everything religiously so it is hard to get
| out of sync.
|
| I am a huge protobuf fanboy, and accept it has flaws, but it has
| saved me so much time and pain over the years it is amazing.
|
| [1] https://luduxia.com/showdown/ Seriously. Obviously the front
| end is JS, built (custom esbuild) and served with golang, with a
| Java backend that drives foundationdb.
| TillE wrote:
| Like others have said, I think this really just comes down to
| experience. Keep at it, become comfortable with the languages,
| and it shouldn't be an issue.
|
| Writing beautiful _idiomatic_ code in multiple languages is a big
| challenge, but writing syntactically correct code should just
| come naturally after a while.
| bschmidt1 wrote:
| To me the syntax is the least problematic - Ruby, Python, Node,
| PHP... they're not _that_ different looking syntax-wise.
|
| For me it's definitely the CLI, package manager, and other devops
| around using the language that makes the context-switching
| tougher. npm vs gem vs pip and the fact that they all kinda work
| differently: npm will install libs into a "node_modules" folder
| in every project (so you could have 45 copies of React) where
| other package managers might install 1 copy system wide and your
| project just references it, so it affects how you deal with
| version mismatches. nvm vs rbenv vs venv/pyenv - slight nuances
| there too.
|
| Case in point try using Angular as a React dev. You're still in
| JavaScript, but the CLI part is different and more involved, the
| @ decorator syntax and other paradigms look/feel nothing like the
| React ecosystem.
|
| Getting into compiled languages there's usually a heavy IDE
| component you need to use and be good at (thinking of iOS/Xcode,
| or whatever C/C++ devs are using).
|
| But once I'm to the point of writing in a code file and I can
| easily run it and see my changes, I'm good at that point.
|
| Tips: LLMs are great translators. An LLM sidekick to accompany
| work outside your normal language or framework is extremely
| useful - can't recommend it enough. Not only will you get bespoke
| code examples but it will explain the "why" behind certain things
| that are foreign to you.
|
| And of course, just spend a lot of time coding in the language
| you want to make less mistakes in.
| rgrmrts wrote:
| I've written a fair amount of production code in a bunch of
| different languages and despite years of experience I still
| usually reference a syntax cheat sheet or something for most
| languages (python being an exception at this point).
|
| Like others have said, keep at it and you'll improve
| memory/recall over time. But if you don't, that's fine too. The
| ability to write code really fast with perfect recall of syntax
| is overrated IMO.
___________________________________________________________________
(page generated 2024-05-06 23:00 UTC)