Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type suffix for Byte and SByte types #213

Open
AnthonyDGreen opened this issue Dec 2, 2017 · 14 comments
Open

Type suffix for Byte and SByte types #213

AnthonyDGreen opened this issue Dec 2, 2017 · 14 comments
Labels
Approved-in-Principle LDM Considering LDM has reviewed and we think this has merit Proposal

Comments

@AnthonyDGreen
Copy link
Contributor

Today in VB all the integral literal types have a type suffix (S, US, I, UI, L, UL). There isn't one for byte, which is mostly fine, but it's still incomplete. And for the Option Strict crowd this forces them to write CByte(-1). We talked about how to change the language to avoid this error but after some thought I concluded that the error was not in the language for implicitly converting -1 (implicitly an Integer) to the SByte type but with Option Strict for being stupid. C#, for example, doesn't forbid this implicit conversion. We should probably fix Option Strict to not report an error for this conversion but that's orthogonal to whether there's a native syntax for 8-bit integer types in the language.

All that being said, we talked it over in the LDM some time ago and decided to just add suffix characters for these two types. After much debate we settled on UB for unsigned bytes and SB for signed bytes. F# for example uses Y and UY but that's not very intuitive. The reason we picked these is two fold:

  1. Because all of the other integral types are signed as standard (CLS-compliant) and use an extra character for the unsigned types we weren't sure if we should go for consistency and use B and UB, or if we should prefer the CLS-compliant unsigned byte and put the extra character on the signed byte, B and SB.
  2. B is a valid digit character in the hexadecimal base. We could just restrict these characters to decimal but hexadecimal byte literals seem like an awfully common use case of the byte type.

I guess the counter argument would be that since bytes already take up so few characters adding two more to the end starts to really obscure their value, e.g. &HFFUB or 255UB. It seems like a harmless and natural extension to the language though.

@Bill-McC
Copy link

Bill-McC commented Dec 2, 2017 via email

@reduckted
Copy link
Contributor

@Bill-McC, # is a type suffix for Double, so that wouldn't work very well.

I'm happy with UB and SB, but isn't this a duplicate of #111?

@Bill-McC
Copy link

Bill-McC commented Dec 2, 2017 via email

@paul1956
Copy link

paul1956 commented Dec 3, 2017

I hate, haven't used and don't recommend any of these suffixes because as was said I just have to look them up and Google/Bing aren't good at looking up #. What about a code fix for existing code and autocorrect for new code for people that don't like to type. maybe the formatter should just fix this on load. I found if funny that there is a change request for C# to replace several symbols with words (&& with And...) I almost replied just use VB. This is making VB more C# like and not in a good way. The beauty of VB is any programmer can read the code and intent is very clear without having to look stuff up.

@reduckted
Copy link
Contributor

I hate, haven't used and don't recommend any of these suffixes

Ditto. Well, almost. I do use # sometimes (only after the literal value) because it's stuck in my muscle-memory from VB6 days. Maybe I need to write an analyzer to enforce R instead of #.

But regardless, it's part of the language, so it won't be going anywhere (although there are a number of legacy things I'd love to see die!)

@Echo-8-ERA
Copy link

Would be nice to see them depreciated and eventually removed, freeing up their reuse in new syntax additions.

@KathleenDollard KathleenDollard added the LDM Considering LDM has reviewed and we think this has merit label Aug 1, 2018
@KathleenDollard
Copy link
Contributor

I have some concern about &B at the start of a number meaning binary and B at the end meaning Byte.

I don't know what else we would use, but when this was proposed binary literals ($B) weren't a thing.

I do not know what other letter we would use for Byte. No other prefixing character is also a suffix.

@craigajohnson
Copy link

craigajohnson commented Aug 1, 2018

While you are considering this, could we also please consider the GUID literal proposal? This would be particularly useful when decorating with attributes and not having to wrap the literal as a string and convert. #27

@AnthonyDGreen
Copy link
Contributor Author

@KathleenDollard I agree that just B would be wrong. It wouldn't work for hex:

' Is this an integer hex for decimal 27 or byte hex for decimal 1?
Dim value = &H1B

The proposal was for SB for signed-byte and UB for unsigned-byte to avoid that problem and others. They were originally discussed when &B binary literals were first discussed/prototyped/previewed (pre-VS2015 RTM) but not when binary literals were finally released (VS2017).

Again, I code with Strict Off and am fine with implicitly converting integer literals to Byte, this is only something for the crowd that likes to be extra explicit about literal data types but finds CByte(255) too verbose.

@KathleenDollard
Copy link
Contributor

@AnthonyDGreen Thanks for clarifying!!! We were bouncing between three issues when we reviewed this and over looked that. UB/SB solve the problem.

@KathleenDollard
Copy link
Contributor

@craigajohnson Could you ping #27. It's quite old so will be a while before it comes up for review otherwise.

@AdamSpeight2008
Copy link
Contributor

Note, if we do add this we're also need to update some assertions that state that visual basic doesn't support them.

@AnthonyDGreen
Copy link
Contributor Author

AnthonyDGreen commented Aug 8, 2018

@AdamSpeight2008 that Visual Basic doesn't support what--what is "them" in your sentence?

@AdamSpeight2008
Copy link
Contributor

@AnthonyDGreen
Murphy has deemed that I can not locate the assertion, but I did see one that listed all of the types / suffixes. Unsigned Byte wasn't in that list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved-in-Principle LDM Considering LDM has reviewed and we think this has merit Proposal
Projects
None yet
Development

No branches or pull requests

8 participants