kotlin


Moving During The Holidays  

Preparing for Different Types of Moves: Moving During the Holidays

Moving during the holidays feels more overwhelming than any other time of the year and the dilemma about whether or not to decorate is challenging. Getting the right crew to help you with the actual moving with important; contacting these guys at Easy Moves allow you to move without stress and problems. Keep it simple but make it special with these tips.

Think Ahead
• If you have little ones, have them help you mail off a change of address card to Santa so they won’t worry about the sleigh missing its stop at your new home. You can even have your children pack Christmas stockings in their suitcase, so they can unpack and hang them right away in your new home.
• If you have the time, do yourself a favor and go through your holiday decorations before your move.
• Purge dated décor and lights that don’t work and donate any excess decorations, so you have less to move.
• If you like being super-organized, buy seasonal color-coded bins to quickly indicate which holiday decorations are in the bins. Use your label maker to neatly label the outside of the bin.
• When packing decorations, separate them by room or purpose, e.g. tree trimmings or dining room table.
• When you do use them in your new home, take a picture of the room after it has been decorated. Make decorating the following year a snap by storing the photo in the bin.
• Holiday Cards – Have your holiday cards do double duty by serving as a change of address card as well. If you’re confident of your move date, you’ll be extra glad if you order them well in advance of the holidays and prepare them by addressing and adhering postage. Bonus – many websites offer discounts for early orders!
• Be Prepared – You’ll want to keep things simple, but there may be certain things you won’t be able to avoid – like wrapping gifts. Along with your First Night Survival Box, you’ll also want to pack 1-2 holiday boxes. Your wrapping holiday box should contain:
o An extra copy of your holiday gift list
o Wrapping Paper
o Scissors
o Tape
o Gift Tags – Adhesive would be best to avoid mixing disappearing tags. Save yourself time by purchasing inexpensive adhesive labels in fun shapes online or from your office supply store; many label companies offer free holiday templates. You simply choose the template and ‘sign’ electronically.
o Ribbon

In Your New Home
Simple can be Special — If you move right before Christmas, take a break from unpacking and visit a local garden store and select a small, potted outdoor evergreen. Have the kids make home made decorations to create a sweet and simple holiday tree. When the time is right, you can plant it in your yard – it will always be there to remind you of your first holiday season in your new home. Take an annual family picture next to it so you can look back and see how the tree — and your family have grown throughout the years!

Keep the Move Merry – You can’t go wrong if you make sure your car is in great condition and your auto loan as well, by visiting completeautoloans.com, and if you remember the five ‘M’s’ of moving during the holidays:

• Music – Load up your phone with a holiday playlist or keep a few holiday CDs out for your drive or unpacking time. It’s hard not to be happy with the old favorites playing!
• Mood – Set aside one simple string of lights – place it on a little potted evergreen tree, down a stair rail, above kitchen cabinets, on a front porch or even in a bedroom. The glow of the lights will bring you a little peace for the holidays
• Movies – Everyone needs time to unwind, why not do it with a classic holiday favorite film?
• Menu – Don’t forget to think about food! Take the pressure off by ordering a holiday meal in box from your local grocery store – these meals include the main dish with all the trimmings and all you’ll do is heat and serve.
• Marvel – Amid all of the chaos, don’t forget to take a deep breath and marvel at the wonder of the holiday season.

Alone in a New Home
If you’re moving away and won’t be able to attend your usual holiday celebrations, use social media to find “orphan friends” near you in a similar situation. Invite them over for a low-key celebration. Keep the food and drinks simple and focus on reuniting with old friends and meeting new ones.

Local Holiday Happenings
The holidays are a perfect time to explore your new community. Take a break from the house and visit local holiday displays, attend a play or visit a museum. You’re sure to find lots of ideas online and in your local paper.

Keep Traditions Alive
You may be tempted to let it all slide (and who would blame you?) but try to pick one special tradition and stick with it. Plum pudding, singing carols, picking out a new ornament – you’ll be glad you’ve taken the time to enjoy the season.

Moving alone can be a stressful time, but during this holidays, it can get even more hectic! So if you’re thinking about moving during the holidays, I hope you the above tips help in many ways and make sure to check out the San Mateo County Moving Guide to allow you to better the process and move easier and with little to no stress! Wishing you the best! Remember to try and have fun! Best wishes.


Converting Carballo to Kotlin

Kotlin is a JVM language developed by JetBrains: http://kotlinlang.org gaining momentum among Android developers. Kotlin has interesting features like:

  • It can be compiled to bytecode compatible with Java >=6, allowing to use a lot of Java 7-8 features (lambdas…)  in Java 6 bytecode (=Android)
  • It can be transpiled to Javascript (like Java with GWT)

So I decided to migrate the Carballo Chess Engine code to Kotlin (and his name is Karballo) to make some experiments and having some “fun” :)… but it became a non-trivial task, the converted code is at: https://github.com/albertoruibal/karballo.

Converting the code

To start working with Kotlin I installed the Kotlin plugin for Android Studio (=IntelliJ) from:

File->Settings->Plugins->Install JetBrains Plugin

Once the Kotlin plugin is installed, it’s quite easy to convert java source files to Kotlin with: CTRL + SHIFT + ALT + K

Conversion problems

The Java to Kotlin code conversion does not work perfectly, the Carballo conversion arose these errors:

  • Kotlin is strong typed, you cannot compare a long against the literal ‘0’, you must use ‘0L’… I had hundreds of this comparisons
  • A Long cannot be initialized with an unsigned hex literal if the value does not fit in the signed type, it gives a “Value out of range” compilation error ,  so you cannot do:
    var variable = 0xffffffffffffffffL

    The solution is to convert the literals to a signed decimal:

    var variable = -1
  • Error “Property must be initialized or be abstract” with attributes not initialized in the constructor, solved adding the “lateinit” modifier to the declaration of the attributes (yes, Kotlin knows if you are initializing the attribute in the constructor)
  • Strange toInt() insertions:
    pieceNames.indexOf(pieceChar.toInt())

    should be:

    pieceNames.indexOf(pieceChar)
  • Variables of type Byte cannot be used as array indices, I had to manually change many vars from Byte to Int
  • Kotlin does not allow assignments in expressions, so it’s impossible to do:
    while ((node.move = node.moveIterator.next()) != Move.NONE) { 

    I manually had to change some cases to the more verbose:

    while (true) {
        node.move = node.moveIterator.next()
        if (node.move == Move.NONE) {
           break
        }
  • The binary operators do not work in multi line if they are placed at the beginning of the second line, only if they are at the end of the first, so:
    var myLong : Long = long1
        or long2

    does not compile, it must be:

    var myLong : Long = long1 or
        long2
  • It didn’t recognize some custom getters and I had to merge them manually, I like a lot how they look in Kotlin (notice the use of the special word “field” to avoid calling the getter recursively):
    var lastMoveSee: Int = SEE_NOT_CALCULATED
        get() {
            if (field == SEE_NOT_CALCULATED) {
                field = board.see(move, ai)
            }
            return field
        }
  • The conversion process got hung with two complex classes: CompleteEvaluator and ExperimentalEvaluator… I had to kill IntelliJ. I converted the CompleteEvaluator class copying to a new class small chunks of code.
  • Kotlin’s when() statement do not work like the Java’s switch->case, as it hasn’t breaks, you cannot jump from one option to the next excluding the break: the conversion duplicated a lot of the MoveIterator code and I fixed it manually.
  • Some other strange errors like wrong expressions and missing parenthesis…

Some things of Kotlin that I don’t like (yet)

Some are part of the claimed Kotlin “features”:

  • Kotlin does not has primitive types, but it seems to not affect the performance…
  • There is no ternary operator in Kotlin, it’s replaced with “if (…) … else …” expressions: This increases a lot the verbosity, al least in my code
  • Kotlin’s crusade against NullPointerExcepcions: It a type allows null, it must be explicitly indicated appending a question mark to the type:
    var myString : String? = null

    To convert a nullable var/val to a non-nullable, you should use the !! operator, this forces a NullPointerException if the value is null (and it seems that you are shouting to the IDE…):

    var myString : String? = "hello"
    var myStringNotNull : String = myString!!
  • Static fields and methods are grouped in a “Companion Object”
  • Compilation is slower than pure Java
  • Many bugs running from Android Studio non-android projects (IntelliJ worked better for me)
  • Couldn’t get the JS compilation working yet

And other things that I like

  • The full interoperability with Java
  • Type inference, normally I continue to specify the types, but in some cases it saves a bit of code
  • Data classes, they will save you hundreds of lines of boilerplate code https://kotlinlang.org/docs/reference/data-classes.html
  • Array initialization with lambdas
    nodes = Array(MAX_DEPTH, {i->Node(this, i)})
  • The singleton pattern is embedded in the language: using “object” instead “class” assumes that the class is a singleton
  • Visibility is “public” by default, with the access modifier “internal” it can be accessed only from the same module
  • Implicit getters / setters
  • No need for “new” to call constructors
  • And much more…

Performance

I’m my first tests, I’m not noticing any performance downgrade (or upgrade) over the Carballo Java version. To find out more, why not try here.