Problem with object oriented programming

2024-07-05 Thread Isofruit
Phoenix, it would be appreciated if you didn't try to start debates around your political positions (otherwise, why mention them). That would be neither productive to the discussion, nor give you any helpful replies, other than annoy people.

Problem with object oriented programming

2024-07-05 Thread phoenix27
Yes, it's from my dear Delphi, from which, i'm noticing more and more, nim took a lot, including the result variable! That's good. But even if it was from 89's' pascal, what's wrong with that? Why should i always comply to some new programming FASHION "imposed" by others? And this goes beyond th

Problem with object oriented programming

2024-06-23 Thread Araq
> PS: don't prefix types with T this is not 1989 pascal :P The `T` prefix comes from Delphi, not 89's pascal. :P

Problem with object oriented programming

2024-06-23 Thread ElegantBeef
Well direct casting is unsafe and is to be avoided especially for generics. If the program flow allows it's best to just write. var myVideo = TVideo() var myVideoList = @[TMedia myVideo] # No need to cast when it's not a video list setNewDims(myVideoList) Run

Problem with object oriented programming

2024-06-23 Thread ElegantBeef
Ah sorry ±6 years

Problem with object oriented programming

2024-06-23 Thread phoenix27
I was so taken by this object oriented stuff that i didn't consider the most obvious solution, CASTING. Anyway the last part of your answer, declaring the seq as TMedia and then adding specialized classes is really neat. I'll use this solution from now on. Thank you

Problem with object oriented programming

2024-06-23 Thread Alogani
Hello, Although using generics works, this is not the only solutions, you could also use explicit casting, like that : var myVideo = TVideo() var myVideoList = @[myVideo] setNewDims(cast[seq[TMedia]](myVideoList)) Run If you use generics, it can be a good prac

Problem with object oriented programming

2024-06-23 Thread phoenix27
Often the answer comes after i already posted the problem. I was searching and came across generics, so it's really simple proc setNewDims[T](arr:seq[T])= echo arr[0].id Run It works!

Problem with object oriented programming

2024-06-23 Thread phoenix27
I have this object hierarchy with some fields : TMedia* = ref object of RootRef TVideo* = ref object of TMedia TImage* = ref object of TMedia TWebPage* = ref object of TMedia proc setNewDims(arr:seq[TMedia])= discard Run if i pass a seq[TVide