Any ideas how to abstract that?

  • 15
  • 1
    What IDE is this? I like the editor color scheme. Can you share that :D?
  • 5
    Even if it's not user input data, please never write your sql statements using string interpolation
  • 2
    @Kyu96 it’s dracula theme for intellij (but they have it for all popular ide’s) + firacode font with ligatures enabled, 14pt size with 1.2 line spacing. I also use same setup for python, though its slightly different (more cyan, and less pink)
  • 0
    @AlexDeLarge I don’t see how changing the language affects OOP principles. Let’s say it’s written in Java, so I am stuck with the same shit.
  • 0
    @julkali it’s ok, this is just abstraction for reusable expression. And this is actually DQL (doctrine dsl for sql), so I always get error if interpolated values are invalid.
  • 2
    Could extract the logic into objects that expose some methods like

    supports($prediction, $actual): bool
    result(): int

    Then in a loop return the first supported result()
  • 1
    "switch(true)" yeah, fuck this
  • 0
  • 0
    @Bitwise first case is checking if prediction and actual result is the same:
    actualHome = predictedHome.

    Then ifs below are checking which team was the winner:
    predictedHome > predictedAway
    Same as:
    actualHome > actualAway

    @AlexDeLarge something I can agree with, but language after all is just a tool

    @jallman112 https://draculatheme.com
  • 0
    @Bitwise oh, come on:

    aH = 3 | aA = 5
    pH = 3 | pA = 5

    If aH == pH && aA == pA: # true
    if aH > aA: 6 # false
    elseif aH < aA: 6 # true
    else: 3

    PS: u figured it out already I see, well its devrant ing compression not much I can do.
  • 0
    Yes, switch was for readability and also for easier reasoning compared to SQL.

    Abstraction is needed, though, to separate SQL and PHP implementations and reduce duplication for easier future maintenance
  • 1
    @gintko Cool! I'm just used to people getting autocorrected on that.

    I guess everyone can use regular TIL moments 😀
  • 0
    What exactly do you mean by abstracting a SQL and a PHP script?

    One abstraction for a script is a function. Just wrap it in a function and it's abstracted to one function from multiple lines of code.

    That wasn't probably what you meant.
  • 0
    @joas @Bitwise what I meant, was refactoring code so it can comply with solid and dry, which in this case can be only approached by abstracting the code or in other words, splitting code into higher level class(-es) which then can be reused to implement actual logic.

    Anyway, I kind of solved it in the not the best way by defining template methods for specific instructions, that really does nothing besides documenting the code. I can post link here on tuesday if someone is interested.

    I figured, that probably the best way to achieve reusability here, is to implement builder pattern which abstracts both SQL and PHP DSLs, sth like following:

    Anyway, thats overengineering for my case.
Your Job Suck?
Get a Better Job
Add Comment