Why do I listen to my sleep coding self?
-
Ok so let's have an example.
public static class BaseService {
public static void LoadData() {
Console.WriteLine(GetDataSource());
}protected virtual static string GetDataSource();
}public static class FileService : BaseService {
protected override static string GetDataSource() { return "file.dat"; }
}public static class DatabaseService : BaseService {
protected override static string GetDataSource() { return "database"; }
}... and calling code
void Run() {
DatabaseService.LoadData();
FileService.LoadData();
}This would print "database" and "file.dat", because the class used for the vtable lookups would be taken from the data type used for the call (i.e. DatabaseService.LoadData). That would be resolved at compile time and based on the static declaration type used in the call, not dynamic object type lookups as with instance dispatch. A related good idea is the ability to pass service classes around and dispatch off them:
void Run(Class<BaseService> service) {
service.LoadData();
}... called like Run(DatabaseService) which would bake in the type for dispatch.
-
:laugh: I work for myself, so I give myself special permission to "goof off". :laugh:
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
Lucky you! Allowed to give yourself some special permissions :laugh:
-
Lucky you! Allowed to give yourself some special permissions :laugh:
The down side is the Christmas party is a little lonely... ;)
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
The down side is the Christmas party is a little lonely... ;)
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
Started working here the week after they had their Christmas party so I can't give you any feedback on that one, yet! :-D
-
0 times. I've wished that interfaces could contain static methods so that T.someFunction could exist for generics (constrained to that interface), but that's a completely separate issue. (that can't work in C# of course) How is "static virtual" even a reasonable concept? No instance = no vptr = no dynamic dispatch.
harold aptroot wrote:
no vptr
Don't get hung up on how current languages are implemented. I too would like a language that allows static members in interfaces and abstracts. If a Bright compiler developer wanted to make this happen, I'm sure he could, it would likely have to be very different from current implementations. (It's way beyond my skills of course.)
You'll never get very far if all you do is follow instructions.
-
In bed last night, I dreamt a wonderful improvement to the design of some software I'm working on. It would clean it up, move the code into it's appropriate classes, make it all beautiful. So I have just coded it. Or at least, I coded 3/4 of it. That was the point when I thought "Hang on a moment, you can't have
abstract static
methods in C#". :doh: Bugger. Note to self: don't listen to me when I'm sleepy. Anyone else done this? Constructed a massive edifice of beautiful code in your mind, only to find when you have got sufficient caffeine in your system that it has a fatal, fundamental, flaw?Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
OriginalGriff wrote:
abstract static
OriginalGriff wrote:
Anyone else done this?
Yes, for exactly the same thing. Was such a perfect solution to the problem. Except that it wasn't. Obviously. I even still have the code in place, safely commented out, just to remind me.
cheers Chris Maunder
-
In bed last night, I dreamt a wonderful improvement to the design of some software I'm working on. It would clean it up, move the code into it's appropriate classes, make it all beautiful. So I have just coded it. Or at least, I coded 3/4 of it. That was the point when I thought "Hang on a moment, you can't have
abstract static
methods in C#". :doh: Bugger. Note to self: don't listen to me when I'm sleepy. Anyone else done this? Constructed a massive edifice of beautiful code in your mind, only to find when you have got sufficient caffeine in your system that it has a fatal, fundamental, flaw?Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
Make it more dynamic. Instead of static abstract, make it a static property of a delegate type.
-
Delphi allowed virtual static methods... so I think it probably allowed abstract static methods too.
-
In bed last night, I dreamt a wonderful improvement to the design of some software I'm working on. It would clean it up, move the code into it's appropriate classes, make it all beautiful. So I have just coded it. Or at least, I coded 3/4 of it. That was the point when I thought "Hang on a moment, you can't have
abstract static
methods in C#". :doh: Bugger. Note to self: don't listen to me when I'm sleepy. Anyone else done this? Constructed a massive edifice of beautiful code in your mind, only to find when you have got sufficient caffeine in your system that it has a fatal, fundamental, flaw?Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
I also made that mistake once.... :laugh: :laugh: :laugh:
-
If you started to dream of coding you have only two options - doctor or vacation...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
-
harold aptroot wrote:
no vptr
Don't get hung up on how current languages are implemented. I too would like a language that allows static members in interfaces and abstracts. If a Bright compiler developer wanted to make this happen, I'm sure he could, it would likely have to be very different from current implementations. (It's way beyond my skills of course.)
You'll never get very far if all you do is follow instructions.
very different from current implementations[^] :-D
**_Once you lose your pride the rest is easy.
I would agree with you but then we both would be wrong._**
The report of my death was an exaggeration - Mark Twain Simply Elegant Designs JimmyRopes Designs
I'm on-line therefore I am. JimmyRopes -
0 times. I've wished that interfaces could contain static methods so that T.someFunction could exist for generics (constrained to that interface), but that's a completely separate issue. (that can't work in C# of course) How is "static virtual" even a reasonable concept? No instance = no vptr = no dynamic dispatch.
-
I once coded a class function in C++ that calls realloc() or malloc(), based on whether "this" points to null. It then deletes this and returns This.
-
Not only that, it calls _msize() on the this pointer and checks against another size parameter for the realloc. The last member in the class was a 0-byte array, for which the _msize() of the pointer minus size of other class members gave the array size.
-
In bed last night, I dreamt a wonderful improvement to the design of some software I'm working on. It would clean it up, move the code into it's appropriate classes, make it all beautiful. So I have just coded it. Or at least, I coded 3/4 of it. That was the point when I thought "Hang on a moment, you can't have
abstract static
methods in C#". :doh: Bugger. Note to self: don't listen to me when I'm sleepy. Anyone else done this? Constructed a massive edifice of beautiful code in your mind, only to find when you have got sufficient caffeine in your system that it has a fatal, fundamental, flaw?Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
If you are going tp code in your sleep then choose a language that will better match your fantasies.
-
very different from current implementations[^] :-D
**_Once you lose your pride the rest is easy.
I would agree with you but then we both would be wrong._**
The report of my death was an exaggeration - Mark Twain Simply Elegant Designs JimmyRopes Designs
I'm on-line therefore I am. JimmyRopesOh my, I've been Osmosian-rolled. :sigh:
You'll never get very far if all you do is follow instructions.
-
very different from current implementations[^] :-D
**_Once you lose your pride the rest is easy.
I would agree with you but then we both would be wrong._**
The report of my death was an exaggeration - Mark Twain Simply Elegant Designs JimmyRopes Designs
I'm on-line therefore I am. JimmyRopesMy anti-virus considered it as a trojan horse.
-
It's actually a reasonable concept if you allow static inheritance (i.e. static virtual in C# speak), and that's a really useful concept that is missing in C#. How many times have you had to create an instanced service class, even though it has no state (so should be static), because you can't have static members in an interface or virtual static members in a base class?
BobJanova wrote:
static inheritance (i.e. static virtual in C# speak), and that's a really useful concept that is missing in C#
Couldn't you use a singleton of some related class hierarchy that implements the "static" code?
We can program with only 1's, but if all you've got are zeros, you've got nothing.
-
If you are going tp code in your sleep then choose a language that will better match your fantasies.
As Gilbert & Sullivan put it (in Iolanthe), When you’re lying awake With a dismal headache, And repose is taboo’d by anxiety, I conceive you may use Any language you choose To indulge in, without impropriety;
-
In bed last night, I dreamt a wonderful improvement to the design of some software I'm working on. It would clean it up, move the code into it's appropriate classes, make it all beautiful. So I have just coded it. Or at least, I coded 3/4 of it. That was the point when I thought "Hang on a moment, you can't have
abstract static
methods in C#". :doh: Bugger. Note to self: don't listen to me when I'm sleepy. Anyone else done this? Constructed a massive edifice of beautiful code in your mind, only to find when you have got sufficient caffeine in your system that it has a fatal, fundamental, flaw?Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)