Efficient programmer's notes
80 subscribers
4 photos
30 links
https://boosty.to/andreykas/donate - link to support me

This channel was created to share my experience in making countless attempts to be a more efficient and healthy person and programmer
Download Telegram
Choosing the perfect language/techology to work with

Before Flutter, I didn't know what I wanted to do as a programmer. I've tried different languages and technologies in university and by myself, and nothing made me happy.

I've taken a half-year online course on PHP/Laravel for beginners at school. Created a simple website for a cafe and forgot about this technology. Moved to Russia, where everyone around was saying that it is not mainstream anymore. "Look how cool are Python and Node.js," they said.

I've started learning Python/Django during my second year at uni. Learned a lot (at least I thought so) while working on small projects as a full-stack for other students. Several times in 1,5 years period tried to land a job as a python backend developer - failed. Funny that I've actually couldn't answer questions like "What is a hashtable lookup time complexity? What is a context manager in python?". Yeah, my knowledge of theory sucked. So I've decided to read Mark Lutts' thick book on python and try again - failed.

One day, I was looking through vacancies on HeadHunter and realized that there are so much more Java backend developer vacancies for interns and juniors in Saint-Petersburg. More vacancies - more chances to get a job. So I've started to think about switching to Java. And I've almost done that. I've tried and wasn't excited about it at all. I wanted something cooler and trendier, like Node.js.

Hopefully, at that very time, I've stumbled across Flutter. I've tried it out, liked it, and decided to do as much as I can to get my first software engineering job in a company - success.

What is the moral of the story?

This post's initial title was "The sooner you decide on what you want to specialize in, the better." But in the process of writing, I've realized that this is just half of the truth. Another half in that you should try to know what you like the most. And even if you choose to switch technology, you still have some knowledge and experience, that may be applicable in the future.

At the end comes this moment, where you have to commit to hard work for several months/years. Focus on consistency. Have a road map with clearly defined milestones. And you will succeed. Cause after all, programming is not so hard.

#career #thoughts
Procrastinate like a PROgrammer

How do people usually define pi variable (without math library) in their code:

Dart: var pi = 3.1415926535;
Python: pi = 3.1415926535

Stop it. This is just boooooring. Learn Rockstar language created by Dylan Beattie to become 'CERTIFIED ROCKSTAR DEVELOPER' and your code will look like a hard rock song from the 1980s.

Rockstar: My heart was ice. A life unfulfilled, wakin' everybody up, taking booze and pills

With its syntax, even the worst code can look like a piece of art.

There are people all over the world who like coding for fun creating many interesting things. Have you heard of naked html or generative art, or maybe a program written in C that looks like a donut that produces a 3D rotating donut in terminal?

Watch this video from a conference with a charismatic guy, I've mentioned above and have fun 🔥🔥🔥

#fun
Mental programming by Kirill Mokevnin (2021). Easy to follow rules to write good code.

1. There is a difference between understanding the code and understanding the problem it solves. Good code should have both.

2. If you are unsure if a variable or method name fits your needs, send it to a chat and ask people what they expect from it.

3. Strings. There are no checks for strings. Therefore, if there is code like if (order.status == 'delivering') {...}, and you decide to rename a status label, you should manually find all the places, where you've written such checks and fix them.

What is a solution? Keep such checks in one place.

There are two possible ways to do it:
1) Method: order.isDelivering()
2) Enum: order.status == OrderStatus.delivering

4. Don't save on variables. Oneliners aren't cool if they prevent you from understanding the logic.

A popular example from C language: while (*dest++ = *src++);

5. One vs Many in variable naming.

If I see a variable named attributes, then I expect it to store some collection, not an individual object.

6. Semantics. Make your code meaningful.

Example: if (!items.children) {...}
Do you have any clue of what did we just checked? Me neither.

7. Null object pattern

In some cases instead of writing checks like
if (user != null && user.isAdmin()) {
user.doSomething();
}*,
you can use Null Object Pattern.

