Posts

Android Kotlin Digest #2

Back again with Kotlin I learnt. Kotlin runs on Java Virtual Machine (JVM). Syntax for declaring variables: Mutable:      var name: Type = value Immutable:  val name: Type = value Type Bit width Double 64 Float 32 Long 64 Int 32 Short 16 Byte 8 Kotlin 1.1 supports underscores ( _ ) in numeric values for readability: val mySalary = 1_000_000 val myCreditCardBill = 20_000 Difference between == and === : val a : Int = 10 val b : Int = 10 (a == b) // gives true  (a === b) // gives true  Note: Here primitive types are compared. When the primitive types are nullable it is turned into references and following is the result: val a : Int? = 10 val b : Int? = 10 (a == b) // gives true  (a === b) // gives false   Note: Here a and b becomes references and hence comparision with === results false. Type converters: 'c'.toInt() 80.toString() A raw string is delimited by a triple quote ( """ ), contains no escaping and can contain n

Android-Kotlin Digest #1

Planning to journal updates on my learning in Android and Kotlin development. This would be mostly from an ​ iOS developer's perspective . I will be writing gist of what I learnt today and anything specific interesting.  To start off below are some things I learnt in Kotlin and differences with Swift.  Some basics of Kotlin:   var  of mutable variables val  of immutable variables / constants Adding variable value in a string "The value of variable is $variable_name" Suffix ?  for variables holding null values  Also has a javascript big arrow =>  function like syntax:   fun sum(a: Int, b: Int) : Int = a + b Conditionals: `if (obj is String) { ... }` and not checks `if (obj !is String) { ... }`  I found switch  statements most unique till now: when (obj) {      1          -> "One" // (case)      "Hello"    -> "Greeting" // (case)      is Long    -> "Long" // (case)      !is String -> "N

Why I love programming?

Image
Extended title:  " Why I love coding/programming, software development, software engineering and everything in this field of work ? " I am a guy who easily gets bored of stuff within short span of time. In this context, I have a brain like that of a 2 years old kid who craves for something and when I get it I abandon it away within no time. But it's exactly the other way round when it comes to anything in computers. I first saw a computer at the age of 15 when my first cousin got one for a post graduate program. I, for that matter anyone of us kids, were not allowed to touch it initially. After a few months of pestering we were allowed to play games and MS Paint. Eventually, not by choice though, got a seat in computers and information science branch for my engineering course and my dad got me my first computer. I am including the spec just to know how much we have progressed since 15 years. - Pentium  III  processor cased inside a cab

Design Patterns & Principles - Strategy Pattern

This is a part of a blogpost series listing the design principles and pattern definitions. The Strategy Pattern - defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets algorithm vary independently from clients that use it. Following are few principles adhered in this pattern Identify the aspect of your application that vary and separate them from what stays same. Program to interface not to an implementation Favor composition over inheritance The example code for strategy pattern in Swift is available at my github repo . courtesy: Head First Design Patterns

Protocol oriented programming PoP

This post is a part of my blogpost series while learning Swift and Programming paradigms. First part on Functional Programming can be found here . Protocol oriented programming (POP)  can be said as as - a way to adhere the " Program to interface not to implement " principle  - which is one of the basic design principles of software development. Structure your code such that you define interfaces first then make the classes implement it. Define interfaces using protocols and then make classes implement them. POP is just another technical term for the interface programming in Swift programming language. Yes! There are additional advantages of POP in swift using "Extensions" along with protocols in Swift. Let us discuss this with a classic example - Shapes and its classes . Any shape has area. Every shape needs to be drawn on some canvas. Typically an average programmer thinks: Let's have a base class named Shape. Let's derive all other concrete cl

Functional programming concept and Swift

Image
For quite sometime now I am on a new programming language from Apple - Swift. Apart from the hype Swift got there are multiple programming paradigms that I got introduced to - Functional Programming ( FP ), Protocol oriented programming ( PoP ). I was little curious as I knew what functions are and what protocols are used for especially in objective-C, and my mind asked me few questions - What are Functional Programming and Protocol oriented programming? Is swift a Functional Programming language or a Protocol oriented programming language? Is it mandatory to learn in Functional Programming or Protocol oriented programming to code in Swift? What is the right way? Browsing through some websites and reading few books, this is what I understand. In this post I will be sharing my thoughts & understanding on FP and a subsequent post on PoP. Q: What is Functional Programming? Answer:  (In non-developer's term) Functional Programming is a way of how you code your so

Compiler directives in objective-C 2.0

Here are the list of directives in Objective-C 2.0. Let me know if anything is missing. // directives used in class declaration @interface @public @package @protected @private @property @end // directives used in class implementation @implementation @synthesize @dynamic @end // creating a string object @”string” // for forward declaration @class // similar to function pointers @selector() // used for method declaration mainly for delegation purpose @protocol @required @optional @end // to assure thread safety @synchronized // handling memory issues (useful in ARC enabled apps) @autoreleasepool // throwing and handling exceptions @throw @try @catch @finally // type encoding ( Apple docs ) @encode // aliasing an existing class name to a new one (useful in refactoring) @compatibility_alias Happy coding!