Programming Tips 💡
54.5K subscribers
65 photos
8 videos
30 files
338 links
Programming:
Tips 💡
Articles 📕
Resources 👾
Design Patterns 💎
Software Principles

🇳🇱 Contact & Ads: @MoienTajik
Download Telegram
DRY - Dont Repeat Yourself 🙅🏻‍♂️

Duplication can lead to maintenance nightmares, poor factoring, and logical contradictions.

The DRY Principle states :

"Every piece of knowledge must have a single, unambiguous, authoritative representation within a system."


🔹🔸🔹🔸

Duplication, and the strong possibility of eventual contradiction, can arise anywhere in :

• Architecture
• Requirements
• Code
• Documentation

The effects can range from mis-implemented code and developer confusion to complete system failure.

🔺🔹🔺🔹

Advantages of DRY 💎 :

• Maintainability
• Readability
• Reuse
• Testing

[ Website ] : http://bit.do/drypp

https://t.me/pgimg/19

#DRY #Principle
@ProgrammingTip
SOLID Principles : Simply Explained

• Single Responsibility
• Open / Closed
• Liskov Subsitution
• Interface Segregation
• Dependency Inversion


#OOP #Principle #Solid
@ProgrammingTip
GIGO ♻️

GIGO is a computer science acronym that implies bad input will result in bad output, which stands for :

Garbage in 🗑
Garbage Out 🚮

🔸🔹🔸🔹

Because computers operate using strict logic, invalid input may produce unrecognizable output, or "garbage."

For example, if a program asks for an integer and you enter a string, you may get an unexpected result.

Good programming practice dictates that :
"Functions should check for valid input before processing it."


A well-written program will avoid producing garbage by not accepting it in the first place.☝🏻

Requiring valid input also helps programs avoid errors that can cause crashes and other erratic behavior. ⚡️

https://t.me/pgimg/33


#Principle
@ProgrammingTip
Explicit Dependencies Principle

Classes should be honest about what they need to be created. 🗣

Methods and classes should explicitly require any collaborating objects they need { typically through method parameters or constructor parameters } in order to function correctly.

[ Article ] : http://bit.do/expp

https://t.me/pgimg/35

#Principle
@ProgrammingTip
Hollywood Principle

"Don't call us, we'll call you" ☎️ 


Relevant when you are writing a class/component that must fit into the constraints of an existing framework.

You implement the interfaces, you get registered. 👤

You get called when the time is right. 📞

🔹🔸🔹🔸

By way of an example, a typical ASP.NET Web Form might have in its codebehind page event handlers to respond to Page_Load and Button_Click events. ⚡️

An ASP.NET developer writes code to respond to these external framework events, instead of owning the execution of the web server and making all decisions and method calls accordingly.

[ Article ] : http://bit.do/holprin

https://t.me/pgimg/39


#Principle
@ProgrammingTip
From STUPID to SOLID Code

In the following, We will introduce both STUPID and SOLID principles.

Keep in mind that these are principles, not laws.

However, considering them as laws would be good for those who want to improve themselves. 💎

[ Article ] : http://bit.do/soltup

https://t.me/pgimg/46


#SOLID #Principle
@ProgrammingTip
Principle of Least Surprise 😳

Principle Statement :

In interface design, always do the least surprising thing. 😨

Description :

Never surprise the user.

An interface should behave exactly as the user thinks it behaves.

What surprises the user depends on the kind of interface and the type of user. 🖥

The central idea of PLS is to think about how the user would want to use the interface. 🤳🏻

Principle of least astonishment is when you, as an API designer, prevent your users from saying WAT. 😱

🔸🔹🔸🔹

Examples :

1️⃣ Consider an elevator with a button next to it that says "call". ☎️

When you press the button, the payphone phone rings (rather than calling the elevator to that floor).

The correct design would be to put the call button next to the phone rather than the elevator.


2️⃣ Think of a web page that has popup window that shows a windows style error with an 'ok' button on it. 🆗

People click the 'ok' button thinking it is for the operating system and instead go to another web page. 🌐

This astonishes the user. 😦


3️⃣ The name of a function should reflect what it does. Otherwise, a user of the function will be unpleasantly surprised❗️

Bad :
int multiply(int a, int b)
{
return a + b;
}


Better :
int multiply(int a, int b)
{
return a * b;
}


🔹🔸🔹🔸

When it comes to an API ... 👾

Think about a toString() method that instead of printing out the fields returns back "to be implemented". 🤥

An equals() method that works on hidden information. 👁

Sometimes people try to implement a sorted list class by changing the add method to call sort() on the array afterwards. 🗂

This astonishing because the add method is supposed to append to the list. 🗳

This is especially astonishing when one gets back a List object with no knowledge that somewhere deep inside, someone violated the interface contract. 🤔

Having a method that does one distinct thing contributes to reduction of astonishment.

https://t.me/pgimg/115


#Principle #PLS
@ProgrammingTip