Topics
By Date
<
>
November 2024 |
| | | | | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
| | | | | | |
Style
50 Reasons Why .NET is Better Than VBA
Type Safety
- PLEASE, for the love of dog, type-safe collections!
- In VBA, you are not required to declare the type of a parameter. This makes it possible to overlook this step, and the Variant you'll get by default has poor performance.
The Library
- A comprehensive and modern library, with consistent interfaces and an OOP paradigm.
- A Timer class for quick and easy profiling.
- VBA's Dictionary is case-insensitive for the Exists() method, but case-sensitive (by default anyway) for Item()!
- Better text streaming; VBA's TextStream class is an obscene memory hog.
- .NET has tidier, more rational controls (e.g., ComboBox.Items.Clear(), and the ability to populate a ListBox with objects).
Object-Oriented Programming
- Inheritence. Not necessary in every project, but hugely useful when needed.
- Secure alternatives to module-level variables.
- Constructors with parameters.
Language Capabilities
- VBA's largest integer data type is a signed 32-bit, so values greater than two billion (e.g., phone numbers), have to be stored as Double.
- .NET supports true multithreading.
- The ability to compile utilities into a DLL.
- Static functions, so helpful for factory methods.
- Simple passing and returning of arrays.
- Templates.
- SQLParameters, for more robust handling of strings and dates and reduced risk of injection.
- Donated static methods (what are these called again?).
- Methods with variable parameter lists.
- Better string functions.
- Flexible "for" structures.
- Custom iterators.
- VBA passes parameters by reference by default, making it easy to accidentally cause an obscure side effect.
- Fail-fast logical evaluation.
- The yield command, for simple and efficient looping over non-standard collections.
- Nullable types are a great convenience when working with databases.
- Speed. VBA is astonishingly slow at simple tasks like reading from an ADO source and writing to local, or reading from local into memory.
- VBA does not implicitly cast even when it's perfectly safe: you must manually cast an int to a long, for example.
Exception Handling
- Stack traces!
- Specific catch blocks.
- Easy recursing for nested exceptions.
- If VBA breaks at an Err.Raise, you cannot change or comment out the command. Nor can you simply swallow the error and continue. Your only option is to exit and start over.
The IDE
- Refactoring tools.
- Better navigation: more robust go-to-definition and better file setup.
- Code folding.
- Line numbers in the IDE.
- A stable IDE. Access gets flaky sometimes, and specifically has a bad habit of polling all properties for the Locals window, even though some may not be quick or low-impact. The workaround is to put these into methods instead. Worst of all is when it actually corrupts your code; the workaround is frequent backups and small modules. This is NOT a problem for real languages where the code is stored in simple text files.
- Integration with Visual SourceSafe. As awful as it is, VSS is better than nothing.
- Automatic TODO lists.
- Warnings for unused params and locals are very handy.
Cosmetic Preferences
- Using "return" rather than a function's name.
- Being able to declare and assign a variable in one statement will be a relief.
- Block-local variables.
- The "continue" command for short-circuiting loops.
- The ability to horizontally align run-on parameters, operators, etc.
- Consistent use of parentheses around the parameter list for all methods, which also eliminates the risk of confusion between calling method Foo and references variable Foo.
- There would be no more need to remember to use Set for objects.
- Long string literals.
- The trinary operator. Yes, it can be abused, but sometimes it's much simpler and clearer.
- C#'s case sensitivity allows one to distinguish between fields and properties.
- VBA's implementation of if logic, especially else-if, is clumsy and verbose.