this post was submitted on 26 Aug 2023
305 points (88.0% liked)

Linux

48035 readers
964 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
all 49 comments
sorted by: hot top controversial new old
[–] fubo 74 points 1 year ago (3 children)

Fortran, really.

In Fortran, variables beginning with the letters i through n have integer type by default, whereas all other letters imply a real-number (floating-point) variable. You can change this by declaring a type, but using i for a real is non-obvious.

(Hence the old joke, "God is real — unless declared integer.")

[–] eager_eagle 32 points 1 year ago* (last edited 1 year ago) (1 children)

idk, this arbitrary i-n range behaving differently than other variables sounds like a terrible source of weird bugs to me. I don't think variable names should ever change a program's behavior.

edit:

Many old Fortran 77 programs uses these implicit rules, but you should not! The probability of errors in your program grows dramatically if you do not consistently declare your variables.

source

[–] [email protected] 29 points 1 year ago (1 children)

This comes from early years, when FORTRAN was introduced and the programmers needed to save space in the punch cards. Today, to avoid this possible source of bugs, you usually state "implicit none" in the preamble.

[–] [email protected] 20 points 1 year ago

So I’ve been an engineer doing code ports to newer versions of Fortran. I never knew why that was at the top of every file. Thank you.

[–] [email protected] 11 points 1 year ago (1 children)

Interesting. I assumed i for iterator.

[–] fubo 23 points 1 year ago (1 children)

i, j, k are commonly used as subscripts in linear algebra, too.

[–] [email protected] 5 points 1 year ago

i^2 = j^2 = k^2 = ijk =-1

[–] [email protected] 1 points 1 year ago* (last edited 11 months ago)

[This comment has been deleted by an automated system]

[–] [email protected] 56 points 1 year ago (4 children)

in programming, and in mathematics, it's always been weird to me that frequently paired variables are basically the most easily confused for one another pairs, especially when written quickly or sloppily.

  • i and j
  • x and y
  • m and n
[–] eager_eagle 23 points 1 year ago (4 children)

exactly, this is so annoying. I don't know by first-hand experience, but I also think p and q are confusing for dyslexic people.

[–] [email protected] 9 points 1 year ago (1 children)

i knew i was forgetting some other common pairings, thank you. p/q and u/v always bugged me too.

[–] [email protected] 6 points 1 year ago (1 children)

u and v were so difficult for me to differentiate in handwriting. My handwriting is not that pretty and the difference between a round bottom and a sharp bottom is not that big when stressed in an exam.

[–] [email protected] 2 points 1 year ago

Like in math: given are the vector fields u, nu and v and the normal vector n ...

[–] BleatingZombie 5 points 1 year ago

I'm not dyslexic, but I always had to write P and Q capitalized on my truth tables to not absent-mindedly get them switched

[–] [email protected] 4 points 1 year ago

Interesting footnote about p and q. You see them turn up on formal logic proofs (for philosophy)

[–] [email protected] 1 points 1 year ago

When travelling in places where Latin script is not official (e.g. Middle East, Asia), I notice many mix-ups of p q and b. I always wondered how this would impact their ability to learn to program.

[–] [email protected] 6 points 1 year ago

I think your problem is with the alphabet, friend

[–] affiliate 4 points 1 year ago (2 children)

the worst is when you have to deal with v and ν (greek “nu”). add in the wedge symbol ∨ and things can get painful.

[–] [email protected] 4 points 1 year ago (1 children)

i've never heard a better argument to disallow unicode in variable names.

[–] affiliate 2 points 1 year ago* (last edited 1 year ago)

another great argument against is the greek question mark, which lets you write the following beautiful loop:

for (int ;=0;;<∧;;++)

[–] MrPoopyButthole 4 points 1 year ago (1 children)

Why would you ever have to do that?

[–] affiliate 2 points 1 year ago

to make a contrived example on the internet

[–] [email protected] 3 points 1 year ago

M as in mancy

[–] [email protected] 33 points 1 year ago

