Learn Kotlin Android Development Programming - Programming Ebook

Latest

Download Programming Ebook

Thursday, August 22, 2019

Learn Kotlin Android Development Programming

Learn Kotlin Android Development Programming
Learn Kotlin Android Development Programming



Book Details 
             TitleLearn Kotlin Android Development Programming
         Author: Peter Späth
    Language: English
No. of pages: 517
         Format: PDF, EPUB


Introduction

Computer programs are for executing operations using input data to produce output data, sometimes by manipulating data taken from a database during that operation. The word database here is used in the most general sense: It could be a file, some memory storage, or a full-fledged database product.

Many different programming languages exist nowadays, each with its own merits and drawbacks. Some of them aim at execution stability, some at high performance, some are tailored to solve specific tasks, and some exist only because a company wants to establish a strong market position. Looking at the way programming languages have developed over time is an interesting subject in and of itself, and it has implications for various aspects of information technology. One could write a separate book about that, but for this book I simply want to stress one important fact about computer language development, which I think has a direct effect on the way modern computer programs are written. If you are looking at the historical development of computer languages, you will notice a substantial change in the abstraction level the languages exhibit. Whereas in the infancy of the industry a programmer needed to have a fairly good knowledge of computer hardware, now different levels of abstraction have been introduced into the languages, meaning
an increased conceptional and linguistic distance from hardware features. This
has increasingly alleviated the requirement that software developers know what is occurring in a computer’s central processing unit (CPU).


Bundle 5 books Android And Kotlin: http://www.prograbooks.com/2018/12/android-and-kotlin-bundle-books-from.html

Along with an increasing level of abstraction, modern computer languages— sometimes implicitly, sometimes explicitly—exhibit a prominent new feature: the expressiveness of language constructs. Let me try to illustrate this using an example written in pseudo-code. Let’s say you have a list of items and want to perform an operation on each of the items. With some knowledge of the internal functioning of computers, a programmer might write a code snippet like this:
  • Create some array of data in the memory.
  • Assign a pointer to the first element.
  • Loop over the array.
  • Dereference the pointer, retrieving a list element.
  • Do something with the element (example.g., print it).
  • Increment the pointer, let it point to the next item.
  • If we are beyond the last element, exit the loop.
End loop.
Although this looks a little bit complex, it closely relates to what computers are doing under the hood, and early languages looked more or less like this. As a first abstraction and a way to improve readability, we can try to get rid of the “pointer” element and instead write:
  • variable theList = [somehow create the list of items]
    • loop over "theList", assigning each item to an
                  iteration variable "item":
      
    • do something with "item", for example print it
  • end loop
    This already looks more expressive compared to the first version, and a lot of current programming languages allow for this kind of programming style. We can do even better, though: You can see the definition of the list being written in one line, separated from the list processing in the loop. There’s nothing preventing us from writing a lot of overly complex code between the list definition and the loop, and this is what you see quite often, making the program hard to read and understand. Wouldn’t it be better to have it all in one statement? Using a more expressive snippet allows us to write such a combined statement. In pseudo-code, it could look like this:
    [somehow create the list of items].
        [maybe add some filter].
        forEach { item ->
    
          do something with "item", for example print it
        }
    
    This is about the maximum of expressiveness you can get, if you see the dot “.” as some kind of “do something with it” command and “{ ... }” as a block of code doing something, with the identifier in front of the -> in this case designating a loop variable.
Note Making your code expressive from the very beginning will not only help you to write good code, it will also help you to develop your programming skills beyond average. expressive code is easier to maintain and extend, easier to reuse, easier to understand for others, and easier to debug if the program shows some deficiencies.

The programming language Kotlin is capable of getting us to such an extent of expressiveness, and in this book I want to introduce Kotlin as a programming language for Android that allows you to accomplish things in an expressive and concise way. As a matter of fact, in Kotlin the little looping example, with a filter added, reads:
arrayOf("Blue", "Green", "Yellow", "Gray").
    filter { it.startsWith("G") }.
    forEach { item ->
      println(item)
    }
If you run this, it will print the text Green Gray on two lines of the console. With the notion of parameters being placed inside round brackets, you should be able to understand this snippet without knowing a single Kotlin idiom.

Note don’t worry if you don’t know how to write and run this, we’ll be getting our feet wet very soon in the first chapter of the book.

Once you reach the end of the book, you should be an advanced developer able to address problems in the Kotlin language, with particular attention on Android matters. Of course, you will not know all possible libraries that are out there in the wild for solving specific problems, as only experience will help you there. Knowing most of the language constructs and having good ideas concerning programming techniques, however, will set you on the way to become an expert programmer for Android.
The Kotlin version referred to in this book is 1.3. Most of the examples and most of what gets explained here is likely valid for later versions as well. 

No comments:

Post a Comment