This project was interesting. Recently, I’ve been digging into the functional programming paradigm. This is one of my first tries at it. I’ve been doing OOP until recently, but this project really was impressive to me. The whole implementation took about nine hours. Functional programming is much less convoluted. I spent more time programming than deciding on a good name for a certain identifier.

Not only is functional programming more efficient, but I can also see that it’s much less tedious to write automated tests for. I only have to take care of the local scope of the function I am writing a test for; there is no need to deal with the parent’s inherited mess or even any parent’s mere state. I just have to write the test for the function.

I have scraped the Cambridge Dictionary to collect the data.

The project is licensed under MIT at:

https://github.com/eeriemyxi/novi

https://git.envs.net/myxi/novi

  • Serinus@lemmy.world
    link
    fedilink
    arrow-up
    27
    arrow-down
    2
    ·
    9 months ago

    If your OO experience is from Java, the problem is with Java culture, not OO in general.

    Putting functions and properties into classes is good and helpful. Whyever the fuck Java people want to implement the factory pattern three times in every application they make is convoluted and asinine.

    • myxi@feddit.nlOP
      link
      fedilink
      English
      arrow-up
      10
      ·
      9 months ago

      My OOP experience isn’t from Java, but I get your point. I don’t really have a dislike for OO; it sure does have its applications. I once met a dude who was trying to use an object oriented library in a functional way; the result of that was a mess full of complications. I feel a good balance is necessary.

  • mox@lemmy.sdf.org
    link
    fedilink
    arrow-up
    14
    arrow-down
    1
    ·
    edit-2
    9 months ago

    Object oriented programming rose to popularity a few decades ago, along with a great deal of indoctrination and marketing for both the paradigm and related products. It was pushed so hard and so widely that more than a few folks grew into their developer roles assuming it was the best approach to every problem. Of course, it isn’t.

    (It definitely is useful at times, though, so please don’t condemn it just because it’s sometimes a square peg in a round hole.)

    I’m glad to see you have discovered an alternative, and I hope you will continue to expand your toolbox and aim for simplicity.

    • matcha_addict@lemy.lol
      link
      fedilink
      arrow-up
      10
      arrow-down
      2
      ·
      9 months ago

      People don’t realize that OOP was pushed because some companies, like Sun microsystems, profited from its popularity.

      • Traister101@lemmy.today
        link
        fedilink
        arrow-up
        14
        ·
        9 months ago

        When it’s easier to think about a system in terms of objects. The classic example is video game Entities/Game Objects. GUI stuff has also been very pleasant with OOP as buttons and the like are all easily conceptualized and worked with when seen as objects.

        • Miaou
          link
          fedilink
          arrow-up
          1
          ·
          9 months ago

          ECS is arguably a better for game dev, so even that point is debatable.

      • mox@lemmy.sdf.org
        link
        fedilink
        arrow-up
        7
        ·
        edit-2
        9 months ago

        I think desktop GUI toolkits are a pretty good use case for object-oriented design, mainly because mapping window/widget families onto class hierarchies is straightforward.

        That’s not to say that a good functional design is impossible; it’s just not particularly obvious.

      • Kache@lemm.ee
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        9 months ago

        One of the best use cases is implementing abstract data types and hiding the memory management and other potentially unsafe optimization tricks behind a clean and high level abstraction.

        Also since it’s a logical/mathematical construct and not attempting to model the real world (like business logic), it’s one case where inheritance hierarchies will remain stable.

    • Truck_kun@beehaw.org
      link
      fedilink
      English
      arrow-up
      2
      ·
      9 months ago

      Wasn’t there a video a while back of a presentation that OOP was created as a joke or something, and the person was surprised people were taking it seriously. Might have been advertised as the creator or OOP.

      I took the video as a joke anyways, not a serious thing, but who knows. I don’t even remember if it was OOP, or some other paradigm, or language, or who knows what else.

      If anyone could find/link to it, I’d love to watch it again, but I’m having no luck; so my memory may be faulty.

  • demesisx@infosec.pub
    link
    fedilink
    English
    arrow-up
    10
    arrow-down
    1
    ·
    9 months ago

    As someone else mentioned, you should rewrite this in Haskell (or Purescript or Scala or even Python’s ‘Coconut’) because using vanilla Python for functional programming is like driving Formula 1 with a Toyota Camry.

      • demesisx@infosec.pub
        link
        fedilink
        English
        arrow-up
        9
        arrow-down
        1
        ·
        9 months ago

        Nice. I don’t know much about Nim.

        I should also mention: Once Purescript switches over to a Chez Scheme compiled back end, it would be (IMO) the ideal lightweight Haskell, suited to quick terminal apps that you’re looking for.

        • myxi@feddit.nlOP
          link
          fedilink
          English
          arrow-up
          2
          arrow-down
          1
          ·
          edit-2
          9 months ago

          Thanks for note. Do they currently have that backend?

          That aside, you might want to try Nim. It’s pretty cool. It can compile to C and C++, and JS. There have been browser extensions made with it. Heck, it even has an LLVM backend. And the C code it generates it pretty fast on benchmarks. It’s filled with tons of metaprogramming stuff and AST-level macros. And it has this cool thing where it can ignore name casing of identifiers like variables and functions; so isSome == is_some.

  • litchralee@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    8
    ·
    9 months ago

    I saw “terminal” and “dictionary” and thought this was going to be using the DICT protocol to retrieve definitions. If that’s not supported, could that be added?

    Not for any reason other than I think it’s cool to look up stuff remotely using nothing more than curl. But this is definitely easier to read.

    • myxi@feddit.nlOP
      link
      fedilink
      English
      arrow-up
      9
      ·
      9 months ago

      You mean, like, support for the dict protocol for this program’s interface? I am also scraping a dictionary’s data, so I am a little confused.

      • litchralee@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        10
        ·
        edit-2
        9 months ago

        What I mean is, this program draws from a scraped database, right? Is there any reason it couldn’t also search an online database using DICT, to potentially get more definitions that aren’t in the Cambridge Dictionary?

        Excellent work, btw

        • myxi@feddit.nlOP
          link
          fedilink
          English
          arrow-up
          5
          ·
          9 months ago

          Hi, I spent some time trying out the dictd package. I also read this protocol’s specification. As things are right now, each host-name would require its own parser, because I couldn’t notice a very similar pattern between them. Webster, Jargon, wn, all these have their own standardization for including synonyms and examples.

          The specification doesn’t enforce any pattern on the definitions either. I don’t think it’s going to be very useful even if I do implement it because the parsers are going to be quite complicated.

  • Johannes@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    9 months ago

    If you’re interested in functional programming you could try haskell. It has a reputation for a steep learning curve but it was worth learning for me.

    • myxi@feddit.nlOP
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      1
      ·
      edit-2
      9 months ago

      Oh yeah, I had given that a try, but the installation was too huge. It took like 2 GB. The dependecies were huge as well. But maybe it’d be less on Ubuntu. I will give it a shot again. I heard that language doesn’t have loops; I guess you’ve got to be good with recursion to get good at it lol.

      Or maybe people rely on map like function of Python.