"We should use the Null Object Pattern when a Client would otherwise check for null just to skip execution or perform a default action. In such cases, we may encapsulate the neutral logic within a null object and return that to the client instead of the null value. This way client's code no longer needs to be aware if a given instance is null or not."

For the example above it could be
final user = cond ? AdminUser() : Guest(),
where Guest is a null object.

8. Command-Query separation

"It states that every method should either be a command that performs an action, or a query that returns data to the caller, but not both. In other words, asking a question should not change the answer."

Example: user.isValid() - predicate that returns boolean. We don't expect it to change anything. If it somehow modifies our state under the hood, it'll be almost impossible to find the bug when we face some weird behavior.

*This example doesn't apply to languages with null safety like Dart and Kotlin

#dev
HAPPY NEW YEAR!!!
Size matters

I've recently read about interesting studies from Microsoft. According to them, if you are looking for a technological solution to boost your productivity, almost the only effective way is to buy a large monitor or even two of them.

I found it intriguing because I'm still working on my 13-inch laptop and have recently started to think it's not enough anymore.

Another study from the University of Utah has shown that people using 24-inch monitors complete a series of tasks faster than people with 18-inch monitors by around 52% working with text documents and 26% with spreadsheets. They've also found that taking something more than 24-inch doesn't actually improve users' performance anymore.

Of course, users from experimental group may not have known hotkeys for switching between windows or their tasks can't be compared to programming. So, one may say it doesn't work this way.

But I see some obvious reasons for such results and how bigger monitor can increase my productivity as a programmer.

A bigger screen:

1. Decreases switches between windows.

I usually have 3-4 windows opened at once while working: code editor, phone simulator or browser, UI design, and StackOverflow. For now, I have 3 macOS desktops with needed apps in full-screen mode. Switching from one to another takes time and mental energy.

2. Allows seeing more information at once.

"When people have to remember more, they tend to focus on fewer possibilities and fewer possible solutions. In other words, when people can only see a limited amount of their data, they have to remember the rest, which tends to limit them to fewer solutions and fewer strategies." You can focus on solving the problem instead of remembering some parts of your program.

3. Takes more space in my vision field, which results in better concentration, because I become less distracted. (Personal point)

I've also read from some authoriative sources, that 24-inch is not the limit. The perfect size and configuration depends on type of tasks you have to complete and your working style. So, choose your own path to happiness.

What's your current setup? Are you happy with it?

#efficiency
A small (27-inch) upgrade for my working desk. Excited to try it out. Actually, already watched "21 Jump Street"🙃
🔥1
Caching strategies

Why do we need caching? It's simple. People don't like loaders*. Moreover, people don't like waiting. So, caching some data to instantly show it next time a user asks for it without requesting the server increases app's UX. Which increases user retention. Which increases app's profit.

I have once stumbled upon a problem related to caching and cache invalidation in a mobile app. My main problem was that I'd never done it before and tried to reinvent the wheel. Luckily, my caching strategy was not so tricky. The cache had an expiration date, so I could invalidate it after a day/week/month, and the app could force an update from the server if needed by the "pull to refresh" thing.

After a while, I've found a talk from a mobile conference about different caching strategies. I'll shortly describe all of them, so you don't need to waste 30 minutes of your precious time watching the video. If you're interested in the theme or feel that something is still unclear after reading the post, then go to YouTube and watch the video (it is not boring at all, I promise).

Thanks to the guy who has even drawn block schemes for every strategy. I'll attach them in the comments.

Okay, let's start.

1. Lazy cache

The most basic one. If user request's some data, we try to find it in cache. If it is there, give it to user. If not - make a request to the server and update the cache with data from successfull response.

Pros:
- easy to implement
- instant data delivery
- cached data is independent of internet connection

Cons:
- no cache invalidation

When to use it:
- apps with immutable data that you should upload once a while like book readers, offline apps, etc.

2. Synchronized cache

