Lädt...


🔧 Constants in JS and what do Plato and Aristotle have to do with it


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

It seems to me that juniors view code components as material things, while seniors deal more with ideal categories.
Or maybe it depends on a person's worldview rather than their professional level?

Sometimes during code reviews, I come across code where instead of the constant CAR_WIDTH, the developer used the constant TABLE_WIDTH because it was the first constant he found with a suitable value.

This is a common problem when developers choose a constant based on its value rather than its name. It turned out that the developer doesn't understand the primary purpose of constants. In his view, constants are only for reuse and readability.

Let's recall what Plato and Aristotle had to say about this.

They had their own constant called SHIP_OF_THESEUS.
https://en.wikipedia.org/wiki/Ship_of_Theseus
It was probably named differently in Greek, but we'll write it in Latin and therefore translate it into English.

const SHIP_OF_THESEUS = {
    name: "Ship of Theseus",
    parts: ["mast", "hull", "sail"]
};

The constant SHIP_OF_THESEUS in this example symbolizes the unchanging identity of the Ship of Theseus. Its value, which changes over time, represents the material changes.

// Day 1: Initial state of the ship
const SHIP_OF_THESEUS = {
    name: "Ship of Theseus",
    parts: ["mast", "hull", "sail"]
};

// Day 2: Developer changes one part of the ship
const SHIP_OF_THESEUS = {
    name: "Ship of Theseus",
    parts: ["new mast", "hull", "sail"]
};

// Day 3: Developer changes another part of the ship
const SHIP_OF_THESEUS = {
    name: "Ship of Theseus",
    parts: ["new mast", "new hull", "sail"]
};

// Day 4: Developer changes structure of the part of the ship
const SHIP_OF_THESEUS = {
    name: "Ship of Theseus",
    parts: {
        mast: "new mast",
        hull: "new hull",
        sail: "sail"
    }
};

Ideal (Constant):

SHIP_OF_THESEUS: Every day, this constant represents the ideal essence of the Ship of Theseus. Despite changes in its value, the concept of the ship remains unchanged.

Material (Value of the Constant):

parts: The list of parts of the ship that changes every day. This reflects the material embodiment of the ship, which changes over time.

Plato on Ideal and Material:

The constant SHIP_OF_THESEUS as an ideal form remains unchanged: every day it represents the Ship of Theseus. However, its value (the parts) may change, reflecting material changes.

Aristotle on Form and Matter:

Aristotle would say that the identity of the ship is preserved through its form and function (very similar to duck typing in JS, isn't it?). In our example, although the parts of the ship change, the form of the object (its structure and function) remains unchanged. Every day it is still the same Ship of Theseus, despite changes in its parts.

So what are the actual benefits of using constants?

The main benefit is not readability and reusability. The main benefit is the separation of code into ideal and material (according to Plato) or form and matter (according to Aristotle).

By making this separation, we can change the matter without changing the form.
And we can use the form throughout the program without worrying about matter.

...

🔧 Constants in JS and what do Plato and Aristotle have to do with it


📈 89.23 Punkte
🔧 Programmierung

🔧 Practical Project Aristotle: Bringing Google Team Effectiveness Theory to Life


📈 32.28 Punkte
🔧 Programmierung

🐧 Aristotle Linux tool (pull Wikipedia descriptions with 1 command right into your terminal)


📈 32.28 Punkte
🐧 Linux Tipps

🐧 Aristotle Linux tool (pull Wikipedia descriptions with 1 command right into your terminal)


📈 32.28 Punkte
🐧 Linux Tipps

📰 ESA-Sonde Plato soll ab 2026 nach Exoplaneten suchen


📈 26.73 Punkte
📰 IT Nachrichten

📰 A Book Recommendation for Bill Gates: The Story of PLATO


📈 26.73 Punkte
📰 IT Security Nachrichten

📰 SXSW-Konferenz: Aus Plato hätte unser Internet werden können


📈 26.73 Punkte
📰 IT Nachrichten

📰 SXSW-Konferenz: Aus Plato hätte unser Internet werden können


📈 26.73 Punkte
📰 IT Nachrichten

🕵️ TUTOR on PLATO IV ext Command denial of service


📈 26.73 Punkte
🕵️ Sicherheitslücken

📰 Deep Learning mit Plato


📈 26.73 Punkte
📰 IT Nachrichten

🎥 EH20 Das PLATO-System - Ein unbekannte aber prägende Perle im Urschleim unser Cyberkultur


📈 26.73 Punkte
🎥 IT Security Video

📰 Plato im Escape Room: «Talos Principle 2» im Test


📈 26.73 Punkte
📰 IT Nachrichten

📰 AI just helped us find out where Plato is buried - here's how


📈 26.73 Punkte
📰 IT Nachrichten

📰 Plato's Final Hours Recounted In Scroll Found In Vesuvius Ash


📈 26.73 Punkte
📰 IT Security Nachrichten

📰 PLATO: Bald beginnt die gezielte Suche nach einer zweiten Erde


📈 26.73 Punkte
📰 IT Security Nachrichten

🍏 PCalc for iOS and Mac enhanced with new capabilities for functions, conversions, and constants


📈 24.26 Punkte
🍏 iOS / Mac OS

🔧 Variables and Constants: Declaration and Usage


📈 24.26 Punkte
🔧 Programmierung

📰 Protected API Calls and String Constants: Looting Dridex’s Candy Box


📈 23.3 Punkte
📰 IT Security

📰 Protected API Calls and String Constants: Looting Dridex’s Candy Box


📈 23.3 Punkte
📰 IT Security

🕵️ XM^online Common Utils and Endpoints 0.2.1 Constants.java sql injection


📈 23.3 Punkte
🕵️ Sicherheitslücken

📰 Humans and identity are constants in the ever-changing world of cybersecurity


📈 23.3 Punkte
📰 IT Security Nachrichten

📰 Rust Basics Series #2: Using Variables and Constants in Rust Programs


📈 23.3 Punkte
🐧 Unix Server

🔧 Variables, Shadowing, and Constants in Rust


📈 23.3 Punkte
🔧 Programmierung

🔧 Swift 101: Understanding Types, Variables, and Constants


📈 23.3 Punkte
🔧 Programmierung

🔧 Mastering Go: Guide to Type Declarations, Variables, and Constants


📈 23.3 Punkte
🔧 Programmierung

🔧 Static Variables, Constants, and Methods


📈 23.3 Punkte
🔧 Programmierung

🔧 Constants, Object.freeze, Object.seal and Immutable in JavaScript


📈 23.3 Punkte
🔧 Programmierung

🔧 Enhancing Enum Constants in Laravel with Description and Label Attributes


📈 23.3 Punkte
🔧 Programmierung

🔧 Variables, Constants, Data Types, and Namespaces in C++


📈 23.3 Punkte
🔧 Programmierung

🔧 Task 2 - Constants and variables


📈 23.3 Punkte
🔧 Programmierung

🔧 PYTHON-FUNDAMENTALS: CONSTANTS, VARIABLES AND DATA TYPES


📈 23.3 Punkte
🔧 Programmierung

🔧 What are Variables and Constants in Go? Explained With Examples


📈 23.3 Punkte
🔧 Programmierung

🕵️ An IDA Python script to extract information from string constants


📈 22.35 Punkte
🕵️ Reverse Engineering

🕵️ ActionApps constants.php3 GLOBALS[AA_INC_PATH] privilege escalation


📈 22.35 Punkte
🕵️ Sicherheitslücken

matomo