What the best coding language

In your example, you don’t read from a file, meaning your code will eventually look like this:

from flask import Flask
app = Flask("app")
@app.route('/')
def homepage():
  return """
<!DOCTYPE html>
<html>
    <head>
        <title>Website</title>
    </head>
    <body>
        <p>Example</p>
    </body>
</html>
"""
app.run(port=8080)

That will be really annoying to edit, and you would need to change headers/read a file anyway if you want to use stylesheets/images. If you programmed with a framework like react or svelte, you could do this work easily (and not even have to worry about escaping quotes as well as having proper syntax highlighting). Python isn’t a (good) backend so only use if your code/libraries you want to use only exist in python.

You can use the render_template function in Flask to return from a file.

React… Is frontend?

1 Like

No, I mean have express as a backend API and use react as a frontend

Well you could use React as a frontend with Flask as a backend too? I’m sorry but I don’t see your point.

1 Like

Why would you do that though? You’re just adding unnecessary language switching (when you want to change one you have to get in a different language mindset, also you have to learn two languages to make your website).

You already have to learn HTML and CSS though, most people already know Python and/or JavaScript so they might only need to learn one extra language.

3 Likes
argument 2

JS’s use is for web development. Python is far superior in science fields and general scripting. Most 3D games use a game engine, even most 2D games, but python has good support for 2d graphics. There are a few good libraries for 3D graphics in python if one really wants to use python for this purpose, but obviously this is not a common use for python.
With my experience, I could say the same thing about JS. I’ll hardly touch JS. I argue that JS introduces bad practices too. But I think you overemphasize how hard it is to learn and adapt to a new but similar language.
Write everything in C because of use of numpy? That’s hardly practical in many cases. Python performance is very rarely a bottleneck when using numpy because all of the work is done by numpy. Python code is just the “glue”, and it is written much faster and with less bugs than if it were in C. You say “optimise” the code with C, but if you did any profiling, the python code is hardly the problem (if performance was a concern). Most data scientists would gladly work in python’s great ecosystem and straightforward code than struggle with C.
As I’ve said, python and JS have different uses. Python has great support for science, and it’s good for quick scripting, learning, etc. JS is the main language for web development, which encompasses many programming jobs. It’s up to the learner what direction they want to go in, but in the meantime, both are fine to learn as it is easy to pick up the other.
Most would say python is better than JS in readability and the other aspects. They are both easy to learn, and python is often easier because of it’s consistency, readability, and simple syntax. HTTP and async are web development-specific examples for JS.
Classes are hardly updated. If you at code.org, one of the main learning resources for programming (and it uses JS), it has a really old version and let x = 0; is invalid syntax. Wow, I guess new JS features are never taught.

You miss the point about performance. A little loop doesn’t say how a program will perform as a whole, a more complicated program will be more balanced. Even so, the time gained in performance is negligible, especially with many things being IO bound or insignificant compared to latency. Python’s main benefits are not to be ignored or disregarded just because of performance gains that are not important or significant in many cases. Often, the heavy loads are performed by fast libraries or builtins rather than pure, naive python code that is shown in the benchmark.

4 Likes

Can you not write in a details/summary tag? It’s really difficult for me to read because the background does not contrast well with the text colour.

I’m not saying data scientists should suddenly switch language, I’m just pointing out that python is not perfect for everything. Obviously they will essentially be wasting their time if they program in C (because they will program slower for unneeded performance improvements) but yet C is a useful language to know (because it’s another layer of abstraction away from assembly but doesn’t lose any performance).

Nodejs is honestly amazing in all environments, which is why I admire it so much. When you use it for things like stdout streams it works amazingly (despite JS being so ‘web-based’).

Python does give you some more low-level control but js manages to simplify it so it’s almost also high level. I would not say python is significantly better for scripting (although python’s random module is way better than math.random lmao).

