Why is it possible to lose weight only with the help of programming?

This article will have two parts: a technical one, about a Java application written for AWS, and a demagogic one about losing weight, motivation, etc. If you are only interested in the technical part, you can jump to the “Technical Part” section, and if not, I invite you to the reasoning part:

A few years ago I read an article that gave a lot of calculations, formulas and explanations of why it is so difficult for us, developers, to lose weight. Unfortunately, I did not find the link, but I think many of you have come across similar publications. I do not understand at all why there is so much such material and talk about losing weight, if there is only one way in our universe (maybe in another universe the laws of physics are different) to lose those coveted kilograms, and that is to consume fewer calories than you spend. There is no other way to get rid of excess weight, nature did not invent it, it did not arise in the evolutionary process, and if someone claims the opposite, then perhaps you are a magician and a wizard, why are you reading this article? Then what does programming have to do with it?

Demagogy

I don't believe that losing weight is a difficult and complicated process. Getting rid of excess weight is a long process, which in an ideal (for me) scenario develops into a lifelong process and never ends, like a renovation. True, in the process it moves into another category, where you are not trying to lose weight, but become an athlete for your own health and longevity, and all the heaviness goes into the equipment. And if so, does this mean that you will never get the desired result? Exactly. As soon as you set such a goal: I need to lose weight, you predetermine your failure. The goal should be formulated differently: I want to live a healthy and fulfilling life. The goal of losing weight will never lead to satisfaction, because the reflection in the mirror will never look the way you want, and it will never be like in the Instagram photos of fitness bloggers, at least because you are not a fitness blogger. The goal of losing weight immediately raises the question: how long will it take to lose weight and how? Well, most likely, as quickly as possible, right? Which means either start drinking some crap like fat burners and ruin your health, or put yourself on a strict diet and after a while gain even more than you lost, and repeat this cycle over and over again. How many times have I seen this cycle in gyms: time after time, people starting a new life and returning to the old one with the speed they had gained, falling into an even bigger hole. Let's even assume that you lost the coveted kilograms, did you start looking better? Most likely not, because losing water, fat and muscle does not mean looking better, for most people it is rather the opposite effect. And then, look better for whom? For yourself, for photos on Instagram or for your husband, wife, boyfriend or girlfriend? Not once in 11 years spent in gyms, have I talked to a person who would be happy with the result of such a goal in the long term, NOT ONCE! I can explain and give examples for a very, very long time. For myself, I have decided once and for all: this is not the goal and can never be the goal. I presumptuously suggest that you agree with me, at least for the time of reading this article.

Target

So, our goal is to be an athlete for the rest of our lives and improve its quality. Why should the goal be lifelong? Because I am 100 percent sure that the overwhelming majority of people on earth are the same in one thing: we want to live happily. What this means is up to you to decide, and I am not talking about destructive or unfulfillable desires, maniacs or psychopaths, I am talking about the majority. So if we want to live happily, then why not set a goal that we will be able to keep for the entire time allotted to us, and not from 23 to 31 years old? And it is impossible to keep such a goal without consistency on a daily basis, and further we will talk only about food. Not even about training and about the fact that we should be more active, move more, run and blah blah blah, but about what we cook and eat every day. Proper nutrition is almost 80% of success in achieving the goal, and maybe more. If you can control what you eat, you can control your weight, your well-being to some extent, improve your sleep and, ultimately, your life. What nonsense, I write and do not believe it myself. And you calculate what percentage of life is food, and how much your body is affected by what you feed yourself for decades cannot be overestimated. I would also add sleep here, but this is a separate conversation, I will leave a link to an excellent book about it.

A win-win plan of action

I will try to describe a scheme, which, in my opinion, cannot be a win-win, and in short, the changes should happen very, very slowly and should start with the simplest steps. At the moment, I just know my calorie intake, which is 2300 kcal per day, and I count every meal, if I want to lose weight, I gradually reduce calories, if I want to gain weight, I increase them due to protein and carbohydrates. But this is very difficult and time-consuming for many people to just start counting, if you have never done this, then most likely you will not last even a couple of months. Let's simplify the scheme. Let your first step be to start writing down what you eat, make a note in your phone and continue this for a few weeks, and then start analyzing, ask yourself: what could I remove from my diet? For example, on my way home from work, I usually eat two candies or drink a soda, which means I can eliminate it and so on, step by step: eliminate something from the diet completely, replace something with protein and fiber. Does it also seem very difficult? No problem, simplify the first step even more for yourself, since you want to be able to make it a habit for life. For example, like this: I will drink 2-3 liters of water every day, I have a bottle into which I will pour these two liters, and by the end of the day it should be empty. I think you understand the pattern: this is to do something that you can do for a week, two, a month, and so on, without stopping and never ceasing. And add such changes as you get used to the previous ones.

Technical part

Now I'm moving smoothly to programming and how it can be connected. As I mentioned earlier, I count calories, which means that I (or my wife) weigh the raw food that we will eat, and we don't always have the opportunity to cook every day, so we cook for a week. What's the difficulty? For example, we cooked 500 grams of rice, but it's 500 grams of raw rice, and how much is cooked? Each time it's a different number, it depends on many factors, but the essence is the same: you need to know (if you count calories) how many grams of raw product are on your plate. Do you feel the potential for automation? Each time, taking cooked rice (or any other food), we had to count it using the same formula to understand how much raw rice is in the cooked one, and so on with each dish and meal: chicken, beans, beef, fish, bread, butter, buckwheat, and so on.

Formula:

(X / N) * Y, where:

  • X is the raw weight of the food you want to eat

  • N — total raw weight of the prepared dish

  • Y — total weight of the finished dish

Automation of the process

Each time the weight of the finished product is different, because we don’t want to go crazy eating only boiled chicken and rice. Therefore, the end result changes depending on how you cook. So, at some point we realized that we need to make it more convenient. That’s how the idea came up to make an application that would remember and count all this for us. The idea is very simple:

We write down the food we cooked, the raw weight, the finished weight, and when we eat, we simply choose the dish and how much raw you want to eat, and the bot gives you the finished weight, which will correspond to the raw weight. For example, if you cooked 500 grams of rice, the output is, let's say, 1210 grams of the finished dish, so in order to eat 40 grams of raw, you need to take 96 grams of the finished one.

Preserving the dish

Preserving the dish

Eating

Eating

Implementation

How to implement such functionality is an unplowed field of options. What influenced my decision: firstly, I did not want to have a separate application for this, especially for such insignificant functionality, there should be something that I use constantly. Secondly, I wanted to study AWS Lambda, and the choice was obvious – Telegram Bot. For DI, I chose Dagger. But for communication with the DB, I used standard tools from java.sql, and in the end I regretted that I did not spend more time looking for some lightweight ORM solution. You need to write a lot of auxiliary code, it takes a lot of time, and the project is growing a lot.

Main functions

So, I needed to do only two things: the ability to remember cooked food and count how many grams of cooked food there are in N grams of X grams of raw food. There are only two buttons: “Cooking” and “Eating”. Each time one of these buttons is clicked, a message flies to the Telegram server and from there comes to the API Gateway webhook, which triggers the lambda function, and this request goes to the handleRequest method, where in the input, in the body field, there is a user message and all the additional information that needs to be put in the update object. Accordingly, with each new message from the user, we need to know what step the user is at in order to send him the right message and perform the action corresponding to his step. The exception is commands such as /start, /help, /cancel. /start and /help are standard commands that Telegram recommends implementing for a better user experience, here messages are simply displayed to the user and there is no need to go to the DB. With the /cancel command, the user needs to be returned to the beginning and all previous actions are canceled. To my shame, I was lazy here and did not implement the process of canceling the deleted dish when deleting, this command simply returns the user to the main menu. But the /delete command also starts a chain of actions, like the main buttons, and the user step is saved in the database.

Project structure

  • The com.nutritrack.bot.service.step package contains all the logic responsible for processing each user step.

  • Each service implements the StepService interface, and is named after the custom step: SteplessServiceImpl, RawFoodWeighingServiceImpl, etc.

  • All possible user steps are represented in the UserStep class.

  • At the end of each service, the user's Step changes and is saved in the database so that the desired service can be called with the next message.

Link to the project itself. In README.md I tried to give detailed instructions on how to run it locally. Link to the project itself bot.

Conclusion

This is such a seemingly simple project, but there was something to think about and study. For now, you can poke around and look at the response time of the first message and subsequent ones. If you suddenly want to join and push your contribution, I will be very glad and grateful.

This is definitely the last conclusion.

Why did I need to do this project and write this article? Firstly, for my own convenience and to save time in every day of my family. Secondly, for motivation: I made my project, it is not perfect, not without mistakes, but it helps me to stick to my goal every day. Isn't that a worthy reason for spending time? Well, and a sufficient number of positive side-effects, such as learning new technologies: Dagger and AWS Lambda, realizing mistakes in choosing libraries, a finished pet-project that is on GitHub, and not in a folder on a portable storage device that I will never remember, and so on. And the article? Well, if I inspired or helped at least one person with the work done, then it was not in vain! And if any of you lack motivation to start doing something big, start small. And if your own project, article or contribution to someone's application will prompt positive changes, then why not try? Thank you all for your attention!

P.S. As the master said: The less tests you write in applications, the more calories you burn when debugging 😉 may the force be with you.

Book: Matthew Walker; Why We Sleep

Video about the intestines, immunity and nutrition from doctor Alexander Dzidzaria

To contact me LinkedIn

Project on GitHub

Telegram Bot

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *