B.S.W.E. Bachelor of Software Engineering Practice 2 — Questions and Answers
Question 1: Which refactoring technique replaces a temporary variable with a direct call to the expression that assigned it?
- Extract Method
- Inline Temp (Correct answer)
- Replace Magic Number
- Introduce Explaining Variable
Correct answer: Inline Temp
Inline Temp removes a temporary variable by substituting its value expression directly wherever the variable is used.
Question 2: In test-driven development (TDD), what is the correct sequence of steps?
- Write code → Write test → Refactor
- Write test → Make it pass → Refactor (Correct answer)
- Refactor → Write test → Write code
- Write test → Refactor → Make it pass
Correct answer: Write test → Make it pass → Refactor
TDD follows the Red-Green-Refactor cycle: write a failing test, write minimal code to pass it, then refactor.
Question 3: Which version control strategy involves developers integrating code changes into a shared branch multiple times per day?
- Feature branching
- GitFlow
- Continuous Integration (Correct answer)
- Trunk-based development
Correct answer: Continuous Integration
Continuous Integration requires developers to merge code frequently (at least daily) and run automated builds and tests on each integration.
Question 4: A code review reveals a function is 300 lines long and performs database access, business logic, and UI formatting. Which principle is violated?
- Open/Closed Principle
- Single Responsibility Principle (Correct answer)
- Liskov Substitution Principle
- Interface Segregation Principle
Correct answer: Single Responsibility Principle
The Single Responsibility Principle states a class or function should have only one reason to change, but this function handles three distinct concerns.
Question 5: What does a cyclomatic complexity value of 15 in a single method indicate?
- The method has 15 lines of code
- The method has 15 independent paths requiring test coverage (Correct answer)
- The method calls 15 other methods
- The method has 15 parameters
Correct answer: The method has 15 independent paths requiring test coverage
Cyclomatic complexity counts the number of linearly independent paths through code, indicating the minimum number of test cases needed for branch coverage.
Question 6: Which practice involves automatically deploying every code change that passes all automated tests directly to production?
- Continuous Delivery
- Continuous Deployment (Correct answer)
- Continuous Integration
- Blue-Green Deployment
Correct answer: Continuous Deployment
Continuous Deployment automatically releases every passing build to production without human intervention, while Continuous Delivery still requires a manual approval step.
Question 7: When using pair programming, what is the role of the 'navigator'?
- Types the code while the other person watches
- Reviews the code being typed and thinks about design and direction (Correct answer)
- Runs the tests after each code change
- Writes documentation for the code being produced
Correct answer: Reviews the code being typed and thinks about design and direction
In pair programming the navigator reviews code in real time, thinks about the broader design, spots errors, and guides the driver who types.
Which refactoring technique replaces a temporary variable with a direct call to the expression that assigned it?