The same thing as a previous one, but there are two new steps for invalidation. Local (by expiration date for ex.) and server (by status code 304 NOT MODIFIED for ex.) invalidation. If cache is valid we return data to the user.

Pros:
- faster delivery time for up to date data
- invalidation

Cons:
- dependent of connection

When to use:
- apps with not idempotent data*** where user can't add or edit this data. For example: news and booking apps

3. Write-through cache

The most difficult one to implement. However, the reading process is the same as in synchronized cache. But when we apply some changes, we need to synchronize them with our server database.

Pros:
- faster delivery time for up to date data
- invalidation
- full synchronization with server

Cons:
- dependent of connection
- after failed write we should go back to the initial state
- complex implementation

When to use:
- messenger is a best example

4. LRU cache

It speaks for itself. Least recently used cache is removed when we are out of cache memory, so we can put new piece of data in the cache. However, the invalidation now is in write process. MRU and other algorithms can be used.

Pros:
- instant data delivery
- cached data is independent of internet connection
- customizable invalidation mechanism
- not inflating the size of cache data

Cons:
- complex implementation
- you should be careful with invalidation. For example, you may remove some cached data, that user will need in a second.

When to use:
- apps with heavy content like instagram

* those annoying spinning things, which indicate that we are waiting for data from the server
** if there is no connection, we can't properly invalidate our cache
*** the data may update if you refresh the page

#dev
English from zero to hero (or from anywhere to hero)

Hi everybody, today I'd like to recommend a YouTube channel for those who want to get better at English regardless of their current level. In case you are C2, don't forget to suggest it to your friends when they ask you how to learn English.

I've heard about it from a programmer's interview who moved to the US, checked it out because I'm still on my long and complicated way to watching movies without subtitles (currently somewhere between B2 and C1). And it appeared to be a godsend.

There are 3.2k videos in total with 1.3m subscribers on the channel for Russian-speaking people. The guy has plenty of playlists of all kinds: Grammar from zero to hero (649 videos), 50 lessons for each level (A0-C1), English by formulas (398 videos), and much more. Here is the same channel, but completely in English. By the way, he also has many other channels, which partly duplicate the content of the main one. I've heard he also owns a mobile app "Engish Galaxy".

I've watched just a couple of vids from a C1 playlist and can say that I've enjoyed the process. If we take into account that all of these videos are high-quality, just imagine the amount of work done by Alexander Bebris.
Not afraid to call him Pavel Victor of the English education world.

However, you shouldn't forget to practice other skills like writing and speaking to improve your English.

If you are already acquainted with this man or his channel(s), I'd like to hear your thoughts about it. If you know any other good resources for learning English, it is a great chance to share them with others.

#english #career
👍2
Efficient programmer's notes pinned «Hello, my fellow friends. I'm on detox now. It means that I'm trying to read books instead of scrolling the newsfeed, watching online courses instead of Instagram stories, eating fruits/vegetables/nuts/otherHealthyStuff instead of trashy snacks, walking every…»
Efficient programmer's notes pinned «Some thoughts on this channel Hello, my friends. It's been about a month since I've started this channel. And there are already 10 posts in here. These posts mostly are about good habits + efficiency. I appreciate all of you who were reading them. Hope it…»
The Broken Window Theory or Why Technical Debt is an Evil

Have you ever heard about the broken windows theory?

It states that any visible signs of crime and civil disorder, such as broken windows, vandalism, loitering, public drinking, create an urban environment that promotes even more crime and disorder.

"One broken window, left unrepaired for any substantial length of time, instills in the inhabitants of the building a sense of abandonment—a sense that the powers that be don’t care about the building. So another window gets broken. People start littering. Graffiti appears. Serious structural damage begins. In a relatively short period, the building becomes damaged beyond the owner’s desire to fix it, and the sense of abandonment becomes reality." - Andrew Hunt & David Thomas in "Pragmatic Programmer"

