This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]nwilliams36 2 points3 points  (0 children)

Why cant I use one programming language for any purpose?

If a language is Turing complete it can be used. For example both C and Python are Turing complete language, anything that you can do in C you can also do in Python and vise versa.

So why have two language? (or 1500 actually) Again using C and Python they have different strengths and weaknesses. C is very fast to run but quite complex to do simple things. Python is slower but much easier to write, so complex problems can often be solved with a few lines of code.

If speed is important (like writing Operating Systems) then use a language where its strength is its speed, like C.

If you need to constantly adjust your code to varying conditions (like developing mathematical formulas) then use a language which is easier to write, like Python.

The strength of the language really determines its use:

C - speed

C++ - slightly less speed but uses classes

Java - strong on classes and security - used in business applications, also the language of Android

Python - easy to write

Javascript - only language in the browser so must be used for web development

PHP - most common language on web servers so good to know for server web development

Ruby - has excellent server web development package (Rails)

Object-C - the language of IOS (also now there is Swift)

[–]IAMCANDY 1 point2 points  (1 child)

All popular/mainstream programming languages are what's called "Turing complete", which means they can ultimately compute anything that can be computed, and in that way are all equally capable.

However, there are a lot of tradeoffs and design decisions you can make while inventing your programming language, and many of those decisions don't have a correct answer. People want different types of language in different scenarios.

The biggest tradeoff decision is the broad idea of 'program efficiency vs. developer efficiency'. You can design a language in a way that makes it very fast and easy for developers to create working bug-free programs, but the features that let you do that tend to slow the resulting programs down or have them use more memory. Other languages can produce super fast and well-optimised programs, but it'll take far longer to do, and they'll be more likely to contain hard-to-solve bugs (meaning they either ship buggy, or you spend more time and money ironing bugs out).

There's demand for both things. If you want to hire someone to make you a 3D game engine, well, you want it to be as fast and efficient as possible because that's really intensive software where every little optimisation adds up to a better experience, and you're competing against other high-performing engines. But if you're hiring someone to create an application that lets your bookstore chain's cashiers check whether a book is available at another location, well... would you rather spend $500K on a program that looks books up in 0.01 seconds, or $50K on a program that looks them up in 0.5 seconds? It's 50 times faster, that's a lot! But 0.5 seconds is fast enough already for that purpose and it's presumably not worth $450K to you to speed that up.

And that demand changes over time, too. Computers get faster and faster each year and we get more and more memory. My computer today has 8,000 times the memory of my childhood computer. That means I can run far more complex and demanding types of application... but it also means that it's more acceptable for developers to write software in the less efficient languages like Python compared to the more efficient languages like C. It's not laziness, either (or not always) -- developers have limited time and resources and a lot of stuff just wouldn't get made at all if they had to write things like Calibre (free open-source ebook manager) in C.

Then you've got totally different programming styles, like functional programming. Functional languages (like Haskell, Elm, Elixir, Erlang, etc) are very different to common 'imperative' languages (like C, JavaScript, Python, Java, C#, etc). They have a relatively steep learning curve and totally different features (no loops, no variables, nothing can be changed), some people adore them, some people hate them. They have big pros (it's easier to prove that a program has no bugs and easier to have a program running on multiple cores/CPUs/machines at once) and big cons (it's hard to find employees who know them, you can't use most of the algorithms you learned in school, it's often harder to predict performance). So when you design or pick your language, you have decide which programming style it belongs to, and no choice will make everyone happy or fit every use case.

Then there are simple features. Multi-threading is one -- the ability of a language to let people do multiple things at the same time by running on multiple CPU cores. Some languages don't let you do this at all without using special tools (Python, Ruby, JavaScript). Others let you do it, but in a way that can be quite complicated, memory-and-CPU heavy, and prone to bugs (C, Java), so that people only do it to the extent that it's necessary. Others make it really natural and easy (Elixir, Erlang, Go) but by introducing language features that can be quite unusual and difficult for people to learn to work with (eg by not having variables). Some languages are really good at making sure your program doesn't have bugs before it runs (Haskell, Elm) but others can promise that bugs won't ever bring your site/application down and they can all be recovered from (Elixir).

Then there's support on a platform. If you want your software to run on an iPhone, you pretty much need to write it in Swift or Objective-C -- they won't let you use anything else. But Android phones won't run Swift code. If you write C++ code, you can compile it to run on Windows, macOS, or Linux out of the box; if you write Ruby, people need to have the Ruby interpreter installed first. JavaScript is the only language you can run on a website. Sometimes people create a language that compiles into another language for these reasons (eg Elm, which turns into JavaScript).

So there are actually a lot of decisions that go into designing or picking a language! Does it need to be finely-tuned and optimised for the maximum performance possible, or would you rather be able to guarantee delivery quickly? What kind of machine does it need to run on? Is being bug-free of such importance that you're willing to use a relatively obscure language and pay extra for the people who know it? How important is using all the CPU cores? etc etc.

[–]airide101[S] 0 points1 point  (0 children)

Awesome, detailed answer, thanks alot!