twinbasic / lang-design

Language Design for twinBASIC
MIT License
11 stars 1 forks source link

Left-typed variable declaration (Dim) #16

Open Kr00l opened 3 years ago

Kr00l commented 3 years ago

Is your feature request related to a problem? Please describe. This idea comes from twinbasic/lang-design#44 where Olaf raised a "nice to have" feature. (https://github.com/WaynePhillipsEA/twinbasic/issues/79#issuecomment-825377802)

Describe the solution you'd like To specify the "As [Type]" only once on the left side and have then all the assigned variables on the right side. Dim As Long i, j, k

Additional context This seems to be a feature from FreeBasic. Additional question whether or not to allow identifier type character on this left-typed declaration. E.g. Dim & i, j

bclothier commented 3 years ago

FWIW, I wouldn't want the type declaration characters to be used as a shortcut for the data type's name. They have their uses but only on literals. For example, this is helpful:

Const Foo As Long = &H8000  '-32678
Const Bar As Long = &H8000& '32678

That's the only place we should see type declaration characters in a modern BASIC language. Any other uses of the type declaration character should be discouraged, IMO.

mansellan commented 3 years ago

I do quite like the first proposal though, seems pretty elegant!

Kr00l commented 3 years ago

I do not like the proposal Dim & i, j here as well. Just put it there for completeness.

Because some folks declare the variables like this. Dim i&, j&, k&

bclothier commented 3 years ago

Yeah, those would be a good candidate for compiler warning or even auto-expanding (e.g. type Dim i& => VSC rewrites into Dim i As Long -- you get to type less but still write clear code).

That said, I agree and like the first part of proposal as well.

Greedquest commented 8 months ago

How will this play with existing Dim statement?

Dim As Long i, j, k, v As Variant
Dim As Long i, j, k, As Double x, y
Dim As Long i, j, k As Double, x, y
EduardoVB commented 8 months ago

An error? Once you defined the type at the start, then all the line is of that type. It avoids misunderstandings. If you want, you can place a : and add another Dim with another type. (my opinion)