Therefore, we may conclude that policing these relatively small misbehaviors will decrease or prevent an increase of the crime rate in the area.

I hope you've already noticed where I'm going.

If you leave "broken windows" (bad designs, wrong decisions, or poor code) in your codebase, very soon it'll become a "dangerous place to live in". So, don’t leave them unrepaired. Fix them as soon as they are discovered, otherwise, all of a sudden, you'll need to get a dumpster, or move to another neighborhood.

Easier said than done, yeah?

#dev #thoughts
👍5
Stop using those annoying spinners

I've been catching myself thinking that loading spinners really piss me off lately. It's okay when I see them while logging in to some service, but it becomes a living hell when I see them everywhere afterward. In some mobile apps, you may encounter them on each and every screen. Moreover, I've seen a web app with 10-15 different sections on one screen with 10-15 spinners. One for each section.

I do understand why people use them. It is the easiest way to show that something is loading. And it's even worse when you don't give your user any feedback. But these spinners have some serious flaws.

In The Psychology of Waiting Lines, David H. Maister describes the psychology of queueing. The concepts from his research can be applied to any situation when people are forced to wait for something.

Here are my three takeaways:
1. Unexplained waits feel longer than explained waits.
2. Unoccupied time feels longer than occupied time.
3. Anxiety makes wait feel longer.

And now you can see why bare loading spinners are garbage:
1. They don't explain to us what we are waiting for.
2. We can only watch at the spinning wheel, which is boring. You can compare it to looking at the clock.
3. We don't know when it'll end.

Here is what you can do to fix it:
- Explain the wait. Put some text like: "We are looking for available tickets so you can forget about your work and chill out on the Miami beach. This might take up to a minute." below the spinner.
- Occupy your user with additional information, a short survey, fan fact, or motivational quote.
- Show progress indicator, which will display the actual progress. You can estimate the speed of the progress bar using historical data if you aren't able to get real-time feedback from the application.
- Remove the spinner if it is a placeholder for other content. You might have noticed how Google, Facebook, Instagram, and other big services handle such situations. Google shows low-quality images while high-quality ones are on their way. Facebook and Instagram often use Skeleton UI*. Facebook has even developed an open-source library Shimmer for Android and iOS that make these skeleton screens even more appealing.

*A skeleton screen is a UI that doesn't contain actual content; instead, it shows the loading elements of a page in a shape similar to the actual content.

#dev #thoughts
👍4
Which one do you prefer?
Anonymous Poll
21%
Loading spinner
79%
Skeleton with shimmer effect
Easy money or How not to get followers

It was a long time ago. It was a time when every other article on the internet was about getting easy money, or at least it was just my filter bubble. I didn't have any skills besides playing tennis, though an idea of even insignificant online income seemed attractive.

So I've found a way. My work was to subscribe to other communities in VK* via a special platform. Every subscription gave me a couple of cents. At the end of the week, I had around 1k communities in my subscriptions and some dollars that I exchanged for a VK's internal currency and happily spent on online poker. I felt contended. Soon, I've cleaned up my community list.

I was wondering why did they pay me for such easy tasks. I've realized their business model not so long ago when I got interested in marketing. The platform I was using applied the CPA (cost per action) model.

Advertisers want to get more subscribers for their communities. They pay 0.2$ dollars for a subscriber to this service. Service offers you 0.02$ for a single subscription and earns 0.18$**. Advertisers get their subscribers, you and service earn money. Win-Win-Win.

Not so fast. Remember, I said that I'd cleaned up all my subscriptions after the experiment? Here's the catch. Advertisers get a disloyal and non-target audience.

Do you need these people as an advertiser?
Maybe, if your channel targets the general public (memes, news, funny cats&dogs). Probably, many people will stay with you if you have decent content. If your channel is domain-specific, every other subscriber coming from such a platform will unsubscribe ASAP as they get money or hide your posts from the feed because he/she most likely doesn't give a damn about you and your topic.

