|
Create an interface class called IFa (name it something esle for sure, but this is for ilustration purposes) and implement IFa in a new class CharFA using that interface. or Create an iterface called IFa and a default implementation for IFa and then create another class that implements the default implementation and then just override any methods, etc.
It is object oriented programming, which you hate, but that is how this stuff is usually done, more or less, in C#.
Would that work for you?
Just a suggestion, I am not really trying to solve any problems here. I think your dislike of C# and generics, and object oriented programming may prevent you from seeing how things are done in this language, etc.
Good luck.
|
|
|
|
|
which is what i mentioned in my other reply, after an edit though. it's not that I can't do it. It's that it's clunky and requires more code than the elegant specialization feature in C++
it reminds me of the limitation of lack of multiple inheritance - you can sort of emulate it, but it requires more code.
like i said, i just wish generics could do more.
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 think the "clunky" is relative here, as I don't think it is clunky because I have limited exposure to other techniques.
|
|
|
|
|
that's definitely fair. and I come at C# from a C++ background.
I like C#, don't get me wrong, and it's miles ahead of Java in terms of how it's put together, IMO, but I still miss aspects of C++ development with it, even as it has supplanted C++ as my primary development language and environment.
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 miss the multiple inheritance of C++ as well. I know we can do it via Interfaces but it's not quite as straightforward. Perhaps by C#12 it will be there.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
i'm glad i'm not the only one! =)
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.
|
|
|
|
|
Take a look at F# or another functional language. State machines and functional languages are made for each other.
|
|
|
|
|
I've strongly considered it. I might eventually move, but I'm familiar with C#.
Maybe if they had Haskell I would have moved already.
Edit: Adding, one of the drawbacks of functional programming is lack of state, and some of these equations are so complicated that state is necessary for optimization and I wonder how a functional language will handle such a thing. Recomputing or doing lazy iteration over these algorithms is grossly impractical even if it's "correct"
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.
|
|
|
|
|
Memoization might be useful for you. It's basically a way to cache function results with a given input in a dictionary and return the cached value instead of running the calculation again.
|
|
|
|
|
yeah. in fact, I need to explore memoization more anyway for implementing a PEG parser.
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 there.
I agree that a multi-paradigm language is a better idea than one which insists on objects.
One needs to use the right tool for the right job and OOP is not the right tool for a great many jobs.
|
|
|
|
|
it's one of the areas where C++ really shines and I kind of wish other, higher level imperative languages would catch up.
though i'd also like to see C++ have more functional-programming constructs in the future.
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 only ever dabbled in C++ (80s, 90s), so I never became familiar with what it can do.
I went straight from C (mostly on OpenVMS) to C# (and .net) and it was like a Bob-send -- I'm glad I hadn't had to use C++ and the various libraries people talk about. A lot of the hype I heard turned me off of C++ anyway.
But... I want multiple-inheritance and such. There are a number of facets of C# (.net languages) I don't like.
Languages and frameworks should provide features and _allow_ developers to do what their particular task requires rather than dictating what the develop must or must not do.
I may still need to look at D again.
|
|
|
|
|
Well the weird thing about C++ is by itself it's about 2/3 of a language, while the standard template libraries are (usually) the other 1/3
and it's strange to think of it that way, but that's how it ends up baking out - STL is so intrinsic to any significant C++ development that you really don't even want to do it without it, just like you wouldn't want to write an app without an operating system.
It's not just about runtime libraries, although that's most of it. Because of the way templates work, you can use them to basically implement "language features" of a sort. So STL sort of folds itself into the language.
And the cool thing about that is you can potentially make your own "domain specific" language superset from C++ just like STL does - the spirit framework does this, and boost kind of does.
So that's something that's really hard to get used to at first because it's pretty unique to C++
after that, just learning how to use generic programming is the big learning curve, but I swear once you do, you'll fall in love.
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.
|
|
|
|
|
Yeah, nope, hype hype hype...
|
|
|
|
|
i'm just telling you based on my experience using it.
Very few teach it properly unfortunately.
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.
|
|
|
|
|
At the risk of being even more wildly undesirable here, I'm with ya.
|
|
|
|
|
come sit at my table. we can totally be unpopular together
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:
if i can't do generic programming i'm a sad honey bear. Yuck. OO is procedural, but with structure and local variables.
It doesn't limit a procedural programmer; you're free to put everything in a God-class and pretend to be procedural.
honey the monster, codewitch wrote: generics need to be able to do more. Again, yuck.
Bastard Programmer from Hell
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.
|
|
|
|
|
i mean procedural as in procedures rather than objects to divvy up code. If there's a better word for that I'm unaware of it. You could say that all imperative languages are procedural if they have functions/methods but that's almost too general to be useful.
As far as your yucks, i come from a C++ background and happen to like generic programming. to each their own.
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: i mean procedural as in procedures rather than objects to divvy up code. That's a non-complaint; like I said, you can put all your procedures in a God-object.
honey the monster, codewitch wrote: If there's a better word for that I'm unaware of it. You could say that all imperative languages are procedural if they have functions/methods but that's almost too general to be useful. I'd say you haven't worked in a strict procedural language
honey the monster, codewitch wrote: As far as your yucks, i come from a C++ background and happen to like generic programming. to each their own. Haven't seen much of that, so not going to comment on it. But still, yuck.
Bastard Programmer from Hell
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.
|
|
|
|
|
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.
|
|
|
|