#Changing the default integer literal type.

1 messages ยท Page 1 of 1 (latest)

oblique tinsel
#

No.

#

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)

calm cloud
#

mind blown

oblique tinsel
#

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.

calm cloud
#

for i in uint(0)..<10

oblique tinsel
#

Another quesiton to ask is, why do you think I made the language to use signed by default?

calm cloud
oblique tinsel
#

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.

calm cloud
#

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

oblique tinsel
#

And I have been vindicated.

calm cloud
#

you mean the bug?

oblique tinsel
#

You have missed 0

#

So I was wanting 5, 4, 3, 2, 1, 0

calm cloud
#

๐Ÿ’€

oblique tinsel
#

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--) {
    ...
}
calm cloud
#

Here is how graphitemaster would do it

for (size_t i = size - 1; i < size; i--) {
    // ...
}
oblique tinsel
#

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.

tacit cove
#

@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.

oblique tinsel
#

Whilst:

for (int i = 5; i >= 0; i--) {
    ...
}

is extremely clear

calm cloud
#

Unclear code is not worth having an unsigned religion

oblique tinsel
#

Then I hope this stays a hobby for you.

calm cloud
#

Well it does hide whatever the heck you are doing in your program for others I suppose

oblique tinsel
#

Then don't write code like that.

#

Others have to read your code.

#

And comprehend it.

#

And not make bugs with it.

tacit cove
#

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.

oblique tinsel
#

Good luck!

calm cloud
#

idk what "unsigned gang" is but I use unsigned where ranges are only 0..N

#

to prevent unnecessary checks

tacit cove
#

Stop embarrassing our side. Go build cool software. Then promote unsigned when you have more experience. I believe in you. Good luck.

calm cloud
#

but I always convert them to signed when I have to subtract

oblique tinsel
#

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.

tacit cove
#

I buy that. In my language I do unsigned by default and signed values are only used when I want "bidirectional" numbers.

oblique tinsel
#

I can tell you all of the arguments for unsigned by default quite easily.

#

They are practically wrong.

tacit cove
#

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.

oblique tinsel
#

Issues with signed:

  • INT_MIN / -1
  • INT_MAX % -1
  • INT_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))
reef gulch
#

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.

oblique tinsel
#

What are you trying to express with your code?

tacit cove
#

Bro stop. I'm going to have to advocate for your banning in a second.

#

I don't want that.

calm cloud
#

You talk about practical application of number ranges, and then give the most batshit crazy code that nobody has idea of what it does

tacit cove
#

Your not convincing.

#

The above snippet always does nothing.

#

Be more pro, people will listen then.

reef gulch
#

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

oblique tinsel
#

You demonstrated to me earlier that that was not the case for you.

tacit cove
#

@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

calm cloud
#

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

oblique tinsel
#

You've just contradicted yourself.

calm cloud
#

Or it will have subtle bugs that you won't notice for a long time.

oblique tinsel
#

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.

tacit cove
#

Your asking to be banned.

#

Seriously.

calm cloud
#

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.

tacit cove
#

You may think it's good faith. But the way it arrives is not contributing.

calm cloud
#

if I am wrong about things, my program will not run
This is just a false statement

#

Programs can have subtle bugs.

tacit cove
#

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.

calm cloud
#

For practical purposes, do you want programmers to be using a complete and bug-free model or an incomplete and bug-prone model?

tacit cove
#

We have heard what you have to say.

#

Now stop and just be a part of the discord.

reef gulch
#

In fairness to them, this is true.

tacit cove
#

Okay then. With that said let's have no more activity in this thread.

#

True

gentle prairie
#

that was... interesting conversation