So, the conclusion is to make people subscribe to you because they are interested in you and the content you produce, not the money you offer them to subscribe.

You'll ask me how it's connected to programming. I've prepared two points for this case:
1. Every developer should be a bit of a marketer to sell his ideas, solutions, projects, and himself/herself***. So from now on, you may see posts about marketing on this channel.
2. I've considered this info interesting and worth writing about.

*Russian analogy for Facebook
**Numbers may vary
***During the job interview or working as a freelancer

#marketing #thoughts
👍5
Learn blockchain, bitcoin, and web 3.0

What is the hypest thing in software development nowadays?
I bet it is Web 3.0 that includes topics like blockchain, dApps*, smart contracts, and other buzzwords.

I've connected my diploma thesis with blockchain and its security features because I've been wanting to figure out how this works for ages.

I've dug a bit deeper than blockchain and can't stop satisfying my curiosity. I believe these technologies are still in their early stages of a long-term trend, so you and I are not missing the boat yet.

If you've always wanted to understand blockchain and how/why bitcoin works under the hood, here are only two videos I want you to watch (1,2). These are visual demos that explain basic concepts like hashing, blocks, transactions, coinbase, distributed ledger, digital signature, and how it all works in tandem.

Here are some other resources that I found valuable:
1. MIT course on blockchain and money (en, ru). Learn fundmentals with Gary Gensler - an American government official and former investment banker. Btw, I've skipped the first two lectures about the history of money just because they're boring.
2. Binance academy - "your one-stop guide to all things crypto." If you like reading articles more than watching YouTube.
3. Polygon** academy for developers. It seems to be a fast start to developing decentralized apps.
4. How to DeFi beginner/advanced and How to NFT. I've not got around to these yet but heard only positive feedback.

If you have something to add to the list, write it in the comments. I'm still quite a dummy in the theme, and will appreciate every suggestion.

*Decentralized apps
**A scaling solution for the Ethereum blockchain

#crypto #blockchain #learninpublic
👍6
Pardon me for not writing for a while. I remember my New Year's resolution to write a post every week, but everybody needs a little break today, and I hope you can understand.

I still feel overwhelmed by what's happening in the world today. But life goes on. I can't just sit down reading the news and freaking out. I still have work to get done by the end of the next sprint, relatives that I must support during these difficult times, a diploma subject to get researched, posts to be written, and much more.

As Mark Twain (not quite sure if it was him) once said: “If you don't read the newspaper, you're uninformed. If you read the newspaper, you're misinformed.”

I prefer to read the news believing no one and focus on my day-to-day life.

I hope you and your families are safe and healthy and everything's gonna be okay very soon.
Sentry

Today I want to tell you about an amazing tool I didn't know existed when I was starting out as a developer. Luckily, I got acquainted with it as soon as I got into a company with numerous web and mobile apps in production.

Its main purpose is to track errors in your apps. In other words, if the app throws some weird exception in production, you instantly get notified and receive a stack trace*. So, you can see when and why your app crashes and release a patch before all of your users abandon you.

Moreover, there is another feature, that I didn't have a chance to benefit from. It is performance monitoring. Sentry allows you to measure metrics like throughput, latency, failure rate, number of users impacted, and user misery. On top of that, you get a lot of graphs that visualize these metrics, so you're able to keep an eye on changes in performance over time.

What I especially love about Sentry is that there is a well documented library for almost every platform (language/framework/library) which allows you to use it in all of your projects both on frontend and backend. The second thing is that it has a free plan, so you can always try it out if there is no need for third-party integrations or other team members to join.

*In Flutter you can also get info about recent screen transitions

#dev
👍4
To do != to get done

I won't pretend that it's my original idea. I've decided to borrow it from a cool book on project management because it resonates with me.

Let's imagine a simple task you have to get done.

Your wife asks you to buy a loaf of bread for dinner. In other words, your goal is to have tasty bread on your table, so you and your wife enjoy it with a soup today. When a task is so trivial, nobody doubts if it's is done or failed.

❌ You forget to buy a loaf.
❌ You buy some old bread that nobody wants to eat.
❌ You get hit by a car on your way home, and an ambulance takes you to the hospital.
✅ You enjoy bread today during the evening meal (at some X time).

To get something done is to get the result by the specified deadline with the specified quality. Everything else has nothing to do with "getting done" even if the sun has exploded.

What if we have a more complex and undetermined task?

A client asks you to design a landing page by the end of the week. Today is Monday. The task's deadline is 18:00 Friday - you should present your design that meets all requirements given by the client on Zoom meeting.

❌ You did nothing.
❌ You have nothing to show during the call, but you've been working hard all week.
❔ You came up with a great design (at least you and your mom like it) and even implemented it. You think the client will be more than happy.

The last point has a small probability that everything will be fine. But:
❌ What if you or your client forgets some small but cruical detail or your design doesn't actually meet all of the requirements?
❌ What if nobody else appreciates your genuis idea? After all, you have no more time to fix all the issues.

How we could have avoided this situation?

By setting control points.

You could schedule a call with a client on Wednesday, so he could validate your concept and point out the flaws. This way, you have just enough time* to fix everything by the Friday. Moreover, this intermediate call is another deadline that should stimulate you to not put the task off until the last minute.

*If you set an adequate deadline in the first place.

#career #books #projectmanagement
👍3
Push it harder (Part 1)

Recently, during a technical interview, I was asked about push notifications. I was expected to talk about the developer's steps to set up and handle push notifications in the app, like registering a device, subscribing to a particular topic, getting and storing a token, receiving messages. So I wanted to refresh my memory and make a small overview of this feature.

There are services like Firebase cloud messaging (FCM), OneSignal, Amazon SNS, Pusher, and others that come into play when you need to enable push notifications. I will focus on FCM as it is a very popular cross-platform messaging solution developed by Google, and, also, it is the only service I have experience with) The information bellow is a condensed form of the FCM docs.

Key capabilities

- Sending up to 4000 Kb of payload in one message
- Sending notification or data messages
- Three different ways of targetting: to single devices, to groups of devices, or devices subscribed to topics
- Analytics
- Supports Android, iOS, web

Architectural overview

There are four components in the chain of building, delivering and receiving messages (picture 1 in comments):
The notification request builder.

1. It can be a GUI-based notification composer in the Firebase console, Admin SDK or the FCM server protocols used in the trusted environment*
2. FCM backend - accepts requests, performs fanout of messages via topics, and generates message metadata, like message id.
3. Platform-level transport layer - routes the message to the targeted device and handles its delivery.
- Android transport layer (ATL) for Android
- Apple Push Notification service (APNs) for Apple devices.
4. SDK on a device.

Lifecycle flow

1. An instance of the client app registers to receive messages, obtaining a FCM token that uniquely identifies the app instance. Several additional steps are needed to register Apple devices in FCM:
1) First of all, you should get the APNs device token.
2) Register it in FCM.
3) Get FCM device token which is associated with APNs device token. So when you need to send a notification, FCM searches for the corresponding APN's device token and sends a message request to APNs. (picture 2 in comments)
2. You'd probably want to send this FCM token to your server and store it on the device.
3. Your backend decides that a certain device should get a push notification, so it takes its FCM token, composes a message, and sends this request to FCM.
4. FCM backend gets this request, generates metadata, and sends it to the platform-specific transport layer.
5. When the device is online, the message is sent to the device.
6. You're able to react to the notification in your client app by overriding certain methods (onMessage, onBackgroundMessage). App behavior when receiving messages depends on whether the app is in the background or the foreground.
7. When a user logs out, you probably want to unsubscribe him from notifications. Login -> Subscribe.
8. You'd better update your token every once in a while, so you know that the device is still active and you aren't wasting resources by sending messages to inactive users.

*Firebase cloud functions or app server
👍3