karelpeeters
09/27/2019, 1:01 PMRuckus
09/27/2019, 2:00 PMkarelpeeters
09/27/2019, 2:06 PMMatteo Mirk
09/27/2019, 3:04 PMOptional
everywhere, even if a plain old if/else is more readableLou Morda
09/27/2019, 4:26 PMtDnamein
09/27/2019, 7:34 PMRuckus
09/27/2019, 7:43 PMtDnamein
09/27/2019, 9:06 PMif(true)
println("true")
else
println("false")
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:
val result: String =
if(true)
"TRUE"
else
"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.Ruckus
09/27/2019, 9:09 PMif (t) a else b
, java is t ? a : b
, Python is a if (t) else b
(I really dislike that one), etc. so your claim that
In the second case it is most likely a solely functional languageis fundamentally wrong.
tDnamein
09/27/2019, 9:16 PMRuckus
09/27/2019, 10:12 PMtDnamein
09/27/2019, 10:22 PMnapperley
09/29/2019, 1:55 AMval i: String = if (isEmpty()) "other" else "ssss"
The code above is much more readable than the elseIf
function version.