<@U0KBF8D7V> in a case like this: ``` override fun...
# announcements
j
@Paul Woitaschek in a case like this:
Copy code
override fun post(req: Request, res: Response): Any {
        val platform = req.bodyAsObject() as Platform
        if (platform.isValid()) {
            PlatformRepository().save(platform)
            return object { val message = "Platform created" ; val status = 201 }
        } else {
            return renderInvalidParams()
        }
    }
I could avoid doing the
if else
statement by using functions as callback... just like this:
Copy code
override fun post(req: Request, res: Response): Any {
        req.bodyAsObject(success = {
            PlatformRepository().save(platform)
            return object { val message = "Platform created" ; val status = 201 }
        }, failure = {
            return renderInvalidParams()
        })
    }
m
jackmiras: I can't see how you avoid
if
there. You are hiding it, adding abstraction that doesn't seem to solve any of: 1) having less client code, 2) having client code that is easier to understand (actually doing the opposite here imo), 3) having client code matching domain more closely (i.e. DSL)
j
Yeah I agree with you, had some of this impressions but is my first days work with Kotlin I'm trying figure out what can I do and how can I do stuff with Kotlin.
And there is nothing better to ask people around 😄
m
You could do this kind of "tricks" in any language.
Follow Zen of Python and you will be good: https://www.python.org/dev/peps/pep-0020/ Here: Simple is better than complex.
j
Nice, I'll take a look soon as possible!