When to use a Class in VBA?

It depends on who’s going to develop and maintain the code. Typical “Power User” macro writers hacking small ad-hoc apps may well be confused by using classes. But for serious development, the reasons to use classes are the same as in other languages. You have the same restrictions as VB6 – no inheritance – but … Read more

When do you write a private method, versus protected? [closed]

public and protected methods form the ‘interface’ to your object, public for developers using (delegating to) your class, and protected for developers wishing to extend the functionality of your object by subclassing it. Note that it’s not necessary to provide protected methods, even if your class will be subclassed. Both public and protected interfaces need … Read more

Object-oriented programming in a purely functional programming context?

The disconnect you see is not of FP vs. OOP. It’s mostly about immutability and mathematical formalisms vs. mutability and informal approaches. First, let’s dispense with the mutability issue: you can have FP with mutability and OOP with immutability just fine. Even more-functional-than-thou Haskell lets you play with mutable data all you want, you just … Read more

what is a member vs. a property

A property is one kind of member. Others might be constructors, methods, fields, nested types, conversions, indexers etc – depending on the language/platform, of course. A lot of the time the exact meaning of terminology depends on the context. To give a C#-specific definition, from the C# 3.0 spec, section 1.6.1: The following table provides … Read more

Can anyone provide an example of the Liskov Substitution Principle (LSP) using Vehicles?

For me, this 1996 Quote from Uncle Bob (Robert C Martin) summarises the LSP best: Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it. In recent times, as an alternative to inheritance abstractions based on sub-classing from a (usually abstract) base/super class, we … Read more

Reducing the number of arguments to a constructor

You could have MovablePatch(Renderer* renderer, CircleAppearance circleAppearance) where CircleAppearance gathers the other info. However, clean code and other books that generalize about what good code should look like, are aiming for 80 percent of the code out there. Your code seems to be “closer to the metal” than the typical LoB (Line of Business) variety. … Read more

Subclass `pathlib.Path` fails

You can subclass the concrete implementation, so this works: class Path(type(pathlib.Path())): Here’s what I did with this: import pathlib class Path(type(pathlib.Path())): def open(self, mode=”r”, buffering=-1, encoding=None, errors=None, newline=None): if encoding is None and ‘b’ not in mode: encoding = ‘utf-8’ return super().open(mode, buffering, encoding, errors, newline) Path(‘/tmp/a.txt’).write_text(“я”)