Skip to main content
30 votes
Accepted

Why do heavily object-oriented languages avoid having functions as a primitive type?

IMO... Because Java and C# are not true OO languages. Functional programming was not in vogue when they were designed. I agree with Jörg W Mittag, neither C# nor Java are true object-oriented ...
Schwern's user avatar
  • 1,192
26 votes

Why do heavily object-oriented languages avoid having functions as a primitive type?

This is a little bit of a silly question. You're asking why object-oriented languages are object-oriented. If they passed functions around as first class types we wouldn't describe them as object-...
Telastyn's user avatar
  • 110k
11 votes

Why do heavily object-oriented languages avoid having functions as a primitive type?

In these “classic OOP” languages like C++/Java/C#, objects are data + behaviour, where the behaviour is provided by a class. On a technical level, this generally results in a memory layout somewhat ...
amon's user avatar
  • 136k
6 votes
Accepted

Fundamental differences between a List<Action> vs Action

Yes, there is a fundamental difference between the two: type safety. Whilst GetInvocationList can indeed be called on act in your example, it doesn't return a list, it returns an array of Delegate. ...
David Arno's user avatar
  • 39.6k
5 votes
Accepted

How to refactor same block of delegate code into a single private method?

Bundle the delegate and the local variable in a class: class Validator { public string ActualValidationString { get; private set; } = string.Empty; public void Validation(string msg) { ...
Doc Brown's user avatar
  • 220k
5 votes

Are there any benefits to delegation over subclassing/inheritance in the case of a singleton?

Is there any benefit to using a delegate to specify behavior of a singleton rather than having the user override the singleton class and providing their own methods all in one place? The singleton ...
candied_orange's user avatar
5 votes

Resorted to Unconventional( i.e., hacky) "circuitous" programming code techniques when using populating a list of C# Action Delegates via a for loop

This isn't how you would iterate a dictionary. For one, it does a linear walk through its keys/values on every call to .Keys.ElementAt(i), which is really wasteful. More importantly, it's just more ...
Alexander's user avatar
  • 5,195
4 votes

Why do heavily object-oriented languages avoid having functions as a primitive type?

The use of "primitive" is a bit too broad in the question. In general terms, primitives are things that have simple, measurable, binary storage, without iteration or growth in allocated ...
S.D.'s user avatar
  • 1,100
4 votes

Why do heavily object-oriented languages avoid having functions as a primitive type?

In later C# versions you no longer have to be explicit about delegates. You can pass a function just by stating its name. I think it is mainly about type safety. In the compiled code there won't be an ...
Martin Maat's user avatar
  • 18.6k
2 votes

Are there any benefits to delegation over subclassing/inheritance in the case of a singleton?

Nobody cares about whatever table size. But if you create a subclass, then a developer who knows the behaviour of the original class has no clue what your subclass will be doing. A macOS / iOS ...
gnasher729's user avatar
  • 49.4k
2 votes

Functions vs Classes for delegate pattern

Using a lambda function of type std::function<void()> or an object which is derived from an abstract class with just one virtual function are both semantically equivalent. More general, objects ...
Doc Brown's user avatar
  • 220k
2 votes

Why do heavily object-oriented languages avoid having functions as a primitive type?

Without delving into any specific language (yet!), one first reason would probably be ease of implementation (in the compiler/interpreter). It is much much more simple to have a single "internal&...
AnoE's user avatar
  • 5,892
1 vote

Turn an asynchronous delegate pattern into a blocking method

Imagine if someone else calls doWork for that same object right after you do. They "steal" the delegate, and they will get both workDone callbacks basically, this is what you should be fixing first. ...
max630's user avatar
  • 2,605
1 vote

Design issue with delegation, inheritance and dependency injection

It seems that MailService should only have one MailerServiceDelegate during it's lifetime. I am not sure if you can change MailService, but I think that it's current implementation have some flaws. ...
SomeGuy's user avatar
  • 76
1 vote

Fundamental differences between a List<Action> vs Action

The main difference is internal. Delegate is a linked list; List uses an array internally. For a public API, you should not use either. List is not supposed to be exposed in properties, and a public ...
Frank Hileman's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible