Results 1 to 4 of 4

Thread: Rules of Thumb

  1. #1

    Thread Starter
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Resolved Rules of Thumb

    Talking about rules of thumb, i know a few programmers and most of them are so bad at it, maybe a few rules of thumb could help people who have bad programming practise.

    • Always comment your code well so you can return to your code anytime and still understand it fully


    • Always use descriptive names for controls and variables, also use naming conventions so you can know the type of control or variable.


    • You can use regions in your .NET IDE to separate code. E.g. I do it like this. (see Figure 1.0)
      VB Code:
      1. #Region "Public Declaration"
      2.  
      3. #End Region
      4.  
      5. #Region "Form Code"
      6.  
      7. #End Region
      8.  
      9. #Region "Sub Procedures"
      10.  
      11. #End Region
      Your regions can then be expanding or contracted so that you can only see the code for regions you have expanded, this helps me focus only on the code i want to.


    Anybody got any more rules of thumb?
    Attached Images Attached Images  
    Last edited by x-ice; Jun 29th, 2005 at 08:39 PM.

  2. #2
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Rules of Thumb

    "Rules of thumb" may be useful but sometimes you can't get people to agree upon what should be considered a rule of thumb. Sometimes s are set by the company you work with (or your boss) and that can change.

    Quote Originally Posted by x-ice
    Comment every line of code, so you can return to the code later and know exactly what it does. (Only comment lines that need to commented, if its obvious then leave it
    That's really confusing since what's obvious to you might not be obvious to me.

    Quote Originally Posted by x-ice
    When using constructs (IE, IF...THEN...ELSE, DO...LOOP, SELECT CASE, etc...) indent all code inside the construct by 1 tab space, therefore it becomes alot easier to read.
    I wouldn't really call this a rule. Most IDEs do that anyway nowadays.

    Quote Originally Posted by x-ice
    If you are setting multiple properties for the same control use a WITH construct.
    VB Code:
    1. With textbox1
    2.     .Enabled = True
    3.     .Locked = True
    4.     .Text = "bla"
    5. End With
    I know lots of people who hate WITHs. If your statement block is large, having a .SomeProperty somewhere inside the block can be confusing. Also, you can't copy-paste the .SomeProperty to the Watches window since the IDE will complain that it's inadequately qualified.

    I would think that it's better to focus on more fundumental things (like "Always use meaningful names instead of TextBox1" etc).
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Rules of Thumb

    Probably basic ones but, for every class/module...

    • Always use Option Explicit On


    • Always use Option Strict On


    • Declare your variables with the narrowest scope needed.
      VB Code:
      1. For [color=black]i[/color] As Integer [color=black]= 0[/color] To [color=black]9[/color]
      2.     'Do something
      3. Next
      4.  
      5. 'Or
      6.  
      7. Private Sub [color=black]Button1_Click[/color](ByVal [color=black]sender[/color] As [color=black]System.Object, [/color][color=navy]ByVal[/color] [color=black]e[/color] As [color=black]System.EventArgs)[/color] Handles [color=black]Button1.Click[/color]
      8.     Dim [color=black]i[/color] As Integer
      9.     For [color=black]i= 0[/color] To [color=black]9[/color]
      10.         'Do something
      11.     Next
      12.     [color=black]MessageBox.Show(i.ToString & " Items Added???")[/color]
      13.     For [color=black]i = 0[/color] To [color=black]4[/color]
      14.         'Do something else
      15.     Next
      16.     [color=black]MessageBox.Show(i.ToString & " Items Changed???")[/color]
      17. [color=navy]End Sub[/color]
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Re: Rules of Thumb

    Quote Originally Posted by ntg
    "Rules of thumb" may be useful but sometimes you can't get people to agree upon what should be considered a rule of thumb. Sometimes s are set by the company you work with (or your boss) and that can change.


    That's really confusing since what's obvious to you might not be obvious to me.


    I wouldn't really call this a rule. Most IDEs do that anyway nowadays.


    I know lots of people who hate WITHs. If your statement block is large, having a .SomeProperty somewhere inside the block can be confusing. Also, you can't copy-paste the .SomeProperty to the Watches window since the IDE will complain that it's inadequately qualified.

    I would think that it's better to focus on more fundumental things (like "Always use meaningful names instead of TextBox1" etc).
    OK, i get you, i've changed my post in response to your reply.

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