1.
A Package is __________.
Correct Answer
A. A higher level of modular granularity than a Class
Explanation
A package is a higher level of modular granularity than a class. In object-oriented programming, a package is a way to organize and group related classes and interfaces. It provides a higher level of abstraction and encapsulation compared to a class. A package can contain multiple classes and can be used to organize and manage the dependencies between classes. It helps in maintaining code reusability, readability, and manageability by grouping related components together. Therefore, a package is considered to have a higher level of modular granularity than a class.
2.
Containment is the __________ relationship.
Correct Answer
B. has a
Explanation
The correct answer is "has a". In object-oriented programming, the "has a" relationship refers to a class having an instance of another class as one of its member variables. It represents a composition or aggregation relationship where the containing class has a reference to the contained class. This allows the containing class to access and use the functionality and properties of the contained class.
3.
Encapsulation is __________.
Correct Answer
D. The enforcer that prevents you from looking at the details even if you want to
Explanation
Encapsulation is the enforcer that prevents you from looking at the details even if you want to. This means that encapsulation hides the internal implementation details of an object, allowing you to interact with it through a well-defined interface. It promotes information hiding and abstraction, protecting the internal state and implementation of an object from being accessed or modified directly. This enhances security, maintainability, and flexibility in software development.
4.
How long should a routine be?
Correct Answer
C. Less than 200 lines
Explanation
The correct answer is "Less than 200 lines" because routines should be concise and focused. Having a routine that exceeds 200 lines can make it difficult to understand and maintain. By keeping routines shorter, it becomes easier to read, debug, and modify the code. It also promotes better code organization and improves code reusability.
5.
One of the strongest mental blocks to creating effective routines is a reluctance to create a simple routine for a simple purpose. Which of the following is the best reason why a good small routine can be helpful?
Correct Answer
D. To improve readability
Explanation
A good small routine can be helpful to improve readability. By breaking down a complex task into smaller, more manageable steps, it becomes easier for others (and even ourselves) to understand and follow the logic of the code. This improves the overall clarity and maintainability of the codebase. Additionally, smaller routines can be reused in different parts of the program, promoting code reusability and reducing redundancy. However, the given options do not mention code reusability or reducing the overall size of code as reasons for the helpfulness of a good small routine.
6.
The MAIN advantage of having small routines is __________?
Correct Answer
D. it improves readability
Explanation
Having small routines improves readability because it allows for easier understanding and comprehension of the code. When routines are small, they are easier to follow and analyze, making it simpler to identify and fix any issues or bugs. Additionally, small routines promote modularity and reusability, as they can be easily combined and utilized in different parts of the codebase. This ultimately leads to more maintainable and scalable code, enhancing the overall readability and understandability of the program.
7.
The best use of Assertions is __________.
Correct Answer
C. documenting assumptions made in the code
Explanation
Assertions are best used for documenting assumptions made in the code. Assertions help in clarifying the intentions and assumptions of the code, making it easier for other developers to understand and maintain the code. By documenting these assumptions, it becomes clear what conditions are expected to be true at certain points in the code. This can help in debugging and identifying potential issues. Assertions also serve as a form of self-documentation, making the code more readable and maintainable.
8.
How can you program 'offensively'?
Correct Answer
B. Introduce debugging aids early
Explanation
Introducing debugging aids early in the programming process allows for the identification and resolution of any potential issues or errors before the production code is running. This proactive approach helps to minimize the occurrence of exceptional cases during development and ensures that they can be easily identified and resolved. By addressing these cases early on, the code can be optimized to avoid them during production, resulting in a more efficient and reliable program.
9.
How should you handle errors that you expect to occur?
Correct Answer
D. Throw (raise) exceptions
Explanation
When handling errors that are expected to occur, it is recommended to throw (raise) exceptions. By throwing exceptions, we can provide a clear indication that an error has occurred and allow the program to handle the error appropriately. This approach helps in maintaining the code's integrity and makes it easier to debug and fix issues. Ignoring errors may lead to unexpected behavior and make it difficult to identify and resolve problems. Using assertions can be useful for checking assumptions during development, but they are not suitable for handling expected errors in production code. Substituting valid values may not accurately represent the error and can lead to incorrect results.
10.
A recommended alternative or supplement to the Pseudocode Programming Process is __________.
Correct Answer
B. Test-first development
Explanation
Test-first development is a recommended alternative or supplement to the Pseudocode Programming Process. Test-first development is an approach where developers write tests for a piece of functionality before writing the actual code. This ensures that the code meets the desired requirements and helps in identifying any potential issues early in the development process. It promotes better code quality, improved design, and faster development cycles.
11.
If following the Pseudocode Programming Process, coding should be done __________.
Correct Answer
A. After checking the design (for example with a desk checks)
Explanation
The coding should be done after checking the design, for example with a desk check. This ensures that any errors or issues in the design are identified and resolved before the code is written. By reviewing the design first, it allows for a more efficient and effective coding process, reducing the likelihood of errors and improving the overall quality of the code.
12.
Creation of __________ routines benefits most from a systematic approach like the Pseudocode Programming Process.
Correct Answer
A. Complicated
Explanation
The creation of complicated routines benefits most from a systematic approach like the Pseudocode Programming Process. This is because complicated routines involve complex logic and require careful planning and organization. Pseudocode allows programmers to break down the complicated routine into smaller, more manageable steps, making it easier to understand and implement. By following a systematic approach like the Pseudocode Programming Process, programmers can ensure that the complicated routine is developed correctly and efficiently.
13.
A valid guideline which avoids initialisation problems (in programing languages Jade and VB languages which do not allow initialising variables as they are declared) is to __________.
Correct Answer
B. initialize each variable close to where it is first used
Explanation
In programming languages like Jade and VB, where variables cannot be initialized as they are declared, a valid guideline to avoid initialization problems is to initialize each variable close to where it is first used. This ensures that the variable is initialized before it is accessed or manipulated, reducing the chances of encountering errors or unexpected behavior. By initializing variables close to their first usage, it promotes code readability and helps in identifying the purpose and scope of each variable more easily.
14.
In choosing between the convenience and intellectual manageability programming philosophies the choice should be __________.
Correct Answer
D. intellectual manageability as it simplifies the reading of programs
Explanation
The correct answer is "intellectual manageability as it simplifies the reading of programs". This choice suggests that prioritizing intellectual manageability, or making the code easier to understand and read, is more important than convenience in speeding up the writing of programs. By prioritizing intellectual manageability, it becomes easier for different people to write code in a consistent and understandable way, leading to better collaboration and maintainability of the codebase.
15.
The code between references to a variable is a window of vulnerability because __________.
Correct Answer
C. New code might be added, inadvertently altering the variable
Explanation
The code between references to a variable is a window of vulnerability because new code might be added, inadvertently altering the variable. This means that if new code is added within the section of code where the variable is referenced, it could unintentionally modify the value of the variable. This can lead to unexpected behavior and potential bugs in the program. It is important to be cautious when making changes within this window of vulnerability to ensure that the variable is not inadvertently altered.