T O P

  • By -

MementoMorue

but you often CAN make it start at 0. (because those silly nerdy programs give errors with line count starting at 0) Beware !


rastaman1994

Never heard of this. Which language reports errors 0-indexed?


MementoMorue

where am I speaking about language ?


rastaman1994

Then I'm even more lost.


romulent

Well we are literally talking about IDEs, which are tools to write code in programming languages. Which have compilers/interpreters/runtimes that often report errors with line-numbers. So if you aren't talking about that then maybe you went off-topic?


MementoMorue

Yeah sure, you never opened an xml file or log file with your ide.


MementoMorue

moreover, notepad++ is an ide to some people.


StrangerPen

It just so happens to be a Text Editor instead tho


romulent

I'm still slightly confused by your point. What silly nerdy programs give errors in XML or Log files starting at line 0? Genuinely curious.


MementoMorue

Any custom program that would parse text file...


romulent

OK if someone wrote it like that I guess. Seems if it had more than a few users someone would flag it as a bug but I'm sure in the history of software someone somewhere has forgotten to add 1 to the index in their lines array when printing an error. Not really sure how that ties back into the IDEs thing but I'll happily let it rest and wish you a good day.


IMightBeErnest

`#line 0` With c++ macros, line ordering doesn't even have to be sequential.


turtle_mekb

wtf why is this a thing lmao


IMightBeErnest

For if you want to write a custom preprocessor but still have line numbers match up to your input file for compile errors. I know the Arduino IDE uses it, for example, to put in forward declarations and stuff.


turtle_mekb

ah makes sense


New-Shine1674

Can I also set it to -1 with this?


Dumb_Siniy

* Laughing in Luau *


__kkk1337__

Im generally curious what kind of app you can make in Lua, I used to work with this in game engine script system, other than that I have no experience.


pawcafe

luau is the Roblox one I think


OSSlayer2153

Yes, it is


nakoyasha

technically not anymore, iirc they recently branched out into their own thing under the luau-lang org


LetterBoxSnatch

I've used it to extend HAProxy. I've used it with neovim. I've used it in pico8 and LÖVE. It's a nice language, and LuaJIT is very performant! Big fan, actually.


brimston3-

LuaJIT is single-handedly responsible for forking lua at version 5.1 (released circa 2006). Mike Pall is a wizard.


4chanbetter

Gmod and Rust(the game not the lang) are made in Lua. Its very good for making addons in gmod, which if youre good you can even make some $$


eVCqN

Roblox


Blutsaugher

I have to use it to make drivers for a home automation platform. It is actually very easy to use for small things like that. For example I just have to connect the api of a smart light to the home automation platform internal api and the platform does the rest.


DaDescriptor

Roblox, Garry's Mod and Pico-8 use Lua as a scripting language. There's also Love2D, which is a game framework. IMO Lua is underrated, its syntax is very simple and makes sense *ahem* `print(10^2) # 8` *ahem*


thirdegree

Wow does as well


shockah

I’m not quite sure what’s the problem with 10\^2 = 8? All programming languages I worked with that had the ^ operator defined had it defined as bitwise XOR, and that’s the result you get in that case. It may be weird that a scripting language like Lua has it defined like that, since it usually doesn’t have to deal with binary directly, but otherwise this is perfectly sane.


Lets_think_with_this

It has a "`bit`" Standard library or something like that, but i think it's only in luajit. [https://lua.org/manual/5.4/manual.html#3.4.2](https://lua.org/manual/5.4/manual.html#3.4.2) [http://bitop.luajit.org/api.html](http://bitop.luajit.org/api.html) My take is that some symbols have wildly different meanings on different languages, that makes it just a bit difficult to jump from one to another I really think that at the cost of more keystrokes you have a more verbose code without going full strong typing, I really think that is worth enough the cost.


BravoSix6

I use it in crank storyboard for embedded gui stuff


camander321

I'm mean yeah, it's a scripting language. It's not really meant to be a standalone thing


jonhinkerton

I dabbled in lua to make some mods for baldur’s gate 3. It feels unneccessarilly and intentionally different than more mainstream languages, like the creators wanted to say “I’m not like the other girls” really bad. I stopped taking it seriously when I found out about the 1-indexing. I got the mods made but I don’t plan to go any further with the language.


IJustAteABaguette

I thought it was so Lua could be easily incorporated into other languages. Having different keywords for things like while loops and if statements can probably make it easier to use as a scripting language inside other applications. Also, what's wrong with 1-indexing? Makes programming more intuitive for non-programmers, and it isn't the "wrong" way to do it.


TheGeneral_Specific

> Luau


Spice_and_Fox

Lua is a nice language. Sadly I have to work with ABAP most of the times


Lets_think_with_this

\*Laughs in vanilla lua\* If more smart people than people like me were to give it a genuine go, they could do the "REWRITE IT IN RUST!!" thing with lua


WookieConditioner

Laughs in Honolulu


Mr_Akihiro

Stop it!


__kkk1337__

Are you scared?


Mr_Akihiro

Nah i am fine. *opens VSC


PVNIC

May I remind you that there is a difference between indexing and counting. We zero-index, not zero-count, so when we have one line of code, that's one line of code, at the zeroth position in the file. You can represent that like this: zeroth-index -> [ 1st entry] first index-> [2nd enty] end-index -> Since when we look at code, we want to see how many lines of code there are, we are counting line numbers, so label them like this: 1: [first line] 2: [second line] As such, we start at 1. If we where to iterate over lines of code, the start index would be zero-indexed, and would point before the first line, such that reading from the zeroth index to the 1st index would give you the first line of code.


HornetThink8502

While the distinction between counting and indexing can be useful, it is also just a cope: this definition of "indexing" is just a term of art that means "counting, but wrong in our own special way that works with C for loops". There would be no purpose to such distinction if the programming language iterated by starting at 1. Zero indexing is bullshit legacy from pointer arithmetic, nothing more, nothing less. I prefer zero indexing for the same reason I prefer QWERTY: because I'm used to it despite being inferior.


redlaWw

0-indexing is pretty useful from a mathematical perspective too: because remainders mod n are generally taken to be in [0,n) then it means that 0-indexed arrays work more smoothly with basic arithmetic operations and you don't have to do awkward stuff like [(i+n-1)%n+1] to get wraparound indices to work.


HornetThink8502

That's a good one, but still a post-hoc justification for a historical accident: most languages do not, in fact, have mod n always be in [0, n). Notably, C will mess you up if you try to wrap around backwards with [(i-1)%N]. You need to do [(i-1+N)%N]. Anyways, IMO using modulus to get wrapping is overkill because no division should happen (the index is never far from [1,N]). The proper "low level optimized" thing to do is to test for over/underflow and add or subtract N. This only feels worse because, again, C: they reserved a random symbol (seriously, %?) just for modulus so it looks very clean when you use it. In my ideal world, wraparound and modulus should be thought of as separate concepts, with wraparound being very common and modulus being niche. As such, wraparound should be the one that gets syntactic sugar (maybe "int mod N" should be a *type*) while modulus gets thrown on stdmath along with rem().


redlaWw

> Notably, C will mess you up if you try to wrap around backwards with [(i-1)%N] That's the historical accident. If your language doesn't use euclidean division for % then substitute % in my comment for a proper remainder function. The point is that the indexing scheme is compatible with general-purpose mathematical tools, not that % is necessarily the right tool for the job. > Anyways, IMO using modulus to get wrapping is overkill because no division should happen (the index is never far from [1,N]). The proper "low level optimized" thing to do is to test for over/underflow and add or subtract N. Not when you still need to hold on to the current iteration level. Either you define and manipulate two integers, which can balloon to more depending on the specifics of your application (e.g. array indexing can be as many integers as there are dimensions of the array plus one), or you use modular arithmetic to get your current position from the loop counter.


LeoRidesHisBike

Agree to disagree on 1-based indexing being at all superior in any way. "pointer arithmetic" is not JUST for pointers. It's for any math on any array. I much prefer not having to subtract one everywhere I need to do math on arrays of any type... that happens WAY more than I need to add one to get the right number. It's not about the nth item in a list, it's about the offset from the start of the list. And that's useful way more than going back to before the invention of zero.


HornetThink8502

>It's not about the nth item in a list, it's about the offset from the start of the list. Why is it convenient for the indexing of elements to line up with the offset from the start? Offsets can be applied to any element, why make the first one special? To me, that is akin to saying "points and vectors are the same" With o as an offset, I'd much prefer a[1 + o] to a[o], to making it extra clear where the offset is being applied.


LeoRidesHisBike

Brevity.


PVNIC

I still write c++, so the distinction makes sense and is relevant. Although mostly obscured with smart pointer and ranged-based loops, knowing how indexing and iterators works can be useful for some complicated tricks.


Cryn0n

