## DEV Community

Niharika Singh β

Posted on

# How To Master A Programming Language Really Fast π₯

Having competency in at least one programming language is SUPER important for a developer. Developing competency in more than one language gives you an edge.

You might know some people who can pick up languages in no time.

### You can't be more wrong.

The only thing that changes when you move from JavaScript to Rust is NOT the syntax.

Programming style also changes. Key fundamentals change.

A couple months ago, I was learning to program in Rust by using the docs. (This is a really good resource for anyone who wants to get started with Rust)

In my personal experience, learning curve of Rust lang π¦ is really steep. No amount of books/documentation can conclude your learning.

Luckily, around this time I was solving a lot of competitive programming questions on LeetCode.

I decided that I'll take up a 30 day challenge: Solve 30 programming questions in Rust.

THAT really made all the difference.

Let's take Contiguous Array as an example question.

Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.

Example 1:

``````Input: [0,1]
Output: 2
Explanation: [0, 1] is the longest contiguous subarray with equal number of 0 and 1.
``````

Example 2:

``````Input: [0,1,0]
Output: 2
Explanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.
``````

Note: The length of the given binary array will not exceed 50,000.

Solving it in Java was quite simple:

``````class Solution {
public int findMaxLength(int[] nums) {
int sum = 0;
int res = 0;
// build a <sum, index> hashmap
Map<Integer, Integer> map = new HashMap<>();
map.put(0, -1);
for (int i = 0; i < nums.length; i++) {
System.out.println(i);
if (nums[i] == 0) {
sum++;
} else {
sum--;
}
if (map.containsKey(sum)) {
res = Math.max(res, i - map.get(sum));
} else {
map.put(sum, i);
}
}
return res;
}
}
``````

Also, in JavaScript it is simple:

``````/**
* @param {number[]} nums
* @return {number}
*/
var findMaxLength = function(nums) {
let hash = {0:-1};
let count = 0;
let max = 0;
for (let i=0;i<nums.length;i++) {
if (nums[i] == 0) count--;
else count++;

if (hash[count]!=null) max = Math.max(max, i - hash[count]);
else hash[count] = i
}
return max;
};
``````

But the real challenge was to solve it in Rust. You search and then you research until you finally learn.

``````use std::cmp;
use std::collections::HashMap;

impl Solution {
pub fn find_max_length(nums: Vec<i32>) -> i32 {
let mut sum: i32 = 0;
let mut len: i32 = 0;

let mut map = HashMap::new();
map.insert(0, -1);

let size = &nums.len();

for i in 0..*size {
if nums[i as usize] == 0 {
sum -= 1;
} else {
sum += 1;
}
if map.contains_key(&sum) {
let x: i32 = match map.get(&sum) {
Some(&s) => s,
None => -1
};
len = cmp::max(len, (i as i32 -x));
} else {
map.insert(sum, i as i32);
}
}
len
}
}
``````

In short, start solving competitive programming questions in the language you want to learn. You will see a stark difference within a month!

Let me know your thoughts in discussion below.

Cheers!

Graham Long

Great article,
Most programming challenge sites like leet code let you see other peopleβs solutions once you have solved a problem, this can expose you to aspects of a language that you wouldnβt necessarily see from just solving the problem yourself.

Niharika Singh β

Absolutely! This is particularly helpful for difficult problems.

Abdur Rehman Khalid

This Article is Something that I really like to read and it contains all the elements that an Article should have i.e. It was short, it was concise, it was to the point, it was attention-grabbing, it was easy to read and it was easy to understand.

First of all, thank you very much for giving this unique tip of solving the competitive problems in a programming language that we are learning. I will look forward to learning PHP and Laravel or even ruby using this technique as well.

Second, it is really important to know what programming language will solve what kind of problem? The problem is to find the solution to the problem, selecting a programming language or even a technology stack is not a big issue but knowing how to solve the problem is the main point.

In the end, I have heart this post, saved and Marked it as unique as well, and I will share this post with my further colleagues and friends as well.

Niharika Singh β

Thank you for the kind words. I am super happy that you liked it. ππ»
Wish you the best in your learning!

