i don't like object oriented programming
-
at the risk of being controversial, I will say: procedural vs object oriented = potato vs tomato Think of Math.Cos(), the fact that Cos() is part of the Math class is not really limiting and artificially constrained by object oriented programming. It's just that the function need be somewhere... I guess I used to feel limited by the number of class I could call "Utils" but I overcame this challenge long time ago! ;P generic limitation: I did notice that when my code become excessively generic it snowball and become more unmaintainable. I did notice that C++ specialization would be a nice touch that is missing. And I also hate boiler plate repeated code. But strangely enough since I noticed that I had no further problem... maybe I unconsciously found working alternative? I guess it might means there might be a solution to the problem you are facing...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
the problem I'm running into right now regarding specialization i had to work around by using a common base class to "share functionality" and it doesn't work very well. I have a lot of duplicated code in the specialization, and i've had to use "new" on some methods. It's rather awful, actually. Luckily most of the time, I can avoid the need altogether but in this case, specialization would make the most sense, so i did my best to "make it work" it's baling wire and chewing gum compared to what i can do in C++ I guess for me, once I relearned C++ the way it's taught in Moo and Koenig's book, I used generic programming for most of my coding. It doesn't make maintenance snowball. If it does, you're probably using it wrong and I highly recommend Accelerated C++ by the two authors I alluded to above. It's worth every penny of the $20-$30 asking price and you can usually get it used for a song. It's also a mercifully short book. It's one of the best programming books I've ever encountered for that - it's concise, accessible, and teaches something that's not typically taught well (C++ programming) But alas, using C++ the way they show you to use it makes me miss being able to do things that way now.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
the problem I'm running into right now regarding specialization i had to work around by using a common base class to "share functionality" and it doesn't work very well. I have a lot of duplicated code in the specialization, and i've had to use "new" on some methods. It's rather awful, actually. Luckily most of the time, I can avoid the need altogether but in this case, specialization would make the most sense, so i did my best to "make it work" it's baling wire and chewing gum compared to what i can do in C++ I guess for me, once I relearned C++ the way it's taught in Moo and Koenig's book, I used generic programming for most of my coding. It doesn't make maintenance snowball. If it does, you're probably using it wrong and I highly recommend Accelerated C++ by the two authors I alluded to above. It's worth every penny of the $20-$30 asking price and you can usually get it used for a song. It's also a mercifully short book. It's one of the best programming books I've ever encountered for that - it's concise, accessible, and teaches something that's not typically taught well (C++ programming) But alas, using C++ the way they show you to use it makes me miss being able to do things that way now.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
As someone else mentioned, have you considered using interface? Interface offer some of the benefit of multiple class inheritance without any drawback or ambiguity. ;)
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
As someone else mentioned, have you considered using interface? Interface offer some of the benefit of multiple class inheritance without any drawback or ambiguity. ;)
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
for this particular problem I don't really need multiple inheritance. I have a single inheritance chain. Frankly, what I need is template specialization and if i had it there'd be no inheritance at all. The use of FA as the base class is just a way to drag common code between the main FA and the CharFA specialization the FA serves as the base class and the main class. The CharFA inherits from FA and specializes it. It's ugly under the hood but it works. The why of this would be easier to explain with a background in finite automata and regular expression engines
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
for this particular problem I don't really need multiple inheritance. I have a single inheritance chain. Frankly, what I need is template specialization and if i had it there'd be no inheritance at all. The use of FA as the base class is just a way to drag common code between the main FA and the CharFA specialization the FA serves as the base class and the main class. The CharFA inherits from FA and specializes it. It's ugly under the hood but it works. The why of this would be easier to explain with a background in finite automata and regular expression engines
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
so you have (taking a guess in the dark)
public class SomeParsingData {}
public class FA
{
// ...
public virtual void MyOperation(SomeParsingData data) {}
}
public class CharFA : FA
{
public override void MyOperation(SomeParsingData data) {}
}static class FAUtil
{
public static void MyOperation(FA target, SomeParsingData data) => target.MyOperation(data);
}And you are lamenting that MyOperation() implementation is in FA instead of FAUtil class. Is it? Particularly when FA and SomeParsingData are not really related but both needed in MyOperation, right? Thinking about it... But not thinking too much until you confirm your issue...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
so you have (taking a guess in the dark)
public class SomeParsingData {}
public class FA
{
// ...
public virtual void MyOperation(SomeParsingData data) {}
}
public class CharFA : FA
{
public override void MyOperation(SomeParsingData data) {}
}static class FAUtil
{
public static void MyOperation(FA target, SomeParsingData data) => target.MyOperation(data);
}And you are lamenting that MyOperation() implementation is in FA instead of FAUtil class. Is it? Particularly when FA and SomeParsingData are not really related but both needed in MyOperation, right? Thinking about it... But not thinking too much until you confirm your issue...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
Actually I have only two classes, with
class FA {
}and
class CharFA : FA {
}Most of the time, the second class delegates to the first. Sometimes it has to overload what the base does. Sometimes it changes the function signature or "overloads" a static method so i have to use the "new" keyword.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
so you have (taking a guess in the dark)
public class SomeParsingData {}
public class FA
{
// ...
public virtual void MyOperation(SomeParsingData data) {}
}
public class CharFA : FA
{
public override void MyOperation(SomeParsingData data) {}
}static class FAUtil
{
public static void MyOperation(FA target, SomeParsingData data) => target.MyOperation(data);
}And you are lamenting that MyOperation() implementation is in FA instead of FAUtil class. Is it? Particularly when FA and SomeParsingData are not really related but both needed in MyOperation, right? Thinking about it... But not thinking too much until you confirm your issue...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
In answer to your question, I'm lamenting that a) i can't share more code. i'm overloading way too much in CharFA b) the two classes are distinct when they shouldn't be I'd much rather have
var fa = new FA(); // instantiate the specialization than
var fa = new CharFA(); // <-- what i have to do nowboth issues would be addressed by using partial template specialization in C++
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
In answer to your question, I'm lamenting that a) i can't share more code. i'm overloading way too much in CharFA b) the two classes are distinct when they shouldn't be I'd much rather have
var fa = new FA(); // instantiate the specialization than
var fa = new CharFA(); // <-- what i have to do nowboth issues would be addressed by using partial template specialization in C++
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
It's funny... I remember once I had generic code that look kind of like that
void DoSomething(T value) {
switch (typeof(T)) {
case typeof(double): DoDoubleThing((double)value); break;
case typeof(int): DoIntThing((int)value); break;
// ... all common base type
default: DoDefaultThing(value); break;
}
}But after some refactoring this all went away... I know, not helping, just sharing! :laugh:
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
It's funny... I remember once I had generic code that look kind of like that
void DoSomething(T value) {
switch (typeof(T)) {
case typeof(double): DoDoubleThing((double)value); break;
case typeof(int): DoIntThing((int)value); break;
// ... all common base type
default: DoDefaultThing(value); break;
}
}But after some refactoring this all went away... I know, not helping, just sharing! :laugh:
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
there's a kind of switch for types in newer C# but i've not used it yet. that might have been what it was. unfortunately it doesn't solve my problem =/. I think i've worked around it well enough, i just wish i had something better. if i ever come up with a trick to solve it i may publish here about it.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
isn't that similar enough to template specialisation?
class A
{
public virtual void Do(T value)
{
Console.WriteLine("Value: " + value);
}
}
class B : A
{
public override void Do(int value)
{
Console.WriteLine("Int: " + value);
}
}
class Program
{
static void Main(string[] args)
{
A a = new B();
a.Do(1);
}
}A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
that's exactly what I want. Does .NET support that now? :omg:
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
there's a kind of switch for types in newer C# but i've not used it yet. that might have been what it was. unfortunately it doesn't solve my problem =/. I think i've worked around it well enough, i just wish i had something better. if i ever come up with a trick to solve it i may publish here about it.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
isn't that similar enough to template specialisation?
class A
{
public virtual void Do(T value)
{
Console.WriteLine("Value: " + value);
}
}
class B : A
{
public override void Do(int value)
{
Console.WriteLine("Int: " + value);
}
}
class Program
{
static void Main(string[] args)
{
A a = new B();
a.Do(1);
}
}A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
that's exactly what I want. Does .NET support that now? :omg:
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
I dunno if there was a problem before.. but it's copy paste from some code I was just running on a test project while thinking about your problem.... So, shortly, this is fine. Assuming it was not always working (which I doubt) the test project use .NET Framework 4.7.2 and C# compiler latest version, i.e. 7.3 **[EDIT & REMARK]**this looks like perfectly valid C# since the beginning of generic to me. Odds are you got confused at some stage...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
that's exactly what I want. Does .NET support that now? :omg:
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
This has always worked. You can't do that with static and/or non virtual method though, maybe that's what mislead you?!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
i never have. give me templates. or you may as well just give me something procedural. if i can't do generic programming i'm a sad honey bear. C# is barely adequate. And it's too object centric IMO. generics need to be able to do more. I want traits. I want the runtimes to do what i can make a C++ compiler do with templates. I probably just got the BAC up of this entire board saying that, but there it is.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
one example I'm running into right now is template specialization. I have a finite state machine engine and it works for any transition input type and any accept symbol type. However, there are additional features that can happen - significant ones that can only exist when the transition type is char - this specialization is effectively a regular expression engine, which means it can parse from a regular expression, and provide regex matching over string inputs. The other kind of FAs it wouldn't even make sense for that. So because of this I have two separate classes - one generic FA class, and one called CharFA where the TInput=char basically. It means more code to maintain because a lot of it is duplicated. To unduplicate a lot of which i could, I'd have to add another codefile with an interface, and another with static methods to share common functionality, which again, increases the code size. So it's not even that I can't do it with C#, it's that what is elegantly handled in C++ is clunky in C# to do the same thing, and requires more code.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
There are two ways that I can think of to avoid this code duplication. (Whether these are suitable is up to you.) 1. Implement your byte specific class as a subclass of your generic class? 2. Use dependency injection for the byte specific code. Good luck
-
i never have. give me templates. or you may as well just give me something procedural. if i can't do generic programming i'm a sad honey bear. C# is barely adequate. And it's too object centric IMO. generics need to be able to do more. I want traits. I want the runtimes to do what i can make a C++ compiler do with templates. I probably just got the BAC up of this entire board saying that, but there it is.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
Eddy Vluggen wrote:
That's a non-complaint; like I said, you can put all your procedures in a God-object
Not a complaint. Just attempting to clarify what i meant
Eddy Vluggen wrote:
I'd say you haven't worked in a strict procedural language
Now I wonder what you'd consider procedural. Batch files? SQL? C?
Eddy Vluggen wrote:
Haven't seen much of that, so not going to comment on it. But still, yuck.
Spoken like someone that's never used it. GP is lovely, elegant, concise and powerful. I wish it was more available in places other than C++.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
honey the monster, codewitch wrote:
Now I wonder what you'd consider procedural.
AMOS, among others.
honey the monster, codewitch wrote:
Spoken like someone that's never used it.
OO is the most logical step forward from the messy and hard-to-maintain pages of procedures, sprinkled with arguments and global variables.
honey the monster, codewitch wrote:
I wish it was more available in places other than C++.
It is still available; you can abuse any OO language as if it is merely capable of procedures.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
honey the monster, codewitch wrote:
Now I wonder what you'd consider procedural.
AMOS, among others.
honey the monster, codewitch wrote:
Spoken like someone that's never used it.
OO is the most logical step forward from the messy and hard-to-maintain pages of procedures, sprinkled with arguments and global variables.
honey the monster, codewitch wrote:
I wish it was more available in places other than C++.
It is still available; you can abuse any OO language as if it is merely capable of procedures.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
generic programming, not procedures.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
There are two ways that I can think of to avoid this code duplication. (Whether these are suitable is up to you.) 1. Implement your byte specific class as a subclass of your generic class? 2. Use dependency injection for the byte specific code. Good luck
the latter isn't practical. the former i already did, and it's sloppy as hell
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
This has always worked. You can't do that with static and/or non virtual method though, maybe that's what mislead you?!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
doesn't compile for me.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
This has always worked. You can't do that with static and/or non virtual method though, maybe that's what mislead you?!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
oh i see what you did. that's not template specialization. that's method overloading
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.