I always like to joke in coding interviews that I really like to make variable names as long as I can so they are very precisely named. Then when I get to a double nested loop I hit them with iterator and jiterator instead of I and j

[–] eager_eagle 24 points 1 year ago* (last edited 1 year ago) (4 children)

Unless they're indices, do yourself a favor and use meaningful names instead.

I avoid index iterations the most I can tbh. And for nested loops,i and k is more readable.

[–] [email protected] 12 points 1 year ago (1 children)

Even for indexes I do index or something more specific for what it's indexing. Any simple iteration I just do map or each so the only time I ever need to actually index things is for more complex scenarios in which case it's worth it to have better names. Also with modem IDEs, auto complete is really good so you don't need to write a full variable name more than once.

[–] eager_eagle 3 points 1 year ago* (last edited 1 year ago)

that's good too. I recommended k over j if using single letters, but I actually tend to use idx when using indices, and more descriptive idx_this, idx_that for rare index-based nested loops.

[–] [email protected] 6 points 1 year ago

When I was a baby coder back in the 90s we were taught that these names were meant to save space in the symbol table because at one time space was so limited that naming your variable n rather than numElementsInArray would have an impact

[–] tkarika 4 points 1 year ago

This is the way.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

Even then,

for (int index = 0; index &lt; 10; index++)

all the way.

[–] [email protected] 15 points 1 year ago* (last edited 1 year ago) (1 children)

i for index or iteration. Using j, k, l... in loops signals (imho) that there is most likely an outer loop and the one using j, k, l are nested. x and y of course are carthesian coordinates . n is used as amount of substance in SI-unit-system, m is mass, maybe thats why it is used as amount of items in a set (Menge).

Programming computers have started to solve mathematical problems and math already used these symbols for centuries(?), so why you should change them? They are well established even in simple school mathematics. And at the end of the day a computer is nothing more than a calculator.

[–] eager_eagle 1 points 1 year ago (1 children)

why you should change them

Readability and maintainability, mostly. They are one character long mostly to help handwriting compact formulas, but their pros end there. For software, though:

"Programs are meant to be read by humans and only incidentally for computers to execute"

[–] Zeth0s 1 points 1 year ago

For readability the loop has to be short, so it is not really a problem, and it is also clear the iterated variable.

Long loops where the iterated variable is called far from the loop are anyway very bad for readability. There is a much worse problem in that code than i and j

[–] [email protected] 13 points 1 year ago (1 children)

x = "Am I a joke to you?";

[–] hydroel 6 points 1 year ago (3 children)

Whay kind of savage names their loop index x?

[–] [email protected] 2 points 1 year ago

Not the index, the variable in the for loop. Index is always i because it can be unless it's a nested loop.

[–] Zeth0s 1 points 1 year ago* (last edited 1 year ago)

You'll receive a visit from ML engineers and data scientists asking if you know the lords and saviors X, y

[–] j4k3 1 points 1 year ago

for x, twit in bird:

[–] [email protected] 9 points 1 year ago (1 children)

I haven't used I and J after college

[–] [email protected] 4 points 1 year ago

I've hardly ever looped over indices after college. For-each loops solve 99% of real-world problems in a better way.

[–] [email protected] 7 points 1 year ago (1 children)

Hi there! Your text contains links to other Lemmy communities, here are correct links for Lemmy users: [email protected]

[–] joneskind 4 points 1 year ago (1 children)

Easy

i for index j for jndex

[–] ShortFuse 1 points 1 year ago

We are kndrex spirits

[–] [email protected] 4 points 1 year ago* (last edited 1 year ago)

Usually variables like that can be avoided with itterators nowadays. If they can’t I like to use idx, if they are nested I name them after what they index, like idx_rows, idx_cols.

[–] UnfortunateShort 3 points 1 year ago

Ask the mathematicians, they started it. And I don't question their wisdom because a) maths can be very scary and b) I like Arch almost as much as being dominated

[–] [email protected] 3 points 1 year ago

I prefer to use K in for loops, but that's just me.

[–] nitefox 2 points 1 year ago

Very relevant to Linux and a very original, funny, meme too I see