<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Commenti a: I don&#8217;t like infixes</title>
	<link>http://www.francolombardo.net/i-dont-like-infixes_post-103.html</link>
	<description>Linguaggio Scala, Java, AS400 e...cose più serie</description>
	<pubDate>Tue, 21 May 2013 12:32:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>Di: Franco Lombardo</title>
		<link>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9225</link>
		<dc:creator>Franco Lombardo</dc:creator>
		<pubDate>Mon, 12 Apr 2010 19:54:59 +0000</pubDate>
		<guid>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9225</guid>
		<description>@fogus
You said &lt;cite&gt;"what happens if you need to compare more than just Ints? What if you need to mix them?"&lt;/cite&gt;
Well, here is an example:
&lt;pre lang="scala"&gt;
package net.fl.clojure

object ClojureDemoGeneric {
  case class RichList[A] (list : List[A]) {
    def isOrderedBy(f: (A, A) =&gt; Boolean) : Boolean = list match {
      case Nil =&gt; true
      case x :: Nil =&gt; true
      case x :: y :: xs =&gt; f(x, y) &#038;&#038; new RichList[A](y :: xs).isOrderedBy(f)
    }
  }
 
  implicit def listConverter[A] (list: List[A]) = new RichList[A](list)  
 
  def main(args : Array[String]) : Unit = {
    //lexicographic ordering: prints true
    println(List("a", "c", "z").isOrderedBy(_ &lt; _))
    
    //natural nubers ordering: prints false
    println(List(1, 20, 4) isOrderedBy (_ &lt; _))
 
    //floating point ordering: prints true
    println((1.0 :: 2.5 :: 3.9 :: Nil).isOrderedBy(_ &lt; _))
    
    //custom ordering: prints false
    println(List("one", 2, 3.0) isOrderedBy ((x, y) =&gt; x.toString() &lt; y .toString()))
  }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@fogus<br />
You said <cite>&#8220;what happens if you need to compare more than just Ints? What if you need to mix them?&#8221;</cite><br />
Well, here is an example:</p>
<pre lang="scala">
package net.fl.clojure

object ClojureDemoGeneric {
  case class RichList[A] (list : List[A]) {
    def isOrderedBy(f: (A, A) => Boolean) : Boolean = list match {
      case Nil => true
      case x :: Nil => true
      case x :: y :: xs => f(x, y) &#038;&#038; new RichList[A](y :: xs).isOrderedBy(f)
    }
  }

  implicit def listConverter[A] (list: List[A]) = new RichList[A](list)  

  def main(args : Array[String]) : Unit = {
    //lexicographic ordering: prints true
    println(List("a", "c", "z").isOrderedBy(_ < _))

    //natural nubers ordering: prints false
    println(List(1, 20, 4) isOrderedBy (_ < _))

    //floating point ordering: prints true
    println((1.0 :: 2.5 :: 3.9 :: Nil).isOrderedBy(_ < _))

    //custom ordering: prints false
    println(List("one", 2, 3.0) isOrderedBy ((x, y) => x.toString() < y .toString()))
  }
}
</pre>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Di: Franco Lombardo</title>
		<link>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9224</link>
		<dc:creator>Franco Lombardo</dc:creator>
		<pubDate>Mon, 12 Apr 2010 15:37:40 +0000</pubDate>
		<guid>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9224</guid>
		<description>Here I use the term "Literate Programming" not in the strict Knut's sense, but in the meaning, that is now widespread, of a style of programming that mimics natural languages. See, for example, &lt;a href="http://weblogs.java.net/blog/tomwhite/archive/2006/05/literate_progra_1.html" rel="nofollow"&gt;this post on java.net&lt;/a&gt;. (But you can find a similar usage in many articles on Behaviour Driven Development).
Anyway, even if my opinion is that the maximum of code expressivity is gained by mixing infix and prefix notations, as I told before, you can have a purely infix Scala code using &lt;code&gt;(1 :: 2 :: 3 :: Nil) isOrderedBy (_ &lt; _)&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Here I use the term &#8220;Literate Programming&#8221; not in the strict Knut&#8217;s sense, but in the meaning, that is now widespread, of a style of programming that mimics natural languages. See, for example, <a href="http://weblogs.java.net/blog/tomwhite/archive/2006/05/literate_progra_1.html" rel="nofollow">this post on java.net</a>. (But you can find a similar usage in many articles on Behaviour Driven Development).<br />
Anyway, even if my opinion is that the maximum of code expressivity is gained by mixing infix and prefix notations, as I told before, you can have a purely infix Scala code using <code>(1 :: 2 :: 3 :: Nil) isOrderedBy (_ < _)</code></code></p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: nibble</title>
		<link>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9223</link>
		<dc:creator>nibble</dc:creator>
		<pubDate>Mon, 12 Apr 2010 13:43:05 +0000</pubDate>
		<guid>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9223</guid>
		<description>my 2 cents:
 * Mixing infix and prefix notation, like you do in your scale example, don\'t seems to me \&#34;more clear\&#34; than a pure infix (C) or prefix (clojure) solution.
 * You talk about Literate Programming, but prefix and infix notation has nothing to do with LP. You are talking about code clarity, and seems to me that here you are saying that infix notation is \&#34;more clear\&#34; because it\'s more widespread... 

regards
nibble</description>
		<content:encoded><![CDATA[<p>my 2 cents:<br />
 * Mixing infix and prefix notation, like you do in your scale example, don\&#8217;t seems to me \&quot;more clear\&quot; than a pure infix (C) or prefix (clojure) solution.<br />
 * You talk about Literate Programming, but prefix and infix notation has nothing to do with LP. You are talking about code clarity, and seems to me that here you are saying that infix notation is \&quot;more clear\&quot; because it\&#8217;s more widespread&#8230; </p>
<p>regards<br />
nibble</p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: Franco Lombardo</title>
		<link>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9220</link>
		<dc:creator>Franco Lombardo</dc:creator>
		<pubDate>Mon, 12 Apr 2010 12:23:23 +0000</pubDate>
		<guid>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9220</guid>
		<description>@jneira
You say &lt;cite&gt;"more sintactic sugar, more prone to errors and less elegance"&lt;/cite&gt;.
I agree about syntactic sugar, while about the point of "error proness" I think it's in someway true, even if, on the other hand, you must consider how many errors you'll do in a language that's not "clear".
About elegance, well, you already said...</description>
		<content:encoded><![CDATA[<p>@jneira<br />
You say <cite>&#8220;more sintactic sugar, more prone to errors and less elegance&#8221;</cite>.<br />
I agree about syntactic sugar, while about the point of &#8220;error proness&#8221; I think it&#8217;s in someway true, even if, on the other hand, you must consider how many errors you&#8217;ll do in a language that&#8217;s not &#8220;clear&#8221;.<br />
About elegance, well, you already said&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: Franco Lombardo</title>
		<link>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9219</link>
		<dc:creator>Franco Lombardo</dc:creator>
		<pubDate>Mon, 12 Apr 2010 12:16:17 +0000</pubDate>
		<guid>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9219</guid>
		<description>@fogus

My point is that, with a flexible language like Scala, you can have many solutions: you can use the prefix notation, or the infix one if you feel it better. In other languages you have only one choice, which, I think, most of the times is far less readable.</description>
		<content:encoded><![CDATA[<p>@fogus</p>
<p>My point is that, with a flexible language like Scala, you can have many solutions: you can use the prefix notation, or the infix one if you feel it better. In other languages you have only one choice, which, I think, most of the times is far less readable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: fogus</title>
		<link>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9218</link>
		<dc:creator>fogus</dc:creator>
		<pubDate>Mon, 12 Apr 2010 11:40:29 +0000</pubDate>
		<guid>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9218</guid>
		<description>You've slightly changed the original problem at hand and I'm a little confused about your insistence on the "infix notation of Clojure", but I'll bite.

The original premise was built on finding the monotonically increasing order of a number of arguments, which in Scala could be written as a function isminc:

def isminc(a:Int, b:Int, c:Int, d:Int, e:Int):Boolean = a &#60; b &#38;&#38; b &#60; c &#38;&#38; c &#60; d &#38;&#38; d &#60; e
isminc(1,2,3,4,5)
res6: Boolean = true

That's Scala, not C.  You know the Clojure solution, so there is no need to cover that ground, but let's put it into a function:

(defn minc? [a b c d e] (&#60; a b c d e))
(minc? 1 2 3 4 5)
true

This is the original premise, and I would contest that the Clojure example is far more readable.  However, by changing the problem in the way you did, you've actually helped to prove my original point.  That is, you've taken a problem solved by a somewhat verbose infix solution, put it into a list and made it into a more flexible method call *prefix* solution.  Your way (or some variant thereof... I would have probably used a Trait instead, but I realize that you want to keep things as compact as possible) was probably the correct way to solve this particular problem.  But what happens if you need to compare more than just Ints?  What if you need to mix them?  BTW: I like Scala and I use it every day, so don't take this as a slam against it.  Instead, people like to pick and choose straw-man arguments against prefix notation without thinking through the vast number of cases where it makes sense.  Even if your code was littered with a vast number of 1 + 2 then it's debatable that using (+ 1 2) instead makes things harder to read.</description>
		<content:encoded><![CDATA[<p>You&#8217;ve slightly changed the original problem at hand and I&#8217;m a little confused about your insistence on the &#8220;infix notation of Clojure&#8221;, but I&#8217;ll bite.</p>
<p>The original premise was built on finding the monotonically increasing order of a number of arguments, which in Scala could be written as a function isminc:</p>
<p>def isminc(a:Int, b:Int, c:Int, d:Int, e:Int):Boolean = a &lt; b &amp;&amp; b &lt; c &amp;&amp; c &lt; d &amp;&amp; d &lt; e<br />
isminc(1,2,3,4,5)<br />
res6: Boolean = true</p>
<p>That&#8217;s Scala, not C.  You know the Clojure solution, so there is no need to cover that ground, but let&#8217;s put it into a function:</p>
<p>(defn minc? [a b c d e] (&lt; a b c d e))<br />
(minc? 1 2 3 4 5)<br />
true</p>
<p>This is the original premise, and I would contest that the Clojure example is far more readable.  However, by changing the problem in the way you did, you&#8217;ve actually helped to prove my original point.  That is, you&#8217;ve taken a problem solved by a somewhat verbose infix solution, put it into a list and made it into a more flexible method call *prefix* solution.  Your way (or some variant thereof&#8230; I would have probably used a Trait instead, but I realize that you want to keep things as compact as possible) was probably the correct way to solve this particular problem.  But what happens if you need to compare more than just Ints?  What if you need to mix them?  BTW: I like Scala and I use it every day, so don&#8217;t take this as a slam against it.  Instead, people like to pick and choose straw-man arguments against prefix notation without thinking through the vast number of cases where it makes sense.  Even if your code was littered with a vast number of 1 + 2 then it&#8217;s debatable that using (+ 1 2) instead makes things harder to read.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: jneira</title>
		<link>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9216</link>
		<dc:creator>jneira</dc:creator>
		<pubDate>Mon, 12 Apr 2010 08:14:17 +0000</pubDate>
		<guid>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9216</guid>
		<description>Yum, i didnt know that the great influence of haskell on scala also applied to building lists.
In scala,haskell (or c++ with operator overloading) you can choose or mix the notations you are more familiar (literally is familiar IMO) to build dsls close to english but it has a price: more sintactic sugar, more prone to errors and less elegance. But "elegance" is still more subjective than "naturalness" :-P</description>
		<content:encoded><![CDATA[<p>Yum, i didnt know that the great influence of haskell on scala also applied to building lists.<br />
In scala,haskell (or c++ with operator overloading) you can choose or mix the notations you are more familiar (literally is familiar IMO) to build dsls close to english but it has a price: more sintactic sugar, more prone to errors and less elegance. But &#8220;elegance&#8221; is still more subjective than &#8220;naturalness&#8221; <img src='http://www.francolombardo.net/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: Franco Lombardo</title>
		<link>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9215</link>
		<dc:creator>Franco Lombardo</dc:creator>
		<pubDate>Mon, 12 Apr 2010 07:27:36 +0000</pubDate>
		<guid>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9215</guid>
		<description>I agree with you : learning to switch from infix and prefix notation could really 
expand and improve your mind. Anyway, at least in the european modern languages I know, the infix notation is preminent. So, if we want to go in the direction of literate programming, we should choose programming languages that can use it. Moreover, as you said, Scala, as natural languages, has a mixed notation, while Lisp-like ones are more rigid in the direction of infix notation.
By the way, in Scala you could write &lt;code&gt;println( (1 :: 2 :: 3 :: Nil).isOrderedBy(_ &lt; _))&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I agree with you : learning to switch from infix and prefix notation could really<br />
expand and improve your mind. Anyway, at least in the european modern languages I know, the infix notation is preminent. So, if we want to go in the direction of literate programming, we should choose programming languages that can use it. Moreover, as you said, Scala, as natural languages, has a mixed notation, while Lisp-like ones are more rigid in the direction of infix notation.<br />
By the way, in Scala you could write <code>println( (1 :: 2 :: 3 :: Nil).isOrderedBy(_ < _))</code></code></p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: jneira</title>
		<link>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9214</link>
		<dc:creator>jneira</dc:creator>
		<pubDate>Mon, 12 Apr 2010 06:14:15 +0000</pubDate>
		<guid>http://www.francolombardo.net/i-dont-like-infixes_post-103.html#comment-9214</guid>
		<description>Mmm i think the only sin of prefix (or fortran postfix)  notation is being less popular than infix one. There isnt a only "natural" way of lang syntax, neither real langs nor prog langs. I think learn to switch from one to another expand and improve your mind.
F. e. x=x+1 is very common in imperative prog and its completely different in "natural" math and in a imperative lang.
Your scala example have prefix and postfix notation, cause "List" is in first place and "isOrderedBy" is in last one and its very much verbose than in clojure and c.
In haskell make a list have a real infix notation a:b:c:d:e:f:g:[]. isnt it strange? ;-)</description>
		<content:encoded><![CDATA[<p>Mmm i think the only sin of prefix (or fortran postfix)  notation is being less popular than infix one. There isnt a only &#8220;natural&#8221; way of lang syntax, neither real langs nor prog langs. I think learn to switch from one to another expand and improve your mind.<br />
F. e. x=x+1 is very common in imperative prog and its completely different in &#8220;natural&#8221; math and in a imperative lang.<br />
Your scala example have prefix and postfix notation, cause &#8220;List&#8221; is in first place and &#8220;isOrderedBy&#8221; is in last one and its very much verbose than in clojure and c.<br />
In haskell make a list have a real infix notation a:b:c:d:e:f:g:[]. isnt it strange? <img src='http://www.francolombardo.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
