Linked Questions

90 votes
10 answers
53k views

If null is bad, why do modern languages implement it? [closed]

I'm sure designers of languages like Java or C# knew issues related to existence of null references (see Are null references really a bad thing?). Also implementing an option type isn't really much ...
zduny's user avatar
  • 2,653
59 votes
14 answers
9k views

When is type testing OK?

Assuming a language with some inherent type safety (e.g., not JavaScript): Given a method that accepts a SuperType, we know that in most cases wherein we might be tempted to perform type testing to ...
svidgen's user avatar
  • 14.7k
10 votes
4 answers
3k views

Why not apply Interface Segregation Principle to "extreme"

Providing that clients would typically consume just one method, though methods would be conceptually related, why not always apply the Interface Segregation Principle to the extreme and have [many] ...
Den's user avatar
  • 4,847
15 votes
2 answers
3k views

Implement Haskell typeclass with C# interface

I'm trying to compare Haskell's type classes and C#'s interfaces. Suppose there is a Functor. Haskell: class Functor f where fmap :: (a -> b) -> f a -> f b How to implement this type ...
ДМИТРИЙ МАЛИКОВ's user avatar
5 votes
3 answers
5k views

What is a good design for a method that can return several logically different results?

The question title is probably too abstract, so let me provide a particular example of what I have in mind: There is a webservice that encapsulates a process of changing passwords for users of a ...
Nikola Anusev's user avatar
1 vote
4 answers
596 views

The point of sealing a class

What is the point of sealing a class? Why should we seal a class at all? I've found a bit contradicting answers on the internet, for example here: https://stackoverflow.com/questions/268251/why-seal-a-...
frgt's user avatar
  • 133
3 votes
3 answers
4k views

"One of some"-type

Say that you have some different classes that does not really have any functionality in common, but somewhere in your program, you need one of them (which one is not necessarily important) because ...
Torm's user avatar
  • 151
6 votes
1 answer
946 views

Is this actually good OO design?

Context I have Specification class with several properties including: StartDate, EndDate, DaysToComplete, DateToComplete. A specification contains a list of required courses (i.e. a company requires ...
BVernon's user avatar
  • 483
3 votes
2 answers
2k views

Lazy Processing of Streams

I have the following problem scenario: I have a text file and I have to read it and split it into lines. Some lines might need to be dropped (according to criteria that are not fixed). The lines that ...
Giorgio's user avatar
  • 19.7k
1 vote
3 answers
1k views

Avoiding a large amount of overloads

I'm currently writing a mailing interface for our enterprise application. Dependent on the send mode (regular email, bulk email, templates, mailmerge, ...) our Send() method requires a bunch of ...
SeToY's user avatar
  • 278
6 votes
3 answers
1k views

Is it a good idea to return a default value if a field in a query cannot be found?

At the place I work we are using a SafeReader class that wraps an IDataReader. One of the 'features' is that if the field you are trying to access wasn't in the query then it just returns a default ...
BVernon's user avatar
  • 483
6 votes
2 answers
3k views

How should I refactor switch statements like this (Switching on type) to be more OO?

I'm seeing some code like this in our code base, and want to refactor it: (Typescript psuedocode follows): class EntityManager{ private findEntityForServerObject(entityType:string, serverObject:any)...
Taytay's user avatar
  • 211
1 vote
3 answers
5k views

Checking for the presence of optional properties of an object

I'm designing a class that holds several types of data. Some of the properties are optional. For example, let's say I have a class that represents a person, and one of the properties is occupation. ...
codebreaker's user avatar
  • 1,724
2 votes
3 answers
1k views

What procedural languages support algebraic data types? [closed]

One of the things I like about the new Apple language Swift is that it combines procedural programming with algebraic data types. What other languages do this?
John DeHope's user avatar
3 votes
3 answers
2k views

Empty superclass for Collection of derived classes

Basically, what I would like to obtain is a way to iterate through ONE list, and call methods specific to the interface the objects in the collection implement. In my Java project, it would result in ...
hornobster's user avatar

15 30 50 per page