What design pattern should I use for specific multiple inheritance?
DynamicSquid

Let's say I have an interface called Squid.

And we have a bunch of different types of squids:

Here's everything a squid can be:

aquaticland
basicbasic-aquaticbasic-land
advancedadvanced-aquaticadvanced-land

How would I go about create an instance of a squid? Should I go about creating 4 classes BasicAquaticSquid, BasicLandSquid, AdvancedAquaticSquid, AdvancedLandSquid like this:

I think that's called the Abstract Factory method? It seems very tedious though. Any better way of doing so?

Thanks

You are viewing a single comment. View All
Answered by xxpertHacker [earned 5 cycles]
View Answer
firefish

@DynamicSquid use the duplicate macro in the duplicate crate

(will invite you to said repl)
Stack Overflow link

firefish

@DynamicSquid also come on the NightLang pr #65

xxpertHacker

@firefish Why did I not think of that!? Rust duplicate crate, there we go, problem solved.

DynamicSquid

@firefish genius

firefish

@xxpertHacker I did spend some time combing through Stack Overflow, as you can tell by the link

firefish

@DynamicSquid @Lethdev2019
Slice, dusk, and night... what do you think?

(dusk is smaller because it ain't a language)

StringentDev

@firefish i like it but when are we gonna work on slice?

firefish

@Lethdev2019 I am, every day. Working on the SoN VM

StringentDev

i mean slice itself. @firefish

firefish

@Lethdev2019 Well how? We can start by making the interpreter, I mean all the sliec stuff is in the SoN VM proto.md, so check there

StringentDev

ok in it. @firefish

StringentDev

also - i am using linux now. @firefish

firefish

@Lethdev2019 Same, I like to use my dualboot, but I'm not using it atm because I want to do some dev now, not wait an hour to update it to Fedora 33

firefish

@Lethdev2019 It's this repl, you haven't come on

firefish

@Lethdev2019 Hi, come on the repl named "SoN-VM"

StringentDev

@firefish are you online?

firefish
xxpertHacker

@firefish I'm surprised that stuff on Rust can even be found, seeing as so few people use it. But honestly probably a better answer than mine.

firefish

@xxpertHacker

so few people use it

how uncultured are you

xxpertHacker

@firefish What do you mean? How am I uncultured because so few people use the Rust programming language relative to other languages?

firefish

@xxpertHacker You are deluded. Google agrees with me:

ignore the last bit

xxpertHacker

@firefish No, it doesn't?
The last sentence supports me, not you.
I'm among the 5% of people who have used the language.

firefish

@xxpertHacker but 86% of people said they were keen on learning it

xxpertHacker

@firefish Yeah, that's cool.. but they haven't started. Actons are worth more than words.
Could I have asked one of the people who are keen on learning it about the duplicate crate? No, because they have no clue what a crate even is, because they want to learn it, but they haven't started.

Thus we return to what I had originally said:

...so few people use it.

DynamicSquid

@xxpertHacker I agree. Rust can actually be a really good language if you know how to use it. Otherwise it seems like C++ but with restrictions and weird rules

firefish

@DynamicSquid Learn the rules, and you will forget how to code in C++ (lol not kidding)

DynamicSquid

@firefish lol. I like C++ since it allows you to do whatever you want. Rust is like:

C++ is like:

xxpertHacker

@DynamicSquid Whoa whoa, you need to learn the language.
Once you have, you'll realize C++ is the language without restriction and with weird rules. Rust is a language that makes sense.

Also, it has one major advantage over C++: there is no undefined behavior whatsoever.

You can have a multi-threaded program, knowing everything will always run flawlessly (okay, it might deadlock, but still).

You will never run into concurrent reading/writing problems.

You should never get a system floating-point exception.
Arithmetic should never overflow and give weird results.

You can't perform certain operations in Rust, but you can in C++:

You can't read uninitialized data:

You can't read out of bounds memory.

You get where I'm going, the list continues, you can't do a bunch of dumb stuff, do you know what that means?
Every package you import and use should work correctly, without having to review the code.

It doesn't have classes, so if you like OOP styled code, you'll have to learn how to write idiomatic Rust.

firefish

@DynamicSquid Well What if you reference something you aren't supposed to, and then you program starts overwriting itself in memory. Oh boy, can that be abused

firefish

@xxpertHacker

how to stuff

I wouldn't have used the verb stuff in THAT context but whatever you say...

xxpertHacker

@firefish Oops, I edited half of the sentence without reconnecting it; fixed.

firefish

@xxpertHacker

<I wouldn't have used the ver

What did the rest say?

xxpertHacker

@firefish What are you talking about?

firefish

@DynamicSquid Night can be BOTH interpreted AND bytecodce

firefish

@xxpertHacker The message you deleted

xxpertHacker

@firefish It was deleted for a reason :)

firefish

@xxpertHacker I bet it ended with
b stuff in that context or something along those lines

xxpertHacker
firefish

@xxpertHacker And then you probably said something indecent in the context in which you WOULD use it.

xxpertHacker

@firefish CPython and the V8 JavaScript engine both just interpret bytecode instead of text, seems more performant, why not just use bytecode?

xxpertHacker

@firefish No, I had actually questioned how "stuff" is even a verb, before remembering that it could mean to put something into a small space.

firefish

@Dynamicsquid @xxpertHacker a.k.a. @StudentFires forgot to ping you, here's what he said:

CPython and the V8 JavaScript engine both just interpret bytecode instead of text, seems more performant, why not just use bytecode?

firefish

@xxpertHacker Oh, ok then... lol

xxpertHacker

@firefish Who's @StudentFires? And no, I was responding to your message, which was directed towards DynamicSquid.

firefish

@xxpertHacker That's you, remember? (aight this guy has memory loss)

xxpertHacker

@firefish Nope, no recollection of that Repl.it user whatsoever.

firefish

@xxpertHacker I hope you're joking because click on the link @StudentFires and you will see that it leads to your own profile

xxpertHacker

@firefish Weird, I'll probably go report that bug later, when I have time.

firefish

@xxpertHacker Explain this.

xxpertHacker

@firefish Nope.

firefish

@xxpertHacker And this:

also i know you are pulling my leg

firefish

@xxpertHacker And what happened to changing repl.it at it's core

DynamicSquid

@firefish, @xxpertHacker Should unsafe programming practices be the programmer's fault, or the language's fault?

firefish

@DynamicSquid The programmer's fault in C/C++, in rust it's the programmer's fault if you put an unsafe block

DynamicSquid

@firefish I feel like it should be the programmers fault. That's why I like C++ so much, you can do whatever you want

firefish

@DynamicSquid it is the progrmammers fsualt

xxpertHacker

@firefish But... fish don't have legs...

DynamicSquid
xxpertHacker

@DynamicSquid To that, I must ask you the following:

In a strongly-typed, and statically typed language, should type safety be the programmer's fault, or the language's fault?

Should you run a compiler on a text file, and get a properly working executable, or an improperly-working executable?

Should source code that was developed on a Windows computer be capable of being compiled on a Linux, and run just as it had done on the Windows, without change?

Should undefined behavior be allowed to even exist?

DynamicSquid

@xxpertHacker Yeah, good points, can't really argue with that

DynamicSquid

@xxpertHacker But again, I think the feeling of "this language won't let me do this" is harmful since it's limiting programmers in what they can do. Programming's (I'm talking about low level programming since that's obviously the best) all about working with the computer, but if you restrict some of the things you can do with the computer, well then you're not really working with the computer, if that makes any sense

firefish

@xxpertHacker Where did I mention legs...

xxpertHacker

@DynamicSquid We can both agree on what to choose from those questions I raised, and Rust made the right choices.

Simply think of the restrictions like you think of what you can do in C/C++ on a pointer.

Let's start, what is a pointer?
Computers only understand numbers, a pointer is a literal integer, yet... in a way, it's not.

It is an integer, yet it simply is used to load and store memory at the specific point that it "points" to.
Why do I bring this idea up at all?
Because they are an abstract idea, but they have restrictions.

Does that seem like a weird restriction? Hopefully not. Yet it makes perfect sense to restrict what can be done in some cases, yet most of the time, C++ just lets you do whatever you want, whether or not it makes sense at all.

xxpertHacker

@firefish You said that I was "pulling your leg," but you're a fish.

DynamicSquid

@xxpertHacker give him a couple million years and he'll grow legs

xxpertHacker

@DynamicSquid You will too, right?

DynamicSquid

@xxpertHacker No, squids can't evolve. If you look closely at the hierarchy:

firefish

@xxpertHacker So there are these things called idioms

xxpertHacker

@firefish Whoa, idioms of the sea? I don't know many fish idioms, sorry.

DynamicSquid

@xxpertHacker But the whole point is not having restrictions. If I want to shift bits, I should be able to shift bits. The idea of "abstraction" I think is just a way for me to better communicate what I want to do with the computer

xxpertHacker

@DynamicSquid Lmao, you can be the first by learning Rust though.

firefish

@xxpertHacker Are you THAT dumb

xxpertHacker

@firefish No, I'm dumber.

DynamicSquid

@firefish, @xxpertHacker I am so confused, we're having like 2 conversations at the same time

firefish

@DynamicSquid @xxpertHacker is trying to annoy me, by being an idiot

xxpertHacker

@DynamicSquid Yeah... it could be confusing for you, being caught in the middle, and being the author of this post, meaning you get every message.

DynamicSquid

@xxpertHacker, @firefish you guys making fun of each other reminds me:

your mamma is so fat that she can sit on a binary tree and turn it into a linked list in O(1) time

firefish

@DynamicSquid lmao lol

DynamicSquid

@xxpertHacker, @firefish gotta go now. probably gonna come back to like 50 notifications :/

firefish

@DynamicSquid we won't annoy you, will we @StudentFires?

xxpertHacker

@DynamicSquid The idea isn't restriction at all, more likely, it's explicitness.

Often times, in source code, when you see something weird, one of thee things are true:

  • You stopped and said, "what am I looking at?"
  • There is a comment explaining the apparent nonsense, explaining that it is not nonsense, but some weird technique.
  • You actually understood what you saw, because you've seen it before, or had actually done it before.

If you've ever seen a weird piece of code before, you should agree.

The first possibility is very likely, and it exists because languages let people do weird stuff. This possibility does not exist within Rust.

The second exists for the same reason as the first and is due to a lack of language-level support for whatever they did, or because they were lazy. What if you provide language-level support for this?

The third possibility is very unlikely and doesn't need to exist, because weird code practice shouldn't need to exist.

xxpertHacker

@DynamicSquid We're not even making fun of each other.