General Flashcards
(32 cards)
What is Test-Driven Development (TDD)?
TDD is a software development process where tests are written before the actual code. Developers write failing tests first, then write the minimum amount of code necessary to pass the tests, and finally refactor the code to improve its design without changing its behavior.
Explain the SOLID principles in software engineering.
Single Responsibility Principle (SRP)
Open/Closed Principle (OCP)
Liskov Substitution Principle (LSP)
Interface Segregation Principle (ISP)
Dependency Inversion Principle (DIP)
What is the Single Responsibility Principle (SRP)?
SRP states that a class should have only one reason to change, meaning it should only have one responsibility or encapsulate one aspect of the software’s functionality.
Can you explain the Open/Closed Principle (OCP)?
OCP states that software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. This means that the behavior of a module can be extended without modifying its source code.
Describe the Liskov Substitution Principle (LSP).
LSP states that objects of a superclass should be replaceable with objects of its subclass without affecting the correctness of the program. In other words, derived classes must be substitutable for their base classes.
What does the Interface Segregation Principle (ISP) advocate for?
ISP suggests that clients should not be forced to depend on interfaces they don’t use. It promotes the idea of segregating interfaces into smaller and more specific ones.
Explain the Dependency Inversion Principle (DIP).
DIP states that high-level modules should not depend on low-level modules, but both should depend on abstractions. It promotes loose coupling between software modules by ensuring that high-level modules are not directly dependent on the implementations of low-level modules.
What are some advantages of using Python over other programming languages for scripting tasks?
Python offers simplicity, readability, extensive standard libraries, cross-platform compatibility, and a vast ecosystem of third-party packages.
what is virtualenv in Python, and why would you use it?
virtualenv is a tool used to create isolated Python environments. It allows you to install Python packages into an environment without affecting the system-wide Python installation, making it useful for managing dependencies in projects.
How do you check the syntax of a Bash script without executing it?
You can check the syntax of a Bash script using the bash -n command followed by the script’s filename, like this: bash -n script.sh.
What is the purpose of the shebang (#!) line in a Bash script?
The shebang line specifies the interpreter that should be used to execute the script. For example, #!/bin/bash indicates that the script should be run using the Bash interpreter.
Question: How can you pass arguments to a Bash script?
You can pass arguments to a Bash script by specifying them after the script’s filename when executing it, like this: ./script.sh arg1 arg2.
What is the purpose of the chmod command in Bash?
The chmod command is used to change the permissions of files and directories in Unix-like operating systems. It allows you to specify who can read, write, and execute a file or directory.
Explain the difference between grep, sed, and awk in Bash.
grep is used to search for patterns in text files, sed is used to perform text transformations on files, and awk is a versatile text-processing tool for extracting and manipulating data.
how can you redirect the output of a command to a file in Bash?
You can redirect the output of a command to a file using the > operator, like this: command > output.txt.
How do you debug a Bash script?
You can debug a Bash script by using the set -x command to enable debugging mode, which prints each command before executing it. Additionally, you can use echo statements to print variable values and intermediate results for troubleshooting purposes.
What is Object-Oriented Programming (OOP), and what are its core principles?
OOP is a programming paradigm based on the concept of “objects,” which can contain data and code. Its core principles include encapsulation, inheritance, and polymorphism.
Explain the concept of encapsulation in OOP.
Encapsulation is the bundling of data and methods that operate on the data into a single unit, known as a class. It hides the internal state of an object from the outside world and only exposes the necessary functionality through methods.
What is inheritance in OOP, and how does it facilitate code reuse?
Inheritance is a mechanism where a new class inherits properties and behaviors from an existing class. It allows for the creation of a hierarchy of classes, with derived classes inheriting attributes and methods from their base classes, facilitating code reuse and promoting the DRY (Don’t Repeat Yourself) principle.
Describe the difference between composition and inheritance.
Composition involves creating objects that contain other objects as attributes, while inheritance involves creating a hierarchy of classes where subclasses inherit properties and behaviors from superclasses. Composition typically favors “has-a” relationships, whereas inheritance favors “is-a” relationships.
What is polymorphism in OOP, and how does it enhance code flexibility?
Polymorphism allows objects of different classes to be treated as objects of a common superclass. It enables code to work with objects of various types through a uniform interface, promoting flexibility and extensibility.
What are abstract classes and interfaces, and how do they differ?
Abstract classes are classes that cannot be instantiated and may contain one or more abstract methods, while interfaces are collections of method signatures without implementations. Abstract classes can have both abstract and concrete methods, whereas interfaces only define method signatures.
What is method overriding, and how does it relate to inheritance?
Method overriding occurs when a subclass provides a specific implementation for a method that is already defined in its superclass. It allows subclasses to customize the behavior of inherited methods to suit their specific needs.
What is the DRY (Don’t Repeat Yourself) principle, and why is it important?
The DRY principle advocates for avoiding duplication of code by ensuring that each piece of knowledge in a system is represented in a single, unambiguous way. It promotes code reuse, reduces maintenance overhead, and improves code readability and consistency.