I Tried To Write an Object-Oriented Program in a Non-OOP Language (Golang). Did I Succeed?

Поділитися
Вставка
  • Опубліковано 1 жов 2024

КОМЕНТАРІ • 26

  • @igorraven8870
    @igorraven8870 Рік тому +2

    I do wish ( GO ) had a IDE like and as complete as Lazarus ( Object Pascal ) ;-)

    • @LearnWithHuw
      @LearnWithHuw  Рік тому

      Go in the full version of Visual Studio would be great. The Go support in Visual Studio Code is pretty good though.

    • @cinderwolf32
      @cinderwolf32 3 місяці тому

      The language server in Visual Studio Code, and the extension to integrate it with the editor (both of which are developed by the Go team), are better than most others I've seen.

  • @vectorhacker-r2
    @vectorhacker-r2 Рік тому +2

    I’d argue that Go IS object oriented

    • @LearnWithHuw
      @LearnWithHuw  Рік тому

      I know some people say that. It's an open debate, I think. At any rate, it doesn't have classes or inheritance which is the element of object orientation that I've concentrated on here.

    • @vectorhacker-r2
      @vectorhacker-r2 Рік тому

      @@LearnWithHuw I don't think you need classes or inheritance to do proper OO. I think the main focus is on messaging and encapsulation.

    • @LearnWithHuw
      @LearnWithHuw  Рік тому +1

      @@vectorhacker-r2 Yes. A good point. Maybe this is something I should discuss more fully in another video? But the particular feature I'm exploring here is the nature of "class hierarchies".
      This is from the GO FAQ:
      "Is Go an object-oriented language?
      Yes and no. Although Go has types and methods and allows an object-oriented style of programming, there is no type hierarchy."
      I can't think of any other language describing itself as OOP that omits class hierarchies. I think I've shown that indeed Go does make "an object oriented style of programming" reasonably easy. However, using any pure OO language (like Smalltalk) or any other mainstream OO language (C#, Java etc.) class hierarchies would normally be thought of as a fundamental feature.

  • @CsiklosMiklos
    @CsiklosMiklos Рік тому +2

    Many software under the Linux/BSD world are written in C language, and if you take a look at the GUI libraries, for example GTK, they are using some rudimentary reimplementation of an object system. In some cases it's because of the age of the software, in other cases it's like that to provide stable ABI and compatibility with other languages, but mostly they use C because masochism ;)

    • @LearnWithHuw
      @LearnWithHuw  Рік тому +1

      I use C for some projects too. It wouldn't be my language of choice for the sort of project I show in this video. But it certainly could be done!

    • @simontillson482
      @simontillson482 2 місяці тому

      I wrote console and PC games for years in pure C. We had hundreds of objects in each game. No masochism required!
      Objects just allow one to smush together structures and methods, that’s all. Whether you think this is a revolutionary advancement or just syntactic sugar is largely moot. If it works, who cares?
      P.S. in C, structs can include function pointers, so technically you can have methods too which can be arbitrarily assigned or replaced at will. Try doing that in C++!

  • @igorraven8870
    @igorraven8870 Рік тому +2

    Thank you very much for the excellent presentation.
    I think that being able to implement in either procedural or object oriented format is a very valuable skill.
    The dogma that is single philosophy is appropriate for all situations can be quite limiting.

  • @fluffykitties9020
    @fluffykitties9020 Рік тому +1

    Hmm, in fact what's happening here is not typical OOP, but in essence it is OOP. I thought it would be doing it in something like BASIC or a purely procedural language. I think that would have been more informative to seen the convenience that OOP brings.

    • @LearnWithHuw
      @LearnWithHuw  Рік тому

      I wanted to use a modern and widely-used language. But it's certainly possible to create something similar in Basic, if you put your mind to it. The adventure game I wrote in the 80s was in Turbo Pascal, which had nothing remotely similar to OOP.

  • @JLarky
    @JLarky Рік тому +2

    If you want a little bit more challenge you can try writing it in Erlang/Elixir 😂

    • @LearnWithHuw
      @LearnWithHuw  Рік тому +2

      Or, to backtrack from Erlang syntax, try Prolog. I was besotted with Prolog for a while. Maybe I'll do some viedos on that language some time?

  • @luisz0339
    @luisz0339 Рік тому +1

    Nice experiment. Is always interesting to see struct use in places were classes would make things a bit easier.

    • @LearnWithHuw
      @LearnWithHuw  Рік тому +1

      The first adventure game I ever wrote was in Turbo Pascal - with no objects of any description. So all the "objects" were done using records (the Pascal version of structs). It's definitely easier to write this kind of code in Go than in (traditional) Pascal.

  • @salman0ansari
    @salman0ansari Рік тому +1

    you deserve more subs

  • @psi4j
    @psi4j Рік тому

    Do Rust!

    • @LearnWithHuw
      @LearnWithHuw  Рік тому +1

      I was already thinking about that. I'll add it to my list! 🙂

  • @dfghj241
    @dfghj241 Рік тому

    i would love to see you writing Non OOP in an OOP language. that would be cool.

    • @LearnWithHuw
      @LearnWithHuw  Рік тому +2

      Ha! To be honest, I think many programmers do that anyway. They just don't realise they are doing it. A good idea for a video, though. I'll give some thought to that!

  • @JLarky
    @JLarky Рік тому

    How would you change this code to use less OOP oriented approach?

    • @LearnWithHuw
      @LearnWithHuw  Рік тому +1

      You could certainly define each struct independently of the others then create libraries of functions to act on those structs (as data) rather than being typed to work with specific structs. Give it a go and see which approach you prefer.