Any examples? I've found Julia far easier for simple things than python. Most modern problems are mathematical and nature and I think it's pretty objective that julia looks closer to the mathematics.
----Some tests of very simple tasks in both languages.
At its most basic the obviouses becomes different:
Let's try to get a very simple object: a 3,3 matrix of random booleans in both languages:
Julia:
A = rand(Bool,3,3)
Python: No standard support for Matrices. I could really do it a disservsice and comapre the "core language", but that''s obivously stupid so we'll bring in some external libraries to make it easier. Of many ways to skin the cat here's one..
Python
import numpy.numpy as np
gen = np.random.default.default_rng()
B = gen.choice([True,False],(3,3))
BTW julia has this choice function built into the command as well, so rand(["Which", "Word", "Will", "I", "get?"]) produces exactly what you'd expect.
----
Acutally I can't think of any cases at all off the top of my head. Sorry, I mean my np.somenamespace.another.namespace.sparce head :)
I mean just going down the list of things that make code easier in Julia..
* Python requires a third party library for any kind of linear algebra. and matrix multiplication:*
A =[1 4;6 7"; B = [2 ;3]; A*B doesn't work, i.e. you literally even multiply a matrix! This is madness.you'll need yet again a third partly library
Python doesnt have broadcasting. let's apply sin(x) to a matrix a Pythonic(+ required third party libraries)
import numpy as np
import math #sigh
x = np.array([1, 2, 3, 4, 5])
f = lambda x: sin(x)
Now in Julia (notice the . after sin) x=1:5 sin.(x)
or more explicity we could write broadcast(sin, x)
Even basic string interpolation in Julia is a much nicer "trivial task" than in python alone
No special brackets, just clean "$myvar"
# Reading files is easier
Julia
readlines("my_test.txt")
Python
open("my_test.txt").readlines()
What a stupid option in 2? if I call readlines on a filename, 99% of people, 99% of the time, want to read the lines on the file at that path. Why require two function calls?
It’s funny that people used to get on Python’s case for not being object oriented enough, and now we’ve come around to folks thinking Python should just throw a function for everything into the default namespace …
In Julia with multiple dispatch there is no problem to adding more things to the global namespace. But it does not work for Python, so it’s developers must be very conservative with global names.
This is a problem for non-dispatch or singular dispatch languages, it's significantly different in the context of multiple dispatch. Namespaces are, well, not bad, but sometimes they are a solution to a problem that does not necessarily exist.
Is it really that different? It's fine in languages with multiple dispatch to have its builtin functions in the default namespace, but that doesn't mean that we'd want functions for everything in the default namespace. Namespacing is still useful.
For one thing, I've found it very useful when folks use syntax like `import numpy as np`, because then when I see `np.foo` I can trace back where `foo` comes from and look up the relevant documentation.
The complaint about `open("foo.txt").readlines()` vs `readlines("foo.txt")` is a red herring IMO, because nothing stops anyone from implementing a generic `readlines()` function in Python that can take a string file name or a file handler object. It's just that nobody really cares enough to because it's a complete non-issue.
But Julia _does_ have namespaces, and you can import everything with the `import` statement, or you can retrieve only the functions you need. This is also what is generally done during package development, while dumping everything is for interactive use.
At its most basic the obviouses becomes different:
Let's try to get a very simple object: a 3,3 matrix of random booleans in both languages: Julia:
A = rand(Bool,3,3)
Python: No standard support for Matrices. I could really do it a disservsice and comapre the "core language", but that''s obivously stupid so we'll bring in some external libraries to make it easier. Of many ways to skin the cat here's one.. Python
import numpy.numpy as np gen = np.random.default.default_rng() B = gen.choice([True,False],(3,3))
BTW julia has this choice function built into the command as well, so rand(["Which", "Word", "Will", "I", "get?"]) produces exactly what you'd expect.
----
Acutally I can't think of any cases at all off the top of my head. Sorry, I mean my np.somenamespace.another.namespace.sparce head :) I mean just going down the list of things that make code easier in Julia..
* Python requires a third party library for any kind of linear algebra. and matrix multiplication:*
Python doesnt have broadcasting. let's apply sin(x) to a matrix a Pythonic(+ required third party libraries) Now in Julia (notice the . after sin) x=1:5 sin.(x) or more explicity we could write broadcast(sin, x)Even basic string interpolation in Julia is a much nicer "trivial task" than in python alone
No special brackets, just clean "$myvar"
# Reading files is easier
Julia
Pythonopen("my_test.txt").readlines()
What a stupid option in 2? if I call readlines on a filename, 99% of people, 99% of the time, want to read the lines on the file at that path. Why require two function calls?