Python’s better for science because that’s what it’s been used for and why it has so many libraries for it, meaning that you certainly should learn it for science, but that doesn’t mean it should be taught as some assumed canonical default.

The loop isn’t an accurate representation because every small performance loss will be emphasised for each iteration. However a program often will consist of a loop with an absurd amount of iterations and that is when you want to consider performance. Honestly performance doesn’t really matter until it does (in rare cases), so python is effective basically all the time.

That said, in projects I have worked on previously, using C++ has given me a huge advantage (literally 1000x faster). In the said project, I was reverse seed hunting and python’s simplicity (automatically resizing numbers to avoid overflow errors) was what caused my programs to be so slow. In said example I could have probably spent ages looking for a library that worked with my specific algorithm, or written my own C library to interpolate with python, but I ended up just writing in C++.

Sure, I was putting the dropdown so others didn’t have to read it.

Python is generally considered to be the language with the highest abstraction/level, or one of them, which makes it ideal for many tasks. C is indeed a useful language to know and I have partially learned it. (It also integrates well with python.) Learners would definitely benefit from learning a starting language and then picking up C to use for certain tasks, unless they are certain they will never touch or benefit from low level.
I don’t have any knowledge about NodeJS. Python’s very high level is indeed good for science and scripting, I would think that most people would prefer to script in python than JS (mainly up to preference or experience). Python is one of the main languages for science, the features being one aspect but a bigger aspect being the huge ecosystem: learning resources, community, libraries, etc. There is probably not a better language to learn for science unless the specific field has a more important language (e.g. R).
Python’s maximum tradeoff of more abstraction, less performance is quite effective, yes. The most common uses of python see their heavy loops put into a builtin library, keeping enough performance. For where there is no builtin library, there are tools such as PyPy, C extensions, and Cython that can get the rest of the performance with varying levels of experience needed. One of the reasons python is so useful is because most of the code can be written in convenient Python but the small amount of performance-critical code can be written or imported as fast bindings, builtins, or extensions.
Indeed, I have once created a board game brute force algorithm in python and then transpiled it into C (many code modifications needed, half-python, half-C) using Cython, which achieved the pure speed of C while maintaining maximum compatibility with python. I don’t know how much faster it is than the pure python version but it is just C vs python here. (Basically, I wrote C code in familiar python syntax while keeping code compatibility with python.) Obviously, most people would prefer to keep it all in C but my experience pushes me towards Cython.

4 Likes

Why are posts getting longer and longer :rofl: :rofl:

4 Likes

Addressing the above argument, despite hating Python with a passion (a bit of an exaggeration but I do hate Python), I would argue Python is renowned for being super easy to pick up for beginners and people who I’d describe as ‘non-programming literate’.

Sure plain JS may generally beat plain Python’s performance, as far as I’ve seen (for now at least, but that’s mostly down to all the work done on the V8 engine due to JSs previous popularity, but Python may find itself getting heavily optimised in the future due to its growing absurd popularity, so who knows) and both can be made even faster.

Both have packages and features that allow you to create blazingly fast programs and both are used by experts and professionals (Python: Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify. JavaScript: Netflix, NASA, Trello, PayPal, LinkedIn, Walmart, Uber, Twitter, Yahoo, eBay, GoDaddy. Interesting that many companies actually will appear in both lists…).

But ultimately, despite the topic title, this question was about which language is best for a couple of 8 to 14 year old kids, so nearly none of the above discussed points are relevant… While I generally prefer the syntax in JS over Python, I think 8 to 14 year old’s would have an easier time understanding Python syntax.

5 Likes

I’d say that Python or Javascript are the best programming languages. Python is easy for beginners and offers a variety of packages to use quickly, such as tensorflow, django, and requests.

Javascript is better for speed – Google’s V8 engine can compile JS in a couple milliseconds. JavaScript also has libraries like tensorflow, express and brain.js.

These languages are also very similar to each other – they both do not need semicolons, variable types are not needed and can be customized, and plenty more.

8 Likes