https://kotlinlang.org logo
#announcements
Title
# announcements
j

jackmiras

02/21/2017, 1:57 PM
@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

mg6maciej

02/21/2017, 2:06 PM
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

jackmiras

02/21/2017, 2:11 PM
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

mg6maciej

02/21/2017, 2:12 PM
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

jackmiras

02/21/2017, 2:28 PM
Nice, I'll take a look soon as possible!