Lessons that I learned from good programmers around me.

If you new here, I’m @Buntylm, Singapore-based programmer 👨🏻‍💻. Currently working on Swift developing apps for iOS devices and Web APIs using Java and Golang.

👨‍💻 Below are the lessons that I learnt from good programmer around me.

  • Importance of software design patterns.
    • Inspiration
      • Design patterns don’t provide solutions, they inspire solutions.
      • Patterns explicitly capture expert knowledge and design trade-offs and make this expertise widely available.
    • Improve developer communication, easy to describe a very specific structure of code
    • Help document the architecture of a system.
  • Essentially code that is considered good.
    • Does what it should.
    • Follow a consistent style
    • Easy to understand and test.
  • Code quality measurement
    • Reliability, system will run without failure over a specific period of operation.
    • Testability, relies on how well you can control, observe, isolate, and automate testing
    • Reusability, measures whether existing assets, piece of code can be used again.
  • Programming languages – don’t be language specific. Always learn new language since the technology is changing drastically.
  • Basic of data structure and algorithms is necessary.
  • Become an expert at debugging. Don’t use a debugger when it comes to finding a bug; make use of your mental model and take help from the system logs.
  • Speak up ask questions
  • No – say goodbye to being a people pleaser and learn how to confidently say no to someone without feeling bad about it.
  • Expertise in Git (provides cheap local branching, convenient staging areas, and multiple workflows). Always use source control.
  • Make a working release/build in one step.
  • See things around you, work that you are doing on daily basis and ask you, can I automate it ? Pick the right tool. It can save you a lot of time in the long run.
  • Always maintain a bug database.
  • Learn and try new things. 
    “The day you stop learning is the day you begin decaying.”
  • Minimise your distraction when you are at your desk, try out some tools like Be Focused, make use of some app/website blocker if you cannot control, and turn-off the notifications. Read some interesting books like this Getting Things Done.
  • Process
    • Agile (approach discovering requirements and developing solutions through the collaborative effort of self organising and cross functional teams and their customers. wiki
      Simple definition to describe Agile: A time boxed, iterative approach to software delivery that builds software incrementally from the start of the project, instead of trying to deliver it all at once near the end (every sprint you will some working software/product).
  • xDD which TDD/BDD. Always write test-cases. Think, solve the problem, write test-cases and write code. Later refactor to improve it further.
    • Write a failing test.
    • Make it pass.
    • Refactor to improve your code.
    • Repeat.
    • Techniques
  • Feynman Learning Technique:
    • Choose a concept you want to learn about.
    • Pretend you are teaching it to a student in grade 6.
    • Identify gaps in your explanation, and go back to the source material to better understand it.
    • Review and simplify.

Thanks for reading it.
Do share if you like it, let me know if you have any comments. :✌️

Don’t be foolish | Mind Manipulation

Manipulating others is a best way to get what you want from others, but do you know people around you tricking some techniques to make you fool, and getting what they want from you.

First let’s talk about what is the mind manipulation, when it comes to decision making we have 2 systems in our brain. System 1 operates automatically and quickly, with little or no effort. System 2 allocates attention to the effortful mental model. People are using few hacks to not to allow us to use System 2 where we don’t think much and do what they want us to do.

Image credit : Google.com

The Halo Effect, A type of cognitive bias in which our overall impression of a person influences how we feel about their character. It’s also called “physical attractiveness stereotype” or “what is beautiful is also the best” principle. 

When we like someone we just ignore their bad quality and always appreciate them. If they make some mistake we always say, ah that fine, we all are human we make mistakes. we always follow their advice, without giving a single thought. At the workplace, bosses may rate the employees on the perception of a single characteristic rather than the whole of their performance and contribution.

You will notice this trick is used by politicians, celebrities where they have huge PR team to refine their image, so that you will feel attraction towards them.

Priming, Let’s start with an example first, If i expose a word to you “YELLOW” it will evoke a faster response to the word “BANANA” if you like fruits or “SCOOT” if you air travel a lot. If I write APPLE and ask you to fill in the gap GR_ _ _. most of the us will say GRAPE.

Picture Credit : Google.com

This is the technique used for marketing to sell the product. You can hit Google and see there are thousands of studies on Priming, one of them which i like a lot is Music and Wine testing (Significant associations between the musical stimulus genre and participant change in wine selection).

The Hindsight Bias, Focus on the cartoon for 10 seconds and see you do you think about it.

Picture Credit : Google.com

Tendency to look back at an unpredictable event and think it was easily predictable, I knew it is going to happen, i knew Trump is going to win the US elections. Nope you knows nothing, we all have people around us like this. You are trying to be an expert of something that has happened already, it can case distortions of our memories of what we knew or believed before an event occurred, also don’t trust people like this.

Thanks for reading it.

The Social Dilemma (2020) on Netflix.

Picture credit: Google

The Social Dilemma, one of the most splendid documentary I have seen in a while, shows the rise of social media and the damage it has caused to society.

Reasons why you should watch this documentary to understand.

  • If the you are not paying for the product, then you are the product.
Picture credit: Google

The Goal is to increase the user’s screen time, each of your activity online is being tracked, every like you hit, every comment you post, every video you watched, how long you watched, what leads you to this action, each and every small action you took consciously or unconsciously. Once companies have this information then artificial intelligence comes into the picture.

Artificial intelligence (AI) refers to the simulation of human intelligence in machines that are programmed to think like humans and mimic their actions.

Since companies have all the information on how you behave, what actions you take on certain conditions, they have built AI for each and everyone which gives the content feed what as a user you will like, creates a personalised experience for everyone. Now the even more dangerous thing comes in the picture called Machine learning (that provides systems the ability to automatically learn and improve from the experience without being explicit programmed) which learn from action and improves the judgement accordingly to increase the accuracy.

Picture credit: Google
  • There are only two industries that call their customers ‘users’, illegal drugs and software.
    • Engagement: This is the important aspect, to keep user more engaged by sending them the notification, showing the information that user want to see. The time you spent on one video is also tracked to analyze your interest on the feed.
    • Growth: Friends suggestion, allowing friends to tag in, one more the very common way “Say Hi” to your friend who recently joined messenger.
    • Revenue: Ok, Just login to gmail and go to Google search, search a product and you will see the same product ads will start appearing everywhere for you, if you don’t take action later you will see the same product with some discount.
  • Age of disinformation/false news can lead us to the civil war.
Picture credit: Google

Due to large number of user no application can distinguish between the truth and the fake news. [Study: On Twitter, false news travels faster than true stories] MIT study found that falsehood diffuses significantly farther, faster, deeper, and more broadly than the truth, in all categories of information, and in many cases by an order of magnitude.

Thanks for reading it.

How to perform throttling in Swift, Debounce.

What is Throttling all about, it’s a process responsible for regulating the rate at which application processing is conducted (doesn’t matter statically or dynamically). Wikipedia

A very common use in iOS, when you have a search bar which takes input from user and sends off a request for search results every time. For a long query it may cause lot of requests to be sent on server to process (performance will be different for slow vs fast typing user & also depends on internet connection).

Another use case that I faced today is to log an impression when user sees the TableViewCell. I found and interesting example on Github. I created an extension for this to make use of it everywhere.

Create a protocol.

protocol Throttable {
    func perform(with delay: TimeInterval,
                 in queue: DispatchQueue,
                 block completion: @escaping () -> Void) -> () -> Void

Provide the default implementation using the extension.

extension Throttable {
    func perform(with delay: TimeInterval,
                 in queue: DispatchQueue = DispatchQueue.main,
                 block completion: @escaping () -> Void) -> () -> Void {
        var workItem: DispatchWorkItem?
        return {
            workItem = DispatchWorkItem(block: completion)
            queue.asyncAfter(deadline: .now() + delay, execute: workItem!)

Responsibility of this function is just to return a function, when you call the returned function.

  • It cancels the exiting workItem if exists (magical Optional).
  • Creates a new DispatchWorkItem with the completion block.
  • And the queue calls the workItem with given delay.

And that’s how it works, Just conforms the Throttable protocol wherever you want.

class UserInputHandler: Throttable {
    let triggerAPI = perform(with: 1.0) {
        print("Fetch Search Result")
    func didReceiveInput() {

Here is an easy example to integration it with UIViewController

class SearchViewController: UIViewController, Throttable {
    @IBOutlet weak var searchTextField: UITextField!
    lazy var triggerAPI = perform(with: 1.0) { [weak self] in
        guard let searchText = self?.searchTextField.text, !searchText.isEmpty else {
        print("API Request to fetch result for \(searchText)")

extension SearchViewController: UITextFieldDelegate {
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        return true

Thanks for reading
Find more Swift Tips and Tricks on Github.

How to check API availability in Swift, iOS / macOS / watchOS / tvOS SDK

What is Availability checking?

Today Apple leads the world of innovation with iOS, MacOS, watchOS and tvOS, and every year we see new operating system release with more enhances, and new technologies.

So all the features Apple releases is coupled with the OS releases (for example Sign-in with Apple is available on iOS 13 and above only). As a developer is highly recommend for us to delivery one binary which support latest as well as old operating system.

So this availability check is Swift gives us the power to check weather the user running a specific version or not.

Swift API to check the OS version?

class LoginViewController: UIViewController {

    override func viewDidLoad() {

    private func initLoginView() {
        //initialise login view
        guard #available(iOS 13.0, *) else {
        let authButton = ASAuthorizationAppleIDButton()
        // integrate Sign in with Apple

Code snippet shows that we are initializing a LoginView for user to login, and making use of #available API call to check the version, if it’s iOS 13.0 and above we do add “Sign in with Apple” which is only available in iOS 13.0 and above.

Swift also provides us an declaration attribute (there are two kind of attributes in Swift, one that apply to declarations and another to types) to declare that this call or function is available on which iOS version.

@available(iOS 13, *)
func initSignInWithApple() {
// use AuthorizationService framework to integrate Sign in with Apple.

These are the arguments we can make use in @available attribute.

  • iOS 
  • iOSApplicationExtension
  • macOS
  • macOSApplicationExtension
  • watchOS
  • watchOSExtension
  • tvOS
  • tvOSApplicationExtension
  • swift

An asterisk (*) to indicate all platforms.

Few interesting use that we can make use.

@available(*, unavailable) – Indicates that the declaration is not available on given platform.

@available(*, introduced) – Indicates the first version when the declaration was introduced.

@available(*, obsoleted) – Indicates the first version platform/language in which the declaration was obsoleted.  

@available(*, message) – A message that the complier displays during the warning or error.

@available(*, renamed) – A message that the complier displays during the warning or error about the renaming.

Interesting example that I really like from Swift documentation.

// A protocol defined in first release.
protocol ConfigProtocol {


Would like to change the name in next release?

// change the name.
protocol AppConfigProtocol {


@available(*, unavailable, renamed: "AppConfigProtocol") 
typealias ConfigProtocol = AppConfigProtocol 

In this case, complier will start giving you a error, also a fix for you.

‘ConfigProtocol’ has been renamed to ‘AppConfigProtocol’

Replace ‘ConfigProtocol’ with ‘AppConfigProtocol’

Thanks for reading.

Swift Property Wrapper | Quick Note

This weekend, I gave 👨🏽‍💻 on Property Wrapper to see where I can make use of it, so here are the quick note.

Image credit : https://www.instagram.com/buntylm

Background, Swift properties do contains some extra code (‘get’ and ‘set’) when we want to observe the changes. For example, if we want to add some log to see the new value every time a property changes. The straightforward way of implementing this is

struct Student {
    private var name_: String
    public var name: String {
        get {
            return name_
        } set {
            name_ = newValue
            print("Setting new value \(newValue)")

Wait, If we follow this approach for logging more properties, our codebase will become a mess soon, so handle this let’s create a type which will help us to log.

struct Loggable<T> {
    private var value: T

    public init(wrappedValue: T) {
        self.value = wrappedValue

    public var wrappedValue : T {
        get {
        } set {
            value = newValue
            print("Setting new value \(newValue)")

Let’s update our implementation.

struct Student {
    private var name_ = Loggable<String>(wrappedValue: "NA")
    public var name: String {
        get {
            return name_.wrappedValue
        } set {
            name_.wrappedValue = newValue

Great, looks better and That is the problem, Property Wrapper (require Swift 5.1) is solving. All you need to do is add ‘@propertyWrapper’ to ‘Loggable’, and below the how Loggable and Student class will look like

struct Loggable<T> {
    private var value: T

    public init(wrappedValue: T) {
        self.value = wrappedValue

    public var wrappedValue : T {
        get {
        } set {
            value = newValue
            print("Setting new value \(newValue)")

struct Student {
    @Loggable var name: String = "NA"

Another way of giving the default value 😬

struct Student {
    @Loggable(wrappedValue: "NA") var name

Property Wrapper decorates a property with a custom behaviour (similar like we use annotation in Java/Kotlin).  To note, Property Wrapper

  • always need to defined with ‘@properWrapper’ and must have ‘wrappedValue’ property.
  • cannot be set as ‘lazy’, ‘weak’, ‘unowned’ or ‘@NSManaged’.
  • cannot be declared in protocol or extension.
  • cannot be overridden.
  • cannot have custom ‘get’ or ‘set’.

That’s it, Thanks for reading.
Do give a try and let me know which is the use-case you want to use it. 😃


Building A Second Brain | Note


Over the weekend I was watching Ali on his YouTube channel where he talked about Building A Second Brain, a world-class idea management system. So here is my short note on it.

What’s that?

A methodology for saving and reminding ideas, inspirations, notes, and connections that we have gained through our experience. Idea is to offload our thinking and free our biological brain to imagine, need not keep track every detail just move on confidently.

What will be the benefits?

  1. Work in a result-oriented way.
  2. Connect the dots between ideas.
  3. No information overload, no stress at all.
  4. Cultivate a collection of knowledge.

How to do it?

Part 1: Remember

Whenever we capture something we email ourselves a quick note, a word document or write a sticky note but then we don’t do anything.

So rule number one is to keep it in a single, centralized place such a digital note-taking app & capture the information by following three guidelines.

  1. Think like a curator.
  2. Organize your content by the project.
  3. Keep only what resonates.

Part 2: Connect

Once you start collecting the information, you’ll start noticing the connections. Summarise and distill your notes into actionable by following three guidelines.

  1. Design notes for your future self
  2. Summarise progressively with levels of detail
  3. Organize opportunistically

Part 3: Create

All of this capturing, summarising has one ultimate purpose, Create tangible results in the real world, With this, you always have something to inspire you, support you, guide you and remind you again and again whenever you need it.

Three guidelines will help you to create a better and meaningful.

  1. Don’t just consume information passively – Put it in use.
  2. Start small and make it reusable.
  3. Share your work with the world.


Each note in your second brain is a record of something that you’ve earned in your life, when you start offloading your biological brain you feel easy and you enjoy each and every moment of your life. Your mind will start to work differently it just takes the action.

Building A Second Brain is an integrated set of behavior for turning incoming information into projects (where you put everything is on place, plan accordingly and make use of it fully whenever needed).

Thanks for reading this. ✌️

All you need to know Accessibility | iOS SDK | Swift

Why does Accessibility matter?

First thing first, it always feels good to know that even if your work is small but it’s making a huge difference in someone’s life. 🙂 There are millions of smartphone users all around the world with some sort of disability. Enabling accessibility into the software system ease them in interacting with it.

And on the other hand, if you’re working for any government agency you have to implement it because of 508 compliance (which says that any technology or software product must be accessible to all users).

Accessibility domains?

– Vision: a vision challenge that makes focusing difficult, color blindness or total blind.
– Hearing: difficulty hearing sound, partial hearing loss or maybe deaf.
– Physical and motor skills: difficulty when it comes to tapping the interface or holding a device.
– Learning and Literacy: hard to understand a complex user interface or hard to remember a sequence of step to do a certain task.

Image from Apple.

What is VoiceOver?

A screen reading tool that helps the user to interact with the application without seeing the screen. The feature is designed for those who have vision problems. Navigate to Settings/Accessibility/VoiceOver.

VoiceOver: Gestures?

Enable the VoiceOver to try this out.
– Single tap: Tap anywhere, VoiceOver will start speaking information as per the accessibility attributes (find more later).
– Swipe right or left: Try swipe right/left VoiceOver will navigate you through all items on the screen while reading them aloud. Right for forward/down and Left for reverse/up.
-Double Tap: is to tap on a selected item.
– Single swipe down: is to spell out the focused item.
– Three finger swipe: For page views to navigate forwards or backward

Accessibility attributes?

Core attributes that VoiceOver will use to provide information to the user.
– Label: way to identify the view (like settings button, profile image) VoiceOver will speak the same when the item will be selected.
– Traits: way to identify the element state, usage or behaviour (like a button is selected.) 
– Hint: way to describe the action of an element (like Go to detail).
– Frame: frame of the element within the screen.
– Value: The value of element like a slider bar.
– AccessibilityLanguage: The language code that the element label value, hint should be spoken. 

How to debug accessibility attributes?

Accessibility inspector is a tool given by Apple to debug your app (Navigate to Xcode/Open Developer Tool/Accessibility Inspector). Where developer can choose the target, enable the pointer to debug the view.

Accessibility Notification?

Animation or layout changes are a visual feedback to the user as a response of the action taken, Use announcements notification to provide an update (other options are layoutChanged, screenChanged delegates).

Target Touch Size?

As per Apple human interface guidelines it is recommended to maintain a tappable area of 44x44pt (minimum) for all controls in the application.

What is Dynamic Type?

Functionality that allows the users to dynamically adjust the size of text, images (choose their preferred text size). iOS app will adopt the text/image size as per user preference. (Apple Developer documentation)

Setup Smart Invert Colors?

Need to set `accessibilityIgnoresInvertColors` property to enable or prevent a control from inverting it’s colours. (Navigate to Setting/General/Accessibility/Display Accommodations/Invert Colors).

Thanks for reading this.

Quick Tips To Support Dark Mode In Your iOS App | iOS 13

All you need to know about Dark Mode on iOS 13

Overview? With iOS 13 and above people can adopt a dark appearance where Apple docs says user can use settings to make their devices automatically switch to dark mode when ambient is low and this will help you to put focus on your content.

Development Environment? As as iOS developer you’ve to use Xcode 11 with iOS 13 SDK and above, iOS will automatically update system controls such as switches, collection-views etc. If you are migrating your existing app to dark in that case you will have to adapt the colours. 

How to define colours for each mode?

System Colours? iOS 13 SDK includes new system colours so if you adapt these system colours your app will automatically support dark and light mode, You can use it via Storyboard as well as programmatically (Some example below)

Custom Colors? Yes it’s strongly recommended by Apple that use system colours to provide better UX and also to make sure the consistency across apps but using the asset you can define you colour choices. Once you define iOS will take care everything for you.

How to define Image for each mode?

Using the Assets you can specify which image you want to use for dark VS any other mode and just define the image and let iOS take care for you. 

How to detect dark mode programmatically?

On Load Detection? We can use overrideUserInterfaceStyle to check which mode is currently running on user device (Just make sure, this property only available on iOS 13 and above)

Runtime Detection? Can use traitCollectionDidChange to observe the changes, It is important to remember that trait-collection may be called for other trait changes (such as device rotation)

Set Dark Mode for Specific Screen? Yes you can, this property overrideUserInterfaceStyle is available for you to use (only iOS 13 and above)

How to support WKWebView?
Just need to create variable for the color and need to handle this in CSS.

:root {
    color-scheme: light dark;
        --h1-color: #333;
        --header-bg-clr: #FFF1FF;
        --header-txt-clr: white;
    @media (prefers-color-scheme: dark) {
    :root {
        color-scheme: light dark;
        --h1-color: #333;
        --header-bg-clr: #FFF1FF;
        --header-txt-clr: white;

body { }
h1 { color: var(--h1-color); }
.header {
    background-color: var (--header-bg-clr);
    color: var(--header-txt-clr);

After Integrating this change you can use Safari to test (First you need to enable the developer menu option in Sarafi, Preferences, Advanced). Open wen inspector (using Command + Options + I) and you will see this screen with the option to toggle light/dark mode.

Swift 5 ABI Stability why matters?

Swift is fast, safe and expressive language to code with great full stack potential and community support. According to Apple, it’s 2.6 times faster than Objective C (As a Swift Developer I agree on this too 🙌). It’s 6th most loved language on StackOverflow.

ABI Background
As a developer, I hope sometimes you also felt that Swift is not mature enough as every year major changes are being introduced. One of the key problems articulated by a lot of developers is “Lack of backward compatibility” and you have to choose one Swift version for your Xcode projects (Version lock). Resulting in with a new Swift release you have to make changes in your existing code.

What is ABI?
ABI stands for Application Binary Interface. During runtime, Swift program interacts with other libraries through ABI (low-level set of protocols for memory representation, function calls, and access).
So when I say ABI not stable it means that each binary is building its own version of Swift Dynamic Library inside it. Now the Swift 5 is ABI Stable which means if I build two apps, one using Swift 5.0 and another using Swift 5.2, both will use Swift ABI embedded in the iOS Operating System.

Why ABI Stability matters a lot?

  1. Compatibility: which means new compilers can compile your old Swift code which means no more migration pain.
  2. Bundle Size: It will reduce the build size because of no Swift standard Library in your Framework folder.
  3. Binary framework and runtime compatibility which enables the framework distribution as a binary which will work across multiple Swift versions.

Conclusion: Swift is the future for Apple ecosystem and now it’s ABI stable which means, in other words, it is like write once and use everywhere.