Abdur Rehman Khalid

Doug

I would first create the algorithm in pseudo-code:

1. Give list of binary values.
2. For each value: a. Is it zero? i. If so, ...

And so on. Also, to make understanding each language, I would name all of the variables similarly. So res in Java is max in JavaScript and len in Rust makes it harder to follow the logic.

Matthieu Cneude

Mastering a programming language is, to me, knowing how the tooling works, what semantics is attached to what constructs (and their subtleties). It's as well knowing when to use what, depending on what context. And the most difficult: a language invite you to a specific way of thinking about your problems, and grabbing that is HARD, especially if you know already a language.

In short, it takes more than 30 days.

What you can do in 30 days is having a good idea of the syntax and some semantics already, but I wouldn't call that mastering. It's more having a rough idea about a language.

It depends as well if you go into a paradigm you don't know. Try to learn Haskell in 30 days without knowing the basics of functional programming: it will be hard.

Niharika Singh β

Agreed. But these 30 days can give you the needed confidence that can last even 30 years!

Philippe Bourgau • Edited

I like that your 30 days challenge! Deliberate practice is a sure way to master new skills in no time.

I've experienced something similar by combining Josh Kaufman's 20 hours of learning technique with code katas. Using automated tests during code katas helps you to get instant feedback on your exercises, which I found accelerated the learning even more. I wrote a series of posts on the topic: How to learn a programming language in just 20 hours

One thing I would add to your post is that the more languages you know, and the faster it becomes to pick up a new one. In a way, it's very similar to spoken languages. Once you know 4 or 5, learning the 6th will be a lot faster. Programming languages have many dimensions:

• dynamically to statically typed
• OO, functional, imperative, logic, prototypal, stack based... or multi paradigms
• more or less immutability
• actors, transactional memory, locks... and other concurrency mechanisms
• run on a VM, or not
• low or high level
• more or less metaprogramming
• ...

Once you've learned enough languages to experience different flavors in all dimensions, it's a lot easier to place the new 'BLUB' language you are trying to learn in this space. You get an almost immediate gut feeling about this language. From then on, a lot of the learning boils down to syntax and libraries.

dilakv

I spent a lot of time developing a simple API in Rust, I think there is very little documentation. Maybe I should have taken 2 steps back and did more basic things to learn properly.

I think that's what I'm going to do.

Mohammed El-Afifi

Ironically I don't even understand the solution in any language, but maybe I'm not smart enough. :)

Andrew Baisden

Repetition is the key to being the person you want to be. The more you code the easier it will be to understand :)

Mohammed El-Afifi

It depends on what you're coding.

Niharika Singh β

Maybe itβs time for you to pick it up!

Harvey Church

I think you have pretty much cracked the nail on the head here! I would go even more general though and say the overarching advice is regular, repeated practice is the key - in any area. Making sure the practice is good is also important - and in this case, it is met by doing competitive programming questions :)

Niharika Singh β

Yes, this is the core message. Practising is the key. However, I have read that in so many blogs but never found an actionable step, so 'go practice' may be vague. Mentioning an actionable step for the readers is important! But yes, you could master it by cracking competitive programming questions or by building side projects, the choice is yours. :)

Sviatoslav Melnychenko

You can't master programming language in 30 days. At most you can get a feeling of syntax.

Alhassan Kiwamdeen • Edited

It would set the path and build your confidence

Niharika Singh β

YES!

Niharika Singh β

It is essential to keep up with the cadence.

Where I find a challenge PHP for September? For 30 days

Shauna Gordon

You don't really need to find challenges specific to a given language. Things like Advent of Code and other "kata" tools can be done in any language.

Niharika Singh β

Well, you can log on to platforms like LeetCode or HackerRank and get cracking!

Swastik Baranwal

Competitive Programming doesn't really help with using it in production level. You need to know what language to use according to your needs.

Niharika Singh β

Yes I agree.

πWii π³οΈββ§οΈ • Edited

Correct me if I'm wrong, but all your solutions to the array question seem to only consider sequences that start at the beginning of the array π

Niharika Singh β

Thanks! That's a pretty cool learning approach.