What are Data Structures Data structures are a fundamental concept in computer science and refer to the way data is organised and stored in a computer’s memory or storage system. They are essential for efficient data manipulation, retrieval, and management in software development.
Ruby Blocks In Ruby, a block is an anonymous code block that can be passed as a parameter to a method or used with iterator methods. A block can be seen as a reusable piece of code that can be called and executed when needed.
Static and Dynamic languages Static and dynamic languages are two different ways of classifying programming languages. Here are their representatives and respective advantages and disadvantages:
Representatives of static languages: Java, C++, C# Static languages require variables, functions, and objects to have their type determined at compile time, and perform type checks on these types at runtime.
The main difference between TypeScript and JavaScript is that TypeScript is a static type language, while JavaScript is a dynamic type language.
Specifically, TypeScript has the following features:
Type annotations: TypeScript allows type annotations to be added to variables, parameters, functions, objects, etc.
Example 1 (SRP) Single Responsibility Principle (SRP):單一職責原則
The Single Responsibility Principle (SRP) suggests that each class or module should have only one responsibility. Here’s an example:
SRP 建議每個類別或模組應該只負責單一的職責。以下是一個範例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # 不符合 SRP 的範例 class Customer def initialize(name, email, phone) @name = name @email = email @phone = phone end def save_to_db # 保存顧客信息到數據庫 end def send_email # 發送電子郵件給顧客 end end The above code violates SRP because the Customer class has two responsibilities - saving customer information to the database and sending an email to the customer.