Proposal: Make VB great again!
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
I like this language much, but feels to be kinda outdated vs many popular languages, so these are my proposals (they've been probably suggested before)
1) Accept an **Out** keyword for methods arguments, that works like **out var** in c#, this would be really useful. Like
```vb
Sub SomeMethod()
Console.WriteLine("Type a number between 0 and 255")
If Byte.TryParse(Console.ReadLine, Out Dim b) Then Console.WriteLine($"The input value is {b}!")
Console.ReadLine()
End Sub
```
or (and I personally like this one)
```vb
Sub SomeMethod()
Console.WriteLine("Type a number between 0 and 255")
If Byte.TryParse(Console.ReadLine, Out b) Then Console.WriteLine($"The input value is {b}!")
Console.ReadLine()
End Sub
```
2) Allow 1 line subs/functions like in c#!
```vb
Sub Log(text As String) => Console.WriteLine(text)
Function Sum(a As Integer, b As Integer) As Integer => Returns a + b
```
`=>` could be used, or maybe `>>`
3) Shorts for lambdas, sometimes `Function(x)` makes the code kinda long, for better reading I suggest to allow us to put `F(x)` or `f(x)` instead, like:
```vb
Function SomeMethod(names As String(), filter As String) As String
Return names.First(f(x) x = filter)
End Function
```
or
```vb
Dim someFunction = f(x) x ^ 2+ 1 ' Function(x) x ^2 + 1 is still nice to read, but I'd prefer it shorter
Console.WriteLine(someFunction(5)) ' Expected Output: 26
```
4) Auto implemented interfaces
Long code is really annoying, I don't like the fact that every single method (and even properties) must have `Implements blablabla`, in c# only the class needs to implements, methods are automatically implemented without any special keyword. Just saying. Taking an example from a public repository:
```cs
public class SocketRole : SocketEntity, IRole
{
public Color Color { get; private set; }
public bool IsHoisted { get; private set; }
public bool IsManaged { get; private set; }
public bool IsMentionable { get; private set; }
public string Name { get; private set; }
}
```
in VB
```vb
Public Class SocketRole : Inherits SocketEntity(Of ULong) : Implements IRole
Public Property Color As Color Implements IRole.Color
Public Property IsHoisted As Boolean Implements IRole.IsHoisted
Public Property IsManaged As Boolean Implements IRole.IsManaged
Public Property IsMentionable As Boolean Implements IRole.IsMentionable
Public Property Name As String Implements IRole.Name
End Class
```
this is way annoying and discourages to have big interfaces (like Discord.NET's ones) as the code will end up being a big wall of text. It's good to be explicit, but this is too exaggerated.
Also, something about properties I will mention in the next point (`private get/set`)
5) Properties
Allow us to have a short syntax for private get/set, in c# we can:
```cs
string someProperty { get; private set; }
string someOtherProperty { private get; set; }
```
meanwhile in VB...
```vb
Private _someProperty As String
Private _someOtherProperty As String
Property someProperty As String
Get
Return _someProperty
End Get
Private Set(value As String)
_someProperty = value
End Set
End Property
Property someOtherProperty As String
Private Get
Return _someOtherProperty
End Get
Set(value As String)
_someOtherProperty = value
End Set
End Property
```
I thing it would look good as `Property someProperty As String { Get, Private Set }` in the case I want a private get/set
6) Some short for += 1 and -= 1 (aka ++ and --)
Because... why not?
7) optional counter for While and Do/Loop loops.
example:
```vb
While someCounter < someNumber
'Do stuff
someCounter += 1
End While
```
could be:
```vb
While (someCounter < someNumber, someCounter++)
'Do stuff
End While
```
or
```vb
Do
'Do something
Value += 1
Loop Until Value = 1337
```
could be
```vb
Do
'Do something
Loop Until Value = 1337, Value++
```
inb4 "you can use For/Next": Yea, but the local variable of a For/Next loop cannot be changed while in a while and do/loop it can be changed as these loops only cares that the condition is true or false. Which sometimes it could be useful to manipulate the counter inside the loop but keep increasing it in each iteration.
8) GoTos in Select Case statements
Well, select case is basically a cool looking version of GoTos, but much better (even better than c# switch)
I think it would be a great improvement if we were allowed to use GoTo Case, for example:
```vb
Select Case Error
Case ErrorType.Something
'Some Error Handling logic
Case ErrorType.Another
'Some Error Handling logic
If someConditionIsMeet Then GoTo Case ErrorType.Something
Case ErrorType.SomeOther
'Some Error Handling logic
End Select
```
There are some scenarios where this would be useful.
```vb
'Scenario example
Select Case Value
Case 1
'Do some stuff
Case 2
'Do some stuff
Case 3 To 8
'Do some stuff... But...
If somethingHappens Then GoTo 9 ' To make this work, this would be like an Exit Select and execute again Select statement with a local secret value = 9, somethingHappens could be anything, not just an error, like the expected value of some method returned something that requires Case > 8 to execute instead of calling a method with the same logic
Case > 8
' I know I can, for example, Case 8, 9, 11, but sometimes I think a GoTo could make few things easier in certain kind of scenarios
Case Else
End Select
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.