Coding Standards and Best Practices
50.1 Naming Conventions
Classes, Structures, Modules, Enums I + PascalCase Methods, Properties, Events CalculateTotal, OrderPlaced Parameters, local variables orderTotal, customerId Async suffix Is/Has/Can prefix IsActive, HasErrors
Avoid Hungarian notation in new code (strName, intCount), though WinForms control prefixes (btn, txt, lbl, cbo, dgv) are still common and acceptable.
50.2 Best Practices Checklist
✅ Option Strict On, Option Explicit On (project-wide).
✅ Use AndAlso/OrElse, IsNot Nothing, String.IsNullOrWhiteSpace.
✅ Use Try...Catch (not On Error). Catch specific exceptions. Use Using for disposables.
✅ Use generic collections. Avoid ArrayList, Hashtable, and Collection in new code.
✅ Prefer .NET methods (.Length, .Substring) over legacy VB functions (Len, Mid) for consistency and 0-based indexing.
✅ Keep methods small and single-purpose. Separate UI, business logic, and data access (layers/MVVM).
✅ Use interfaces and dependency injection for testability. Write unit tests.
✅ Document public APIs with XML comments (''').
✅ Use Async/Await for I/O. Keep UI threads responsive.
✅ Use source control (Git), code reviews, and analyzers (.editorconfig, Roslyn analyzers).
❌ Don't use GoTo, On Error Resume Next, or global mutable variables.
❌ Don't leave Option Strict Off project-wide (isolate late binding).
❌ Don't put business logic in form event handlers.
❌ Don't swallow exceptions (Catch ex As Exception with an empty body).
❌ Don't use the default form instances (Form2.Show()) in large apps. Create instances explicitly.
50.3 Code Analysis
.editorconfig rules for VB style, Roslyn analyzers (Microsoft.CodeAnalysis.NetAnalyzers), <TreatWarningsAsErrors>, <AnalysisLevel>latest</AnalysisLevel>, and SonarQube/SonarLint (VB.NET rules).