If algorithms can be converted into code of any language, what is the point in having multiple languages?

949 viewsOtherTechnology

If algorithms can be converted into code of any language, what is the point in having multiple languages?

In: Technology

21 Answers

Anonymous 0 Comments

One way to ELI5 this is: different people speak different language. So what’s the point of having french and english and spanish? well, different people speak it.

But that’s just surface answer. More specifically, each language is better at something. Some language are excellent to express math functions, some other are better to develop objects, some are easy to learn for beginners, some are incredibly compact and optimized for performance, some are tailored made for learning and AI, some are made to quickly code recursive things, and so on and so on.

Finally, one last thing to understand is that we needed languages to create better languages. We created assembly code to translate code into 1 and 0. Then we used assembly code to code a better, more evolved language. Then we used THAT language to create a more evolved one, and so on – each time improving or specializing for certain benefits.

Anonymous 0 Comments

[removed]

Anonymous 0 Comments

A car and a pickup will both take you where you want to go. What’s the point of having both?

The truck makes it easier to move a heavy load. You can do it in fewer trips. A car makes it more comfortable and easier to move more people.

Same capabilities for traveling on the same highways, but they make different jobs easier.

Anonymous 0 Comments

Here is a way to sort elements using a merge sort in two different languages. I think it will illustrate the point well. Some language are better at some things than others. Some languages excel at more abstract mathematical problem solving, others are very good at working with memory and interfacing with hardware. Haskel can make a more compact sort, C takes several more lines to do it.

**Haskell:**
“`
mergeSort :: (Ord a) => [a] -> [a]
mergeSort [] = []
mergeSort [a] = [a]
mergeSort a =
merge (mergeSort firstFew) (mergeSort lastFew)
where firstFew = take ((length a) `div` 2) a
lastFew = drop ((length a) `div` 2) a
— Expects a and b to already be sorted
merge :: (Ord a) => [a] -> [a] -> [a]
merge a [] = a
merge [] b = b
merge (a:as) (b:bs)
| a < b = a:(merge as (b:bs))
| otherwise = b:(merge (a:as) bs)
“`

**and C:**
“`
void TopDownMergeSort(A[], B[], n)
{
CopyArray(A, 0, n, B); // one time copy of A[] to B[]
TopDownSplitMerge(A, 0, n, B); // sort data from B[] into A[]
}

void TopDownSplitMerge(B[], iBegin, iEnd, A[])
{
if (iEnd – iBegin <= 1) // if run size == 1
return; // consider it sorted
iMiddle = (iEnd + iBegin) / 2; // iMiddle = mid point
TopDownSplitMerge(A, iBegin, iMiddle, B); // sort the left run
TopDownSplitMerge(A, iMiddle, iEnd, B); // sort the right run
TopDownMerge(B, iBegin, iMiddle, iEnd, A);
}

void TopDownMerge(B[], iBegin, iMiddle, iEnd, A[])
{
i = iBegin, j = iMiddle;

for (k = iBegin; k < iEnd; k++) {
if (i < iMiddle && (j >= iEnd || A[i] <= A[j])) {
B[k] = A[i];
i = i + 1;
} else {
B[k] = A[j];
j = j + 1;
}
}
}

void CopyArray(A[], iBegin, iEnd, B[])
{
for (k = iBegin; k < iEnd; k++)
B[k] = A[k];
}
“`

Anonymous 0 Comments

[removed]

Anonymous 0 Comments

Why have a hammer when you have a screwdriver. Languages do different things. You can implement any algorithm in any language but how difficult that is, how fast it runs, and what you can do with it, will vary.

Anonymous 0 Comments

If a screw, a nail, a steel bolt, and welding all stick two pieces of metal together, what’s the point of having all these types?

The answer is that while the use cases and abilities of these things may seem the same on the surface, each thing has strengths and weakness great enough that separate use cases emerge. In this we can see the premise is false, you can’t use any algorithm in any language.

You can’t build the Golden Gate Bridge out of nails, and you cant make an OS using Python.

Anonymous 0 Comments

I know right? Let’s create a new language that will have all the best features of the other and use it everywhere. Wooops, we have yet another language.

Anonymous 0 Comments

C and C++ are compiled languages – the readable code is portable, but the compiled executable (basically, after translating to a runnable program) is specific to a machine (honestly not sure what this entails. Specific to a model of CPU probably?). These two languages are famous for doing nothing for you automatically and making you do everything yourself, and in return it runs really fucking fast (if you don’t tell it to do something, it just won’t do it, meaning you save a lot of time and space).

Java compiles to “byte code”, but not an actual executable. When you run a “compiled” java “program”, it actually runs a CPU-specific interpreter, and then feeds the interpreter the byte code, meaning a “compiled java program” can run on any machine without further changes to the code. It’s a lot stronger than C and C++. The objects you create have a lot of bells and whistles attached and it will clean up its own garbage, but in return its slower than C and C++.

Python isn’t compiled at all. The python interpreter will just straight up run the human readable code. You don’t even have to explain to the program what the objects are and how to use them, it will figure it out itself. The language tries its best to hide as much of the machine from the programmer as possible, so the programmer can focus on the concepts and theories instead of trying to talk to the computer in a friendly way. Runs “very slowly”, much slower than C/C++ or Java, but because computers are a bajillion times faster than a human anyways, for a lot of applications it doesn’t matter.

Those are the three I was taught for my CS degree. They are among the common languages, but not the most common. There’s a ton of other languages out there and they all do something different.

Anonymous 0 Comments

Language A – DRAW (Square)

Language B – DRAW (Coordinates that make a square)

Language A is easier to code, but will require more processing power/time to draw the square.

Language B doesn’t have to think about a square, it just draws between the coordinates stated.

Both get the same result but it’s when more complexity is needed where the language choice can make a difference. In language A it will be easier to go back and change where the square “spawns”, in B you will have to change all 4 coordinates.

However, if you wanted to make a irregular shape, in language B you can just plot as many coordinates where and when needed and it will just go through and plot through the coordinates. In language A you might have to go draw multiple shapes, stretch and squeeze them, and subtract them from each other to get the result. Stacking much more processing power and time.

It works similar when it comes to networking/rendering/computations. You can generally get the same outcome whatever the language, but in some languages it can require less lines of code and you might have more control over how the result is gained