Kumusta sa mundo! こんにちはせかい! Aloha Honua! 世界你好! Hola Mundo! Hello World!
Code-switching, a linguistics topic which pertains to a speaker who changes between two to more languages during conversation.
Code-Switching Wikipedia Source
The first program you ever make whenever you are starting out a new programming language. Whenever you click on the first introductory chapter of a coding language tutorial, you usually try to display Hello World in some formal way one way or another.
#ruby
puts "Hello World"
//javascript
document.write("Hello World");
//C#
Console.Writeline("Hello World");
//C++
cout << "Hello World";
return 0;
%MatLab
disp('Hello World')
#Python
print "Hello World"
We just looked at a bunch of different languages saying hello world. There are different ways of how they say it. Let's try to loop through an array of numbers with a for loop.
ruby
javascript
csharp
cpp
matlab
python
#Ruby
numArray = [2, 5, 6, 1]
for n in numArray do
puts n
end
//Javascript
const numArray = [2, 5, 6, 1]
for(let i=0; i <numArray.length; i++){
document.write(numArray[i]);
}
//C#
int[] numArray = new int[4]{2, 5, 6, 1};
for(int i=0; i < numArray.length; i++){
Console.WriteLine(numArray[i]);
}
//c++
int numArray[] = {2, 5, 6, 1}; //C# can also do this
for(int i=0; i < numArray.length; i++){
cout << numArray[i];
}
%MatLab
numArray = [2 5 6 1]
for num = numArray
disp(num)
end
#Python
numArray = [2, 5, 6, 1]
for num in numArray:
print num
From a beginner who is probably just starting on their first language would probably be overwhelmed from the syntax, don't fret, they all output the same thing but they are essentially using a for loop, just in different ways.
Notice some patterns with certain languages's for loop:
Similarities:
- Ruby, MatLab, Python
- Javascript, C#, C++
Arrays look like a different setup though. I'm currently studying Ruby & Javascript, but I've been exposed to C#, Python, and a bit of C++. I had to look up more about MatLab. I mainly heard about it because I have a friend who graduated from bio engineering that uses this language and I was curious about how the syntax looked.
Before entering a coding bootcamp, I self-taught myself a bit with Python & C#. When I was getting into Javascript and Ruby to prepare for entering the school, I was getting all jumbled with the language syntax, especially coming from C# to Ruby. My thoughts were like "Where are the 'int' and 'string' keywords on the instantiated variables?!? Don't we want to lock in these datatypes so we won't have to worry about working with the wrong data??" But I decided to just go with the flow with learning the language since I just have to force my brain to switch it up and adjust to Ruby. Getting into Ruby, I started to appreciate the language more with its functionality and methods it offers that shows its "[---Ruby Magic---]."
We've spent, at most the first 6 weeks working with Ruby and then Rails, and onto week 7 we have switched gears to learning Javascript. I have almost forgotten all my Javascript since working with Ruby even though I did pre-work preparing for entry of the school. However, it kind of felt like stepping into Javascript, it was a bit faster to adjust because it was not about the syntax that I had to transfer, but the thought process. From Ruby land, I had to work with iterating through a collection of data, accessing the data, and changing the data. Moving to Javascript, I felt like I now know I have to do that with my data, but now just trying to apply it differently with following Javascript's rules.
I feel that once we become familiar with one language, we can make comparisons to another language's syntax when thinking in our first language. We can see what parts of that language can automatically be transferred over to another, such as conditional statements and looping. New stuff to research through switching would have to be methods, arrays, objects, and the different parts of the code that may be even more unfamiliar.
Let's take a code that probably not all of us are familiar, except you C experts, can probably help explain more about the code. So I just grabbed a random piece of example code from a tutorial learning website.
/*
* C program to create a linked list and display the elements in the list
*/
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
void main()
{
struct node
{
int num;
struct node *ptr;
};
typedef struct node NODE;
NODE *head, *first, *temp = 0;
int count = 0;
int choice = 1;
first = 0;
while (choice)
{
head = (NODE *)malloc(sizeof(NODE));
printf("Enter the data item\n");
scanf("%d", &head-> num);
if (first != 0)
{
temp->ptr = head;
temp = head;
}
else
{
first = temp = head;
}
fflush(stdin);
printf("Do you want to continue(Type 0 or 1)?\n");
scanf("%d", &choice);
}
temp->ptr = 0;
/* reset temp to the beginning */
temp = first;
printf("\n status of the linked list is\n");
while (temp != 0)
{
printf("%d=>", temp->num);
count++;
temp = temp -> ptr;
}
printf("NULL\n");
printf("No. of nodes in the list = %d\n", count);
}
Source for this code: https://www.sanfoundry.com/c-program-create-linked-list-display-elements/
I don't understand everything that is going on in this code, however, with some background in javascript, ruby, and C# I can already see some similarities.
I noticed that 'while', 'if', 'else' are pretty universal with keywords since languages will still need the essential looping and conditionals. 'printf' is most likely the printing statement for C, and I can only guess 'scanf' takes some sort of user input. I'm still unfamiliar with the linkedlist topic as well, so that would be for future learning for me.
I would see the syntax that I am completely in the dark with, such as malloc, * (does not look like it's a multiply operator because how it is set up), -> (it looks like it may be used similarly but functions different with Javascript's arrow function), struct (which could possibly be class). The 'void main()' is also a different for creating a block when it comes to ruby or javascript, but I have seen it, along with 'public' or 'static' in C#. Ruby & Javascript might group this whole block as class, def, or function.
This is probably a too advanced topic for me, but I felt that I was able to read and understand part of the code of what it was doing, and that is coming from someone who hasn't dove into the C Language. I did have some C# background so it would probably be kind of cheating I guess because they are in the C family, but still! From currently learning Javascript, I feel my C# knowledge quite hazy for this.
If you just starting out learning programming, I would suggest focusing on one language until you get about 75%-80% comfortable with it where you can build some simple passion applications. If you've learned one language and are now switching to another, Great! You can switch to another learning material but you could now move a bit faster since a few sections would most likely be easier to do since you now are comfortable with it after experiencing it from your first language.
Here are some learning materials to get started with some languages. For Python & Ruby, I would suggest Zed's "Learn [programming language] the Hard Way" because he assumes you know nothing about programming and breaks down the code.
Python:
https://www.souravsengupta.com/cds2015/python/LPTHW.pdf
Ruby:
https://www.amazon.ca/Learn-Ruby-Hard-Way-Computational/dp/032188499X
I've learned C# through a few Udemy courses.
C#:
https://www.udemy.com/topic/c-sharp/
Codecademy has some languages too, C++, Javascript, etc:
https://www.codecademy.com/
TutorialsPoint has plenty of resources as well, MatLab:
https://www.tutorialspoint.com/matlab/
Top comments (0)