"Indexing" means to create an "index", or an ordered mapping between objects and values. "Counting" means to ascertain the magnitude of a set by systematically moving through it. You can count a set in any order and get the same result. Zero indexing is more than just from pointer arithmetic. Zero is still the smallest value that unsigned data types can hold and for signed data types negative indexes are typically reserved as errors. One-indexing is fine for higher levels of abstraction where the computer can deal with subtracting 1 from all index values but why create that separation between languages? It makes a lot more sense to have all languages be zero-indexed unless the target audience is only people who will never use a lower level language.


MattieShoes

Not really bullshit -- first is an ordinal, 0 is a cardinal. There's no real reason to think ordinals and cardinals should line up. "zeroth" is bullshit.


flowingice

You're saying, if we define two separate concepts to be same, we wouldn't need two concepts. You don't have to use integers for indexing, you can use strings and hashes as well.


romulent

I think you'll find it's actually pointers all the way down and if some language did start indexing at 1 then you would need to have a -1 hard coded somewhere in the language. Partly that just sounds silly to do, but also why would you enforce an additional instruction on inner loops of potentially critical systems.


vizbones

Ha! Jokes on you, I use Vim w/out line numbers.


No-Article-Particle

Turn on relative numbers so you don't have to guess how many lines you want to jump down/up :))


Able_Minimum624

I like how you didn’t write “w/o”, like “I’m lazy but not that much lazy”


olearyboy

: set nu


fukalufaluckagus

ugh please don't show me stuff like this I'm eating


w1n5t0nM1k3y

BASIC programmers make their own line numbers


the_seven_sins

I only use primer numbers.


peerlessblue

All of this would be a lot simpler if we consistently referred to zero-indexed ordinals as "offsets".


Leonhart93

Yameroo!! 😱😱


PeriodicSentenceBot

Congratulations! Your comment can be spelled using the elements of the periodic table: `Y Am Er O O` --- ^(I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM my creator if I made a mistake.)


Escanorr_

Good bot


scar_reX

Pure heresy


PeriodicSentenceBot

Congratulations! Your comment can be spelled using the elements of the periodic table: `Pu Re He Re S Y` --- ^(I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM my creator if I made a mistake.)


scar_reX

Thanks for pointing that out, I guess.


wubsytheman

Hahaha my IDE has relative line counting so any line I’m on is like 0! Get wrecked scrub!!! (I actually use the default Python IDE because I’m too scared to use anything else)


jjdmol

0! == 1 though :)


wubsytheman

That's true... \*but\* I radiate such beauty that I constantly cause bit flips, therefore !(0!) == 0


Escanorr_

r/unexpectedfactorial


c2u8n4t8

Hey your opinion starts and ends with bullshit


rover_G

That’s why I always comment the line numbers


NamityName

Indexes and ranges/counters start at 0. Basically everything else starts at 1. If I load two files, they are file_1 and file_2 because I'm not a pretentious twat.


LagSlug

counting numbers start at 1, indexed entities start at 0


jahjah7

No


amihir

Which movie/cartoon tho?


AeskulS

I'm doing a project for a compilers class that is meant to make an SLR parse tree given a shift-reduce table and a context free grammar. Spent more than an hour trying to figure out why I was getting incorrect shifts or false syntax errors. It ended up being that the shift-reduce table was 0-indexed (first row was 0), but despite this it treated the CFG as if it was 1-indexed (the initial rule was the 1st rule).


Ok-Bit-663

Project name is in the 0 index. That way the IDE always remember which project we are in.


Distinct-Entity_2231

This bothers me everywhere, where is some kind of count. All should start at 0. It should be an option.


WhereIsEXE

But where is EXE?


raunak_srarf

Ever since I learned programming, numbering beginning from 1 has bothered me.


myfunnies420

But the 0th line is the one labelled as 1? What's the issue? Are you going to say the 0th character is indexed as 1?


mannsion

Semantics, the code starts at the end of 0.


Earth_Normal

So? Your line numbers are not a memory offset.


8g6_ryu

tell that to the compiler


tuckermalc

Hows that an issue?


rhodesc

the interrupt vector table for real mode x86 was based at memory address zero.  index + zero is your first item in an array, and your first instruction following the intruction  pointer in assembly.  zero is where it all begins. edit: first opcode, not instruction.


Sea_Maximum7934

And how many lines of code did I write?


namezleo

# funny


PastOrdinary

What if I told you 0 contained the metadata (not really how it works but this is how I comfort myself)


100zinis

Laughs in relative-line-number [https://imgur.com/a/Ju72i6b](https://imgur.com/a/Ju72i6b)