r/visualbasic • u/user_8804 • May 19 '21
What is your code style regarding blank lines?
None? Blocks of one idea? Padded outside and/or inside keyword blocks (if, using, sub, select)
Where to put blank lines? I am honestly never satisfied with my coding style and I couldn't find any convention regarding this
3
u/chacham2 May 20 '21
There are many different styles. The important thing is to be consistent within any given project. If that makes sense to you, i'd just try different styles until i found one i liked.
Personally, I put blank lines between steps that do not deserve a separate function due to the logic involved. Is hard to explain because it's just a feeling.
3
u/dwneder May 20 '21
The rests in music are music too.
The empty space in program code is just as important.
1
u/revennest May 20 '21
Same as many other VB.Net user, I also view it as paragraph but I add 2 more case to instead blank line, in case if that part of code take much time to read then normal, other case is it already 5 lines and it still easy to read even if I instead blank line between it.
Example.
Function Q_rsqrt_test(Base As ULong,
Correnctness_reccord As Dictionary(Of ULong, List(Of Single))) As ULong
Dim DT(Correnctness_reccord.Count - 1), Y As Single,
Number = 1.0F / Base
Y = (&H5F3759DF - (Number.as(Of Integer) >> 1)).as(Of Single)
Dim R = 1.0F / MathF.Sqrt(Number),
I = 0UL
Const Limit = 10000UL
Do Until Y = R
Y = correcting_result(Number, Y)
If I < DT.Length Then DT(I) = deviation(R, Y)
I += 1
If I = Limit Then
For N = 1 To Correnctness_reccord.Count
Correnctness_reccord(N).Add(DT(N - 1))
Next
Return I
End If
Loop
Return I
End Function1
u/backtickbot May 20 '21
1
u/craigers01 May 20 '21
Personally, I like to isolate a block of code that performs a task. If my function “cleanup”: deletes all temp files; deletes old records from the database; etc. I comment each block of code and space then apart.
1
u/cesto19 May 21 '21
What makes it easier to read, I suppose. Kind of how you'd break down a paragraph
7
u/EkriirkE VB 6 Master May 19 '21
I use blank lines between separate stages of code. Nest indents following if/else/end while/wend do/loop etc code blocks