Stay updated with the last news about Hive Power on our new blog

We announce that in order to have full control on our content, we have created our own blog which is available at this link: https://blog.hivepower.tech This means that we won’t use Medium anymore…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Do you mark your Compose preview functions as private?

(or have you ever written preview functions?)

I used to look for this during code reviews, but sometimes I forgot to set them to private in my work. 🙂

People tend to apply all sorts of principles when writing other functions, but some of us generally do not care too much about preview functions.

Marking preview functions as private can improve code organisation, reduce the risk of errors, and help with encapsulation.

Marking preview functions as private means that they can only be accessed within the same class or file. This can help you encapsulate your code and prevent other parts of the project from accessing or modifying the preview functions.

When you mark preview functions as private, they are hidden from other parts of the project.

Likewise, if a preview function is marked as public, it can be accessed by other parts of the application. I am unsure why people would want to call the preview functions from somewhere else, but at least they can do so. This increases the risk of errors or unexpected behaviour, especially if the preview function is modified without considering the impact on other parts of the project. Marking preview functions as 𝚙𝚛𝚒𝚟𝚊𝚝𝚎 reduces this risk by limiting the function’s scope.

Long story short — If you bother to mark other functions you write private, why do you have excuses for Compose preview functions? Think about this again…

It is generally a good practice to follow the principle of least privilege and declare your functions with the lowest possible access level that allows them to be used as intended. If you say some libraries require this to work, it is fine, but what if this is not your answer?

Credit: A joint effort of ChatGPT and me. 🙂

Add a comment

Related posts:

So What Is Design Operations?

Working in the media, and especially the creative industry, new job titles are made up almost every week. It is getting harder and harder to describe what you do at your job as a Designer because the…

John Snow and the cholera problem

Discussing John Snow, the father of modern epidemiology.

Shall We Play a Game?

One of my favorite movies as a kid was WarGames with Matthew Broderick and Ally Sheedy. The 1983 film focuses on Broderick’s character, David Lightman, who is a young hacker who thinks he’s hacking…