#Changing the default integer literal type.
1 messages ยท Page 1 of 1 (latest)
Odin uses signed by default everywhere.
But to make it clear, The default type for an integer literal means that 1 if not specified will be have a default type of int. 1 on its own is an "untyped integer".
But you can of course do this:
x: uint = 1
or
x := uint(1)
Also, Odin does not suffer from the same issues as C either with regards to integers.
All integers have well defined behaviour.
Why do you "strongly prefer using uint"?
Why?
The difference between 2^63-1 and 2^64-1 is a lot to you?
int is 64-bit on 64-bit platforms.
Odin and its core library uses signed by default.
What you were asking is kind of like asking "can I remove the gendered nouns from French because I don't have them in English?"
It doesn't really make much sense ๐
That's just how the language is.
No
The entire language and core library assumes this.
You'd break everything.
I'd ask yourself why you "strong prefer unsigned".
What?
Among other things, memory does not map to signed values
That isn't true.
Memory doesn't have types.
The computer has no concept of types.
That's irrelevant.
Fun fact, pointers on AMD64 are actually signed (for comparisons)
mind blown
But why do you "strongly prefer using uint"?
You told me you don't know.
I can express all programming problems I want to solve using signeds.
That's not an argument.
How would you write a for loop that iterates down to zero (in the language of your choosing)? (I know how it's done, I am asking you)
I despise the idea of being forced to use signeds
WHY?! And you are not forced.
I read it in context.
I also asked a practical question before.
How would you write a for loop that iterates down to zero (in the language of your choosing)? (I know how it's done, I am asking you)
Show me the code.
Don't describe it.
for i in uint(0)..<10
Another quesiton to ask is, why do you think I made the language to use signed by default?
If you want an index, you likely want to do math with that index, and for math you need to convert it to signed?
Kind of. I've seen so many bugs caused by unsigned-by-default practices which has lead me to be in the signed-by-default camp.
And all of the "cope" for unsigned-by-default leads to weird things.
Which is why I am still asking for that question regarding for loops that iterate down to zero.
There's a bug in that code.
then deal with "clutter", you are the only person who wants to use unsigned by default. I use unsigned where my number range cannot go below zero, but for any math operations that require subtractions, I would just underflow if I used uint, leading to subtle bugs.
oh, as a proof, your code has a subtle bug
And I have been vindicated.
you mean the bug?
๐
My position is vindicated again.
And the common way of doing this does not look like that.
It looks like this:
for (unsigned i = 5; i <= 5; i--) {
...
}
Here is how graphitemaster would do it
for (size_t i = size - 1; i < size; i--) {
// ...
}
And your approach is bug prone, not easily refactorable, and insane to read.
In fact the example I gave of how you normally do it with unsigned integers is pretty bizarre already to read, especially when scanning code.
@snow saffron You are right. But you are a fool. Like the christian who thinks god sits in the clouds where the aeroplane flies. Unsigned is the way but you don't know how to walk it correctly.
Whilst:
for (int i = 5; i >= 0; i--) {
...
}
is extremely clear
Unclear code is not worth having an unsigned religion
Then I hope this stays a hobby for you.
Well it does hide whatever the heck you are doing in your program for others I suppose
Then don't write code like that.
Others have to read your code.
And comprehend it.
And not make bugs with it.
I am a member of the unsigned gang. So you are correct in my opinion to prefer unsigned. But you've not been very convincing at all and have only scored points for team signed.
Good luck!
idk what "unsigned gang" is but I use unsigned where ranges are only 0..N
to prevent unnecessary checks
Stop embarrassing our side. Go build cool software. Then promote unsigned when you have more experience. I believe in you. Good luck.
but I always convert them to signed when I have to subtract
And my first reply was "No."
And that's fine.
I was trying to understand why you wanted it.
And your replies have actually vindicated my rationale behind using signed by default.
I did ponder.
I used to be in the "unsigned by default" camp.
I buy that. In my language I do unsigned by default and signed values are only used when I want "bidirectional" numbers.
I can tell you all of the arguments for unsigned by default quite easily.
They are practically wrong.
But what you must learn @snow saffron is that these are religious wars. Reason cannot win, only force.
Bill is a signer. Therefore Odin is signed by default. You just have to accept that.
When you make your own language you can make unsigned the default.
Sure.
But I would not advice hiring a hit man to take out @oblique tinsel . He doesn't forget and is a force to be reckoned with.
Issues with signed:
INT_MIN / -1INT_MAX % -1INT_MAX - INT_MIN
Checking for addition overflows
if (x + y < x)// works in unsigned, not in signed
For signed:if ((b > 0 && a > INT_MAX - b) || (b < 0 && a < INT_MIN - b))
I take it then that you actually cannot use max(uint) as a valid value in this case then?
Since if your value was equal to it to begin with, the loop exits immediately and is thus a bug.
What are you trying to express with your code?
Bro stop. I'm going to have to advocate for your banning in a second.
I don't want that.
You talk about practical application of number ranges, and then give the most batshit crazy code that nobody has idea of what it does
Your not convincing.
The above snippet always does nothing.
Be more pro, people will listen then.
That is buggy if you're iterating over an array and want to include the 0-th item.
Because it won't run that iteration; it'll only do down to the 1-th one.
I'm not sure what you mean by that
You demonstrated to me earlier that that was not the case for you.
@snow saffron If you want to be in the unsigned squad. This is the correct loop.
// 0 -> 4
for(u32 i = 0; i < 5; i++)
{}
// 4 -> 0
for(u32 i = 5 - 1; i < 5; i--)
{}
When you wrap past zero you end up above max and so the loop stops
Bill is vindicated, your idea makes things unclear.
Even to yourself.
Computer does not care whether you use signed or unsigned, it works either way,.
It's not an argument about hardware.
Computer doesn't even HAVE types
You've just contradicted yourself.
Or it will have subtle bugs that you won't notice for a long time.
If your mental model sticks to the real model of your computer, you should be fine. There shouldn't be any inconsistencies.
you're asking me to be correct on the fly. When I program, I can test myself, and hold my self to the maximum standard of being actually correct.
This means you don't have a mental model of the real model of your computer.
You are being an arsehole.
As in "If your mental model sticks to the real model of your computer, you should be fine". Your OWN mental model does not. Not even talking about people who don't think about this.
You may think it's good faith. But the way it arrives is not contributing.
if I am wrong about things, my program will not run
This is just a false statement
Programs can have subtle bugs.
I saying you should quit arguing so that you can be a part of this discord.
Stop talking about it.
Nothing is more annoying than someone who keeps going on about their perspective.
For practical purposes, do you want programmers to be using a complete and bug-free model or an incomplete and bug-prone model?
In fairness to them, this is true.
that was... interesting conversation