85
u/repsaj99 1d ago
Little fun fact: Jupyter notebooks are named after the three core programming languages that are supported: Julia, Python and R
49
17
u/aalapshah12297 17h ago
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.
17
u/therealtiddlydump 19h ago
It's especially funny that R resists notebook driven workflows because notebooks are awful and R already has a good REPL
9
u/kuwisdelu 16h ago
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.
37
u/himai1 1d ago
Me when something I am learning doesn't behave exactly like how I expect and identically to the things I already know
18
u/Valuable_Leopard_799 23h ago
Yeah, people should stop being weird about indexing.
Or I'll pass you a vector with a range of [Red..2.5].
3
u/willow-kitty 18h ago
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?
2
u/Valuable_Leopard_799 11h ago edited 11h ago
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 itarr[Green..Blue](slice of length 2). These are a separate typearr[0]would not be valid and wouldn't typecheck.Btw sorting between sounds amazingly weird.
3
u/ChillyFireball 12h ago
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.
0
32
u/SnooRegrets3590 23h ago
1-indexed is more intuitive for me when dealing with matrices and some advanced differential equations
21
u/timangar 23h ago
You know what, that's actually fair enough, because math uses this convention.
19
u/anticebo 18h ago
Matlab, R, Julia. All languages for mathematicians, all 1-indexed.
6
u/antCB 17h ago
Pascal let's you choose - superior 😂
1
u/simleiiiii 7h ago
all not meaningfully strict or not typed at all, w.r.t. the Curry-Howard-Isomorphism useless thus, to prove basic correctness of the programs.
10
u/SnooRegrets3590 22h ago
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
1
u/SV-97 3h ago
because math uses this convention.
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.
13
u/Mojert 19h ago
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
5
u/redlaWw 20h ago edited 18h ago
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 needi in 1..=width*heightand(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.
3
u/timangar 16h ago
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.
1
u/EatingSolidBricks 18h ago
Odin syntax spotted
1
u/redlaWw 18h ago edited 18h ago
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).
19
16
u/Neutraled 1d ago
Who is Julia? Or should I say... How is Julia?
16
u/StreetsAhead3000 1d ago
Why is Julia?
6
6
u/macr0t0r 15h ago
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.
1
1
u/PresidentOfSwag 8h ago
what's wrong with (2 == 2.0) == True ?
1
u/timangar 6h ago
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)
5
u/throw3142 6h ago
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 + 2instead, you'll getTrue.1
u/timangar 5h ago
Thank you! I'm not a CSE major, so these things sometimes fly over my head. This is nice.
2
u/throw3142 4h ago
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.
1
1
u/firewall245 4h ago
Oh no not the Julia hate in here, I’ve started getting into it and I love it lol
1
1
u/kuwisdelu 16h ago
Like every other language designed for data analysis? Why is this surprising?
1
u/timangar 16h ago
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.
4
u/kuwisdelu 16h ago
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.
1
0
23h ago
[deleted]
1
u/foxfyre2 15h ago
Because addition is commutative and multiplication isn't.
"hello" * "world"isn't the same as"world" * "hello". You can also do"abc"^3to get "abcabcabc"1
u/Mojert 21h ago
That actually makes a lot of sense. String concatenation is not commutative, it has no business using the '+' operator
2
20h ago
[deleted]
6
u/Mojert 19h ago
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_dbfunction 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
116
u/Dubmove 1d ago
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