avatar
Great article. I just want to note another typo: it's written equals and hashMap methods, but I suppose you wanted to write about equals and hashCode.
avatar
Hey, Jochen. Uh, thanks for pointing that out. Not the smoothest experience. I'll try to take care later this week.
avatar
What doesn't seem to work well is getting authenticated to comment (using Twitter for example) without the comment being lost.
Also it seems that when using the link in the notification e-mail subsequent authentication after clicking comment doesn't bring you back to where you started. (At least not on Safari)
avatar
Heh. We'll see. Just in case you want to write/publish your own one, there is a "+" button in navbar :)
avatar
I avoid implicits like the plague.
It's yet another convenience (aka write less) taken too far.
Thanks for getting back to me.

I'd love to see similar articles about Groovy, Kotlin, Ceylon and Fantom! :)
avatar
Very true about code readability. Scala is definitely one of the tools that can produce a lot of spaghetti code unless you use the language «the right way». Just curious, how often do you use implicits?
avatar
And I would submit to you that some of the «Scala Peculiarities» should be used rarely if at all.If you don't agree on a common, simple standard for scala code in your organization, you will accumulate a lot of technical debt.Code is read more often that it is written or changed.If reading it is a chore, you've failed.And in languages like scala it is very easy to write code that is hard to read.
avatar
Oh, good catch! Resolved.P.S. There is a «code» tag for commenting code blocks, e.g.
if (Log.enabled) {
    Log.log(message)
}
avatar
You have a slight typo, should be «new DoBody» not «new DoDody»object Do{ def apply(body: => Unit) = new DoDody(body)} class DoBody(body: => Unit){ def until(cond: =>Unit): Unit = { body while(!cond) body }}
avatar
The case class example at the beginning does not generate setter methods, only getter methods. You would need to change the constructor parameters to vars to generate setter methods. By default, they're treated as vals.
avatar
Love it!
avatar
oh boy...forgot parenthesis. That's why unit tests exist.
avatar
object Mouth {
  def say(str: String) = println(str)
}

Mouth.say("Good job, Kukuruku."
avatar
The new design looks great! Go KKRK!
avatar
Thank you so much for a (very very) ^ (googol) good article, sir :D you saved my life, thank you again and again :D
avatar
What operations do you specifically mean?
avatar

Dear Hub,
Thanks for your kindly reply. I noticed that the implementation you suggested used push operation instead of recursive function. How do you think the efficiency of these two implementations?

Thanks,
Tang Laoya 
avatar
You are fun. Seriously. Unfortunately, Nikolai Ershov is not around to comment on how to improve the code. But I think your code looks good. You can also check this implementation: AVLTree.h and AVLTree.cpp.
avatar
Dear Hub,

The problem is solved after modified the function popmax as follows:
void * popmax(avltree* &p)
{
        avltree* max=findmax(p);
        void *key=max->key;
        p=remove(p,key);
        return key;
}

Do you have any suggestion to improve the code for faster speed, especially the function popmax?

Thanks,
Tang Laoya

avatar
Dear Hub,   
Sorry to bother you again. There are still some problems. 
when the code running in the latter (after many times insert/remove/popmax operations, the code will crash. 

The code is used as follows:
node *avlroot;

avlroot=insert(avlroot,(void*)t);  /// happened at many locations
...
avl=popmax(avlroot);  /// happened at many locations
...
avlroot=remove(avlroot,(void*)t); /// happened at many locations
...

/// finally
deletetree(avlroot);

Is there any problem in using the code?

Thanks,
Tang Laoya