Category: GSoC (15 posts)

Jun 26 2019

Reasons to choose Kotlin

Hello there! My name is Divyansh Jain. I am a student of Mahatma Jyoti Rao Phoole University. I have been selected as the Android developer for the XWiki organization and I am working on their XWiki Android Authenticator application in GSOC19.

XWiki android Authenticator aims to integrate a wiki instance in Android accounts, mainly including the synchronization of contacts and the XWiki authenticator. By synchronizing contacts of your company on your phone, it becomes easier to communicate and collaborate with each other.

Ever since the start of my work on the XWiki Android Authenticator app, I have been constantly learning new things. In the first week, I migrated most of the XWiki Android Application code from Java to Kotlin. And on this page, I would like to share my understanding of Kotlin that I have gained so far.
 

Getting started with Kotlin

Kotlin is officially supported by Google for mobile development on Android. It was released in Android Studio 3.0 on October 2017. At first, I was a bit afraid to switch to Kotlin since I feared that the code might crash and not run properly, but as I read the documentation, I started understanding the nuances of the language which made the switch from Java to Kotlin an easier process. I started realizing the advantages of Kotlin over Java. Some of them being:

Java Interoperability

I started with migrating the whole XWiki Android Authenticator app code from Java to Kotlin. I was replacing one Java file at a time, and while migrating I saw that Kotlin worked with Java smoothly. Though it required some direct imports, there were no errors in running the app on the device.

Changed variable declaration

In Java, we declare string for instance, String str = "Hello";.

In Kotlin, we declare string for instance, val str = "Hello" or val str: String = "Hello". Here val declares a read-only property or local variable whereas var declares a mutable property or local variable.

The final keyword is default in class

In Kotlin final is a default. E.g.

            
class Button {
   fun click() = print("Click")
}

class displayToast : Button() {  // Error
   override fun click() = print("Toast Displayed") // Error
}

In the above example, class displayToast can’t inherit Button class because it is final. Moreover, it can’t override click(), because it is final in Button.

open class Button {
   open fun click() = print("Click")
   fun doubleClick() = print("Double Click")
}

class displayToast () : Button {           // Inheritance is now possible
   override fun click() = print("Toast Displayed") // Now it works
   override fun displayToast () = print("Toast Displayed") // Error
}

In order to inherit and override, we put “open” keyword that allows inheritance and overriding.

Fun keyword for defining functions

Now in Kotlin, there is a new way to define functions. E.g.

fun displayToast() { } //with no arguments inside functions

fun addDigitis (a: int, b: int) : String { }  //with arguments inside function

It is same as the Java parameterized method or empty method.

The when expression

The "switch-case" is replaced with the much more readable and flexible "when" expression: E.g.

int x = 3
when (x) {
   1 -> print("x is 1")
   2 -> print("x is 2")
   3, 4 -> print("x is 3 or 4")
   in 5..10 -> print("x is 5, 6, 7, 8, 9, or 10")
   else -> print("x is out of range")
}

It works without the argument too.

Static keywords

For declaring static methods & variables, you can put them above the class name, then you can use them by importing directly in other classes.

Null Safety

One of the biggest flaws in Java is the way it handles “null,” leading to the dreaded NulPointerException (NPE). Kotlin resolves this by distinguishing between non-null types and nullable types. Types are non-null by default, and can be made nullable by adding a safe call ‘?’. E.g.

var a: String = "abc"
a = null                // compile error

var b: String? = "xyz"
b = null                // no problem

Conclusion

So after seeing, reading and migrating the code from Java to Kotlin, in my honest opinion, I do not see any reason to not choose Kotlin over Java. For instance, we need to write less code as compared to Java, we don't have to face the dreaded ‘NPE’ error anymore, interoperability with existing Java files, smart casts while declaring variables and many more. We've given the fair amount of our time to Java, but it's time to let it go and welcome our new friend Kotlin.

Happy Reading.

Aug 23 2018

Google Summer of Code 2018 Wrap-Up

This is the eleventh year XWiki has participated in the Google Summer of Code program. XWiki had 12 mentors involved at various levels and 3 successful projects implemented. ...

Aug 13 2018

My GSOC adventure with XWiki and Dokuwiki

The project focused on improving the existing DokuWiki importer that imports instances of DokuWiki to XWiki by using some intermediate common events based on Filter Stream Framework. In the previous Dokuwiki importer module already supported basic functionalities. Improvements like support for handling unserializing of files with no metadata, lists, image-link, interwiki-link, macro support and other syntax-parser bug resolution. ...

Aug 08 2018

My GSoC 2018

Aleksei Ovsiannikov summary of experience in participating in GSoC 2018 and open source projects contributing.  ...

Jan 30 2018

Google Code-in 2017 Statistics

Here are some statistics from the Google Code-in 2017 edition: 12 mentors, 380 successful students, 489 successful tasks, 154 merged PRs, 11 issues fixed, 23 contributors, 181 translations improved, 9 repos improved, etc. ...

Jan 22 2018

Google Code-in 2017 Wrap-Up

After being mentors for Google Summer of Code (GSoC) program for more than 10 years, we decided also to mentor pre-university students in the Google Code-in program. We had 489 successfully completed tasks thanks to 380 students and 12 mentors involved in the program. This was the first year we participated as an organization. ...

Dec 27 2017

What happened in 2017?

As the last blog post of the year, this article summarize the main events that happened during the past twelve months inside of the XWiki project. ...

Mar 01 2016

XWiki is participating in Google Summer of Code 2016

XWiki has been accepted as a mentoring organization for Google Summer of Code 2016. Since its inception in 2005, the program has brought together over 10,900 successful student participants from over 103 countries worldwide and over 500 open source organizations, all for the love of code. This is our 9th time participating in the program and we are pretty excited about it. We value the participation in the program since it allows us to meet and discuss ideas with smart students from around the world. ...

Apr 08 2013

XWiki is participating in Google Summer of Code 2013

XWiki has been accepted as a mentoring organization for Google Summer of Code 2013.

Google Summer of Code is a global program that offers student developers stipends to write code for various open source software projects. We work with many open source, free software, and technology-related groups to identify and fund projects over a three month period. Since its inception in 2005, the program has brought together nearly 6,000 successful student participants and over 3000 mentors from over 100 countries worldwide, all for the love of code. 

This is our 8th year participating in the program and we are pretty excited about it. We value the participation in the program since it allows us to meet and discuss ideas with smart students from around the world. The past years brought great results, such as the WebDAV and RESTful remote access APIs, the Office importer, and the whole XEclipse project, just to name a few.

This year we're proposing a lot of interesting projects, from Live Notifications to XCLAMS Federated Servers, beside our regular mentors also having the support of mentors from the XCLAMS community.

The student application period will last from April 22 until May 3, 19:00 UTC. Students interested in applying for a project with XWiki should:

Let's work together with the community to make this a great Summer of Code!

gsoc2013.jpg

Mar 29 2011

XWiki is participating in Google Summer of Code 2011

This summer, Google organizes the seventh edition of the Google Summer of Code program:

 Google Summer of Code is a global program that offers students stipends to write code for open source projects. We have worked with the open source community to identify and fund exciting projects for the upcoming summer.

A participant in GSoC since the first edition in 2005, XWiki was left out of the program last year to make way for newer and smaller open source projects, but is back as a mentoring organization this year, and we're ready to give a few lucky students a chance to learn how real world, open source development works in the middle of our wonderful community.

With five years of experience as a GSoC organization, our developers are seasoned mentors, ready to guide students through the entire process. Some students are already mixing in with the developers on our IRC channel, or introducing themselves and their project proposals on the mailing lists. We're very happy to meet and discuss ideas with these interesting students, and we can't wait to see what these collaborations can lead to, since every year we've had great results, such as the WebDAV and RESTful remote access APIs, the Office importer, and the whole XEclipse project, just to name a few.

This year we're proposing a lot of interesting projects, from hard core java to clientside javascript projects, and from mobile devices to the cloud. Of course, the poster child of our GSoC experiences, XEclipse, is ready to receive further improvements, and application development on top of XWiki is also present in this year's proposals.

The student application period just started and lasts until April 8th, 19:00 UTC. Students interested in applying for a project with XWiki should:

Let's work together to make this a great Summer of Code!

Tags:
Created by Sergiu Dumitriu on 2011/03/29
    

Get Connected