Results 1 to 4 of 4

Thread: Sub/Function separators

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    Hi,
    Can I set the IDE to automatically print separators (line) between functions/subs? It shows the lines, but how can I print them? I found myself doing this manually for all subs so they look more readable.

    Thanks
    Thanks

    Tomexx.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    anyone?
    Thanks

    Tomexx.

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    You don't need any lines to make it readable.
    Just follow a few rules and you won't ever have readability problems again.

    Rule #1: Always have at least one empty line between procedures.
    Code:
    ' Unreadable:
    Sub Proc1()
        ' Stuff
    End Sub
    Sub Proc2()
        ' Stuff
    End Sub
    Sub Proc3()
        ' Stuff
    End Sub
    
    ' Readable:
    Sub Proc1()
        ' Stuff
    End Sub
    
    Sub Proc2()
        ' Stuff
    End Sub
    
    Sub Proc3()
        ' Stuff
    End Sub
    Rule #2: Do not use variable-declaration symbols. They're ugly.
    Code:
    ' Unreadable:
    Dim X%, Y&, Z!, A@, B$, C#
    
    ' Readable:
    Dim X As Integer, Y As Long, Z As Single, A As Currency, B As String, C As Double
    
    ' If you have many variables of the same type, you can use a shortcut:
    ' Instead of:
    Dim A As Long, B As Long, C As Long, D As Long
    Dim E As String, F As String, G As String, H As String
    Dim I As Double, J As Double, K As Double, L As Double
    Dim M As Boolean, N As Boolean, O As Boolean, P As Boolean
    
    ' You can use:
    DefLng A-D
    DefStr E-H
    DefDbl I-L
    DefBool M-P
    
    Dim A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P
    Rule #3: Always indent the code depending on the context. Also, it is good to leave empty lines between lines of code. For example, I always separate the Dim lines from the other lines, etc.
    Code:
    ' Unreadable:
    Sub MySub()
    Dim X As Integer, Y As Integer, Z As Integer
    For X = 1 To 10
    For Y = 1 To 10
    For Z = 1 To 10
    Debug.Print "(" & X & ", " & Y & ", " & Z & ")"
    Next Z
    Next Y
    Next X
    End Sub
    
    ' Readable:
    Sub MySub()
        Dim X As Integer, Y As Integer, Z As Integer
        
        For X = 1 To 10
            For Y = 1 To 10
                For Z = 1 To 10
                    Debug.Print "(" & X & ", " & Y & ", " & Z & ")"
                Next Z
            Next Y
        Next X
    End Sub
    Rule #4: Do not use the : (colon) operator. It looks ugly. Also, try to put several Dim lines depending on the data type.
    Code:
    ' Unreadable:
    Dim DoIt As Boolean, X As Integer, Y As Integer, Z As Integer
    
    Function MyProc() As Integer
        If DoIt Then Y = 27: Z = 3: DoIt = False: Call SomeOtherProc: X = SomeFunction: MyProc = X + Y
    End Sub
    
    ' Readable:
    Dim DoIt As Boolean
    Dim X As Integer, Y As Integer, Z As Integer
    
    Function MyProc() As Integer
        If DoIt Then
            Y = 27
            Z = 3
            DoIt = False
            Call SomeOtherProc
            X = SomeFunction
            MyProc = X + Y
        End If
    End Function
    
    ' Also readable:
    Dim DoIt As Boolean
    Dim X As Integer, Y As Integer, Z As Integer
    
    Function MyProc() As Integer
        If Not DoIt Then Exit Function
        
        Y = 27
        Z = 3
        DoIt = False
        Call SomeOtherProc
        X = SomeFunction
        MyProc = X + Y
    End Function
    If you still absolutely must print the lines... Do it manually.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    10 points to Yonatan!

    Code:
    ' You can use:
    DefLng A-D
    DefStr E-H
    DefDbl I-L
    DefBool M-P
    Because that helps me alot
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width