How would that work? How many indices would even be in that range? Would it be looking at a map and referencing the keys that would sort between those values?
I was half joking by combining these but some languages allow you to use any discrete Enumerable type as your bounds.
So a single precision fixed width number would be totally valid with for example indices 0.0, 0.1, 0.2, ..., 2.4, 2.5. It would just make an array of length 26.
Or obv. [1.0..2.5] to start at one or [42..64] to have an array with valid indices only integers between 41 and 65.
You can obviously also use Enums, so you declare an array of RGB colours and get indices Red, Green, Blue, and then you can both index arr[Red] and also slice into it arr[Green..Blue] (slice of length 2). These are a separate type arr[0] would not be valid and wouldn't typecheck.
I look at it this way: Some games map the attack button to right trigger. Other games map the attack button to X. Both of those can work. But if you map the attack button to the D-pad, I'm gonna question your sanity.
Yea I was mostly using python and made fun of matlab bc of its 1-index, the got addicted to it because scipy is so shit and it was much harder to implement while matlab was out of the box
Then I also got used to the 1-index as well. People in this sub are mostly SWE but scientific researchers code a lot too and julia aims for these people.
Julia should be more popular in the future bc it mogs Python, R, C++ in the science
Except that it really doesn't, even though people like to claim that it does for some reason. Math uses both 1- and 0-based indexing (with neither being significantly more common than the other); and also indexes using other ranges or even all sorts of non-numerical objects on the regular.
I find it more intuitive if the only thing I do with the index is use them... well, for indexing. But the moment you start needing to do some math on the index, I find 0-based better. In 1-based indexing I often find myself having to add and/or subtract one at some place and I more often get off-by-one errors
Regardless of which one you use the math can both be simpler or more complicated. Get the last element of the array in 1 index is just simply A[N] which in zero it's A[N-1]
Loops in 1 index are inclusive, loops in zero based don't contain the upper bounds.
But then things to do with various array math have a +1 in one indexed while zero usually don't.
It doesn't matter which system you pick. You're going to get some ugly +1 or -1 somewhere. It's just a question of where. You get used to both paradigms pretty quickly
If you want to index a matrix though, 0-indexing is more convenient since if the matrix is 0-indexed, for i in 0..<width*height, (i/width, i%width) indexes every element. If you use 1-indexed matrices, then you instead need i in 1..=width*height and (i/width, (i+width-1)%width + 1).
EDIT: Also, relativity can have index 0 be the + dimension and indices 1 to 3 be the ā dimensions, which is kind of nice.
Yes, relativity goes nicely with the zero index convention imo. It's weird having spatial dimensions in index 2-4 instead of 1-3, and having time in index 4 is also not standard.
I actually just tried to be familiar but language-agnostic. The range syntax is based on Rust because I find it to be quite comfortable and intuitive, and it doesn't have the awkward issue of the range of possible meanings that : can have, but mine is more explicit in terms of right-openness or closedness, because I wanted to make it unambiguous what I meant for someone who isn't familiar with Rust range notation. Presumably that's also how Odin designed their range notation, assuming that's what you're referring to (I don't know Odin).
2.0 is a float and therefore subject to floating point errors (2.0000000015 or something like that). 2 is an integer and just 2. So the two actually are not the same in the programming languages I am used to (C++ and python)
That's not how floats work. 2.0 is exactly represented in both 32- and 64-bit floats. They are the same in any language that casts ints to floats for value comparison, and uses IEEE floats.
This can work for certain large numbers, as shown below.
x = 2 ** 53 + 1
print(x)
# x loses precision when converting to float
y = float(x)
print(f'{y:.0f}')
# False
print(x == y)
# y loses no precision when converting back to int
z = int(y)
print(z)
But if you change the first line to x = 2 ** 53 + 2 instead, you'll get True.
Think of it this way: a float is just scientific notation, with a limited amount of precision. So like 3.042 x 105. Except it's in base 2, so it would be like 1.011 x 23.
An integer like 2 is just 1.0 x 21, so it's represented perfectly. Even a fraction like 0.25 can be represented perfectly (1.0 x 2-2).
But e.g. 0.4 can't be represented perfectly, since it's 2/5 and there's no perfect way to represent 1/5.
There are also large integers that can't be represented perfectly. For example, if you had 3 bits of precision then you could never represent 100000001_2 perfectly (it would get rounded to 1.000 x 28).
In reality, 64-bit floats have 53 bits of precision. This is why 253 + 1 can't be represented exactly as a 64-bit float.
First exposure to any language like that. I'm a physics major and only have experience with C++ and python. I have only ever done data analysis in python, Julia is the main programming language of a course I'm taking this semester.
Ah. Yeah, Python is the odd one out when it comes to data science languages, because itās actually a general purpose language that happens to have some good data packages. Any of the languages designed for data analysis from the start use 1-based.
Iāve seen this weird assumption that 0-based is ācorrectā here so many times that I explain this historical distinction when introducing indexing in all my classes now.
Jupytr notebook world have sounded cooler. Like a premium fashion brand that's deliberately spelt wrong so their customers can feel good about themselves when they tell other people how to pronounce it.
Coming from R, I never understood the point of Jupyter notebooks until I actually tried using Pythonās REPL. Yeesh. One more reason semantic whitespace is a bad idea.
My problem with it is that it is JIT while using LLVM (a notoriously slow compiler infrastructure), so to write performant code you need to intuite what will or will not cause a JIT pause. Even sadder is that using a lot of the nice features of Julia will cause this.
I remember watching in horror my ~100 lines script taking 7 minutes to compile during my master thesis. Julia should just ditch the dynamic typing and become a compiled language IMO. But it will never happen because it would break too many things
Long time Julia user here, your experience is not representative of average Julia usage.
These crazy long Evaluation times only happen when you import packages you have never loaded before, since that is when compilation happens. Even then, 7mins is extreme (did you per chance load a plotting library? Those are huge).
Compilation of user code, even for moderately large programs, is typically sub second. It used to be very bad, back in the 1.0/1.1 days, but they put in a ton of work and it got a lot better.
Also, Julia's JIT does not work like those of java and JavaScript, for example. Instead of compiling on assumptions during execution, Julia will analyze your program and only compile what it can prove before running any code. Some people have this referred to it as JAOT compiled instead of JIT (Just Ahead Of Time), to make the difference more clear, but the term never really caught on.
The last time I tried to use Julia was last year - maybe something has changed since then.
When it took nearly an hour to precompile all of the packages I knew I needed, I decided that it wasnāt going to be the tool for me. What if I wanted to share the code with some colleagues? What if I wanted to move it to a different piece of hardware? I realize that these are not significant hurdles for experienced Julia users, but things like āwhich plotting library do I useā or āwhy is it precompiling AGAINā or the extremely slow debugging with common IDEs were a massive turnoff for me.
At the end of the day, my job revolves around solving nonlinear PDE systems on distributed architectures, so petsc4py will continue to be my workhorse, but Iāll give Julia another try one day because it would be REALLY nice to not have to name a variable āvarrho_hat_phi_sigma_gas1ā.
Ok. Just FYI, I don't really care which language you use for your PhD, but reddit is a public platform and Julia still a somewhat niche language trying to grow, so when I see stuff that is in my experience factually incorrect I'm gonna say something.
I have heard that Julia has a rather advanced package ecosystem around PDEs specifically (never used it myself though), so if you find the time and motivation to check it out again you might want to look into JuMP.
Reproducibility and portability should be strengths of Julia, not concerns, so not sure what that's about, but oh well š¤·
Yup. To be fair, it had to compile my dependencies as well, but to be even fairer, there weren't a lot of them.
Which is why for my PhD I switched back to Python. It might be slower once the Julia JIT did its thing, but the performance is way more predictable. That makes it so much easier to write code so that it is performant enough, which includes writing Cython/C++/Rust and calling it from Python. I'm happy with my choice
Exactly the same experience for me (defending soon). At the end of the day, 90% of the walltime is C anyways (numpy, PETSc), so Iād rather stick with old faithful.
Funnily enough, for me most of the wall time ended up being Python. I thought it would be C because my program basically constructs matrices and diagonalize them. Turns out constructing them in Python was a bottleneck, oops. But I ended up writing some C++/Rust code to do that, and now everything is fine
Python may have been slow, but it easily allowed me to see what needed to be sped up, and I could speed it up using another language. With Julia, I would have no idea how to proceed
The worse is that it already has a real type system, not like python or TS. If you specify a type of a function argument, it will be typed check. And the type system is pretty good, it even has multiple dispatch!
Now that I think of it, maybe multiple dispatch is to blame for the language not being compiled ahead of time...
Yeah, it's by design and actually a strength in the right context. It wants to make sure that at compile time, every function call is as type-specified as possible. But very annoying when adding packages and then have to recompile code that was already compiled.
My company's half a million line codebase spread across 200+ projects compiles in way less than that, 7 minutes is enough to run half of the multi-thousand tests for it after compiling and building a seeded database for the tests.
Julia is the language I thought would be a great, free alternative to MatLab language until I ran a simple script for solving two cubic polynomials and saw it take like 10 seconds.
The biggest problem of Julia is it doesnāt actually save the compiled binary. Iām sorry, but at that point itās a glorified interpreted language.
It does save the compiled binary. But it has a really weird thing with the scoping to where if you don't bury your code inside function wrappers, the compiled code for what you ran is lost. And also when you add packages, if they introduce new methods for functions in your code then it gets invalidated and need recompile. You have to use tricks like pre compile workloads and warmup scripts to guarantee a fast experience.
You should check out Dyad Studio from JuliaHub. It ships with it's own Julia image with a custom distribution made for minimal compilation lag for engineering work. Also has a fantastic AI agent for modeling and simulation.
I think custom, opinionated Julia Distributions, like Linux , will be very helpful for getting the potential of the language to be convenient enough to be useful.
Speaking as an ex-Fortran developer who now bounces between C++, Python and MATLAB...the 0 vs 1 indexing argument will never be resolved. They both have their issues. C/C++ needs to be 0-based because it is actually an address offset, not an index. It would make a mess of things if you tried to make it 1-based. But, if you are just doing mathematical equations...yah, there is an argument that 1-based indexing makes more sense. However, it means you can't use clever negative numbers for reversed indexing (used in Python) without creating that weird +/-1 gap, but math-centric languages just tell you to calculate the index from the size, because the size should be determinant in math equations.
So, yah, Julia is 1-based and that fits it well. A pity that the JIT compiler is kind of a pain, though.
Because addition is commutative and multiplication isn't. "hello" * "world" isn't the same as "world" * "hello". You can also do "abc"^3 to get "abcabcabc"
It's "colloquial" only in software engineering circles, but Julia wasn't designed for that community. It was designed to be used by scientists and mathematicians and so make choices that makes sense for that community. Concatenation is also a concept in math, and using '*' as a symbol of concatenation is pretty common
Your rant about commutativity is odd. If you did any abstract algebra, you'd know that when we call something "addition" it implies commutativity. Using the addition symbol for something that is not commutative is actively deceptive. It's the math equivalent of a register_user_in_db function not interacting at all with the database. On the other hand, using a multiplication symbol doesn't imply anything so the fact that "multiplication on scalar is commutative" is irrelevant: it follows the expectation of "multiplication can be whatever". Also, multiplication on scalars doesn't even have to be commutative
58
u/himai1 Sep 18 '26
Me when something I am learning doesn't behave exactly like how I expect and identically to the things I already know
45
u/SnooRegrets3590 Sep 18 '26
1-indexed is more intuitive for me when dealing with matrices and some advanced differential equations
5
u/PresidentOfSwag Sep 19 '26
what's wrong with (2 == 2.0) == True ?
4
u/kuwisdelu Sep 19 '26
Like every other language designed for data analysis? Why is this surprising?
188
u/repsaj99 Sep 18 '26
Little fun fact: Jupyter notebooks are named after the three core programming languages that are supported: Julia, Python and R
156
u/Dubmove Sep 18 '26
Julia is the language I really want to like but deep down I know I hate it although I never would admit that to myself
19
u/JosebaZilarte Sep 18 '26
Julia... is a set.
16
u/Neutraled Sep 18 '26
Who is Julia? Or should I say... How is Julia?
8
u/macr0t0r Sep 19 '26
Speaking as an ex-Fortran developer who now bounces between C++, Python and MATLAB...the 0 vs 1 indexing argument will never be resolved. They both have their issues. C/C++ needs to be 0-based because it is actually an address offset, not an index. It would make a mess of things if you tried to make it 1-based. But, if you are just doing mathematical equations...yah, there is an argument that 1-based indexing makes more sense. However, it means you can't use clever negative numbers for reversed indexing (used in Python) without creating that weird +/-1 gap, but math-centric languages just tell you to calculate the index from the size, because the size should be determinant in math equations.
So, yah, Julia is 1-based and that fits it well. A pity that the JIT compiler is kind of a pain, though.
2
u/firewall245 Sep 19 '26
Oh no not the Julia hate in here, Iāve started getting into it and I love it lol
2
u/mehonje Sep 19 '26
1-indexing is normal for math and science-oriented languages.
2
u/stupled Sep 18 '26
Julia?
1
u/SexyMonad Sep 18 '26
1
u/ThatSnek Sep 24 '26
i thought this was about the Julia Set at first and i was so confused
1
u/johnschnee Sep 18 '26
Who? Never heard of herā¦
0
u/[deleted] Sep 18 '26
[deleted] ā view deleted comment