title: Is Scala idiomatic coding style just a cool trap for writing inefficient code?
body: <p>I sense that the Scala community has a little big obsession with writing "concise", "cool", <strong>"scala idiomatic"</strong>, "one-liner" -if possible- code. This is immediately followed by a comparison to Java/imperative/ugly code.</p>
  
  <p>While this (sometimes) leads to easy to understand code, it also leads to inefficient code for 99% of developers. And this is where Java/C++ is not easy to beat.</p>
  
  <p>Consider this simple problem: <strong>Given a list of integers, remove the greatest element.</strong> Ordering does not need to be preserved.</p>
  
  <p>Here is my version of the solution (It may not be the greatest, but it's what the average non-rockstar developer would do).</p>
  
  <pre><code>def removeMaxCool(xs: List[Int]) = {
    val maxIndex = xs.indexOf(xs.max);
    xs.take(maxIndex) ::: xs.drop(maxIndex+1)
  }
  </code></pre>
  
  <p>It's Scala idiomatic, concise, and uses a few nice list functions. It's also very inefficient. It traverses the list at least 3 or 4 times.</p>
  
  <p>Here is my totally uncool, Java-like solution. It's also what a reasonable Java developer (or Scala novice) would write.</p>
  
  <pre><code>def removeMaxFast(xs: List[Int]) = {
      var res = ArrayBuffer[Int]()
      var max = xs.head
      var first = true;   
      for (x &lt;- xs) {
          if (first) {
              first = false;
          } else {
              if (x &gt; max) {
                  res.append(max)
                  max = x
              } else {
                  res.append(x)
              }
          }
      }
      res.toList
  }
  </code></pre>
  
  <p>Totally non-Scala idiomatic, non-functional, non-concise, but it's very efficient. It traverses the list only once!</p>
  
  <p>So, if 99% of Java developers write more efficient code than 99% of Scala developers, this is a huge 
  obstacle to cross for greater Scala adoption. Is there a way out of this trap?</p>
  
  <p>I am looking for practical advice to avoid such "inefficiency traps" while keeping implementation clear ans concise.</p>
  
  <p><strong>Clarification:</strong> This question comes from a real-life scenario: I had to write a complex algorithm. First I wrote it in Scala, then I "had to" rewrite it in Java. The Java implementation was twice as long, and not that clear, but at the same time it was twice as fast. Rewriting the Scala code to be efficient would probably take some time and a somewhat deeper understanding of scala internal efficiencies (for vs. map vs. fold, etc)</p>