Day 18 of Flutter

Photo by Gnider Tam on Unsplash

Day 18 of Flutter

On day 18, I did more code refactoring and improved already built functions, such as making sure the user verifies their email after registration, accessing the main view of the app after registration and login, and also displaying errors that may occur to the user. During this phase, I learned about hardcoding and why it isn't the best practice.

Hardcoding

Hardcoding is when specific values are embedded into an app's source code. Hardcoding is not only practised in Flutter but programming in general. In some cases, hardcoding is not considered best practice. For example, the routes for my notes app have to be hardcoded whenever I want to navigate to a view, which eventually bloats the source code with string literals. To deal with this, I created a file for my routes and assigned the values to a variable used whenever I want to navigate to a view.

Why Hardcoding Isn't Considered Best Practice

  • Lack of flexibility: Hardcoded values cannot be easily changed without modifying the source code of an app. This can make the program rigid and challenging to maintain over time.

  • Difficulty in testing: Hardcoded values make it difficult to test a program since the values cannot be easily varied. This can lead to bugs and other issues that are difficult to catch during testing.

  • Security risks: Hardcoded values can be a security risk. Because they may include sensitive information like passwords or API keys that could be discovered easily by attackers.

I also created a file for my dialog functions to help display the exceptions I handled using try-catch blocks on day 14 to my user. That will be all for today.