karelpeeters09/27/2019, 1:01 PM
Ruckus09/27/2019, 2:00 PM
karelpeeters09/27/2019, 2:06 PM
Matteo Mirk09/27/2019, 3:04 PM
everywhere, even if a plain old if/else is more readable
Lou Morda09/27/2019, 4:26 PM
tDnamein09/27/2019, 7:34 PM
Ruckus09/27/2019, 7:43 PM
tDnamein09/27/2019, 9:06 PM
would be an imperative style of programming in that sense that you won't find this in "pure functional" languages (most likely not even in those who are solely "functional" but not "pure functional") On the other hand this:
if(true) println("true") else println("false")
is a functional style of programming in a sense that you will find this in functional languages (even in those, which call themselves "pure functional" And while you will find an "if-else" in any language (at least in any that I one of) you have to differentiate if it can be used as a statement or can only be used as an expression. In the first case that language is most likely not solely functional (although it may be a multi-paradigm one). In the second case it is most likely a solely functional language That's why your claim basic-control flow can be found in any language and because it is so, it's common to call it imperative is just not correct- as (shortly) explained above there is a huge difference between an "if-else" in Java and an "if-else" in - let's say - Elm. Even when on the surface both look similar there are not the same. Additionally: Despite reading blogs, or chats like this one about Java-Programming, Kotlin-programming or programming in general all the time since 11 years, it's the first time for me hearing that language features common to all languages can be called imperative. Furthermore: Such usage of the term "imperative" isn't helpful even if it was wide spread. If everything common to all languages can be called imperative then it is much harder to understand what the difference is between "imperative" or "declarative" or "functional". But we as programmers need this understanding to make conscious decisions while coding. There is a difference between an "if-statement" and an "if-expression" which has implications and we should be aware of them. This awareness lets us as programmers appreciate what's special to the paradigms or programming styles and enables us to make the right choice when solving a problem.
val result: String = if(true) "TRUE" else "FALSE"
Ruckus09/27/2019, 9:09 PM
, java is
if (t) a else b
, Python is
t ? a : b
(I really dislike that one), etc. so your claim that
a if (t) else b
In the second case it is most likely a solely functional languageis fundamentally wrong.
tDnamein09/27/2019, 9:16 PM
Ruckus09/27/2019, 10:12 PM
tDnamein09/27/2019, 10:22 PM
napperley09/29/2019, 1:55 AM
The code above is much more readable than the
val i: String = if (isEmpty()) "other" else "ssss"