· 9 years ago · Nov 19, 2016, 03:46 PM
1Question #1: What does this code do?
2
3The code defines a method that computes a charge for some product based on whether the season is summer or not summer (winter).
4Note: the code only checks the date of the charge against the start and end of summer. A date outside this range is charged
5a winter rate; a date within the range is charged a summer rate.
6
7Question #2
8
9How would you refactor this code? Please include your refactored code and a brief written explanation of your changes.
10
11Refactored Code:
12
13class UtilService
14 @@summer_start = ...
15 @@summer_end = ...
16 @@winter_rate = ...
17 @@winter_service_charge = ...
18 @@summer_rate = ...
19
20
21
22 def calc(date, quantity)
23 if date < @@summer_start || date > @@summer_end
24 chargeamt = quantity * @@winter_rate + @@winter_service_charge
25 else
26 chargeamt = quantity * @@summer_rate
27 end
28 chargeamt
29 end
30end
31
32
33The code has been refactored to reflect the fact that start and end of summer (summer_start, summer_end) are relatively invariant
34values that can be encoded as class properties that are constants. Similarly, winter_rate and winter_service_charge are likely
35to be relatively invariant and are encoded similarly to summer properties. In keeping with this representation, it is not
36necessary to pass these properties as parameters to the calc method. Further, there was a parameter "charge" in the original
37code that was not used and has been removed.
38
39Note: I haven't written Ruby code in 8 years; took me awhile to remember it...
40
41
42Question #3
43
44At Bloc, we have students who enroll into one of several programs (Web Developer Track, Software Developer Track, and
45Designer Track). Our programs are provisioned by supplying each student with a mentor, whom they choose on their start date (which is not necessarily the same as their enroll date).
46
47How would you go about modelling these requirements in a SQL database? Please include as much detailed information as possible.
48
49Here's the SQL for the table. I couldn't get the model picture in here. The assumption is that the database is mydb and this is
50a MySQL database.
51
52SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
53SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
54SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
55
56CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
57USE `mydb` ;
58
59-- -----------------------------------------------------
60-- Table `mydb`.`country_code`
61-- -----------------------------------------------------
62DROP TABLE IF EXISTS `mydb`.`country_code` ;
63
64CREATE TABLE IF NOT EXISTS `mydb`.`country_code` (
65 `country_code_id` INT NOT NULL ,
66 `country_name` VARCHAR(45) NOT NULL )
67ENGINE = InnoDB;
68
69
70-- -----------------------------------------------------
71-- Table `mydb`.`contact_information`
72-- -----------------------------------------------------
73DROP TABLE IF EXISTS `mydb`.`contact_information` ;
74
75CREATE TABLE IF NOT EXISTS `mydb`.`contact_information` (
76 `id` INT NOT NULL AUTO_INCREMENT ,
77 `address_line_1` VARCHAR(45) NOT NULL ,
78 `address_line_2` VARCHAR(45) NULL ,
79 `city` VARCHAR(45) NOT NULL ,
80 `state` VARCHAR(45) NOT NULL ,
81 PRIMARY KEY (`id`) ,
82 CONSTRAINT `country_code`
83 FOREIGN KEY ()
84 REFERENCES `mydb`.`country_code` ()
85 ON DELETE NO ACTION
86 ON UPDATE NO ACTION)
87ENGINE = InnoDB;
88
89
90-- -----------------------------------------------------
91-- Table `mydb`.`person`
92-- -----------------------------------------------------
93DROP TABLE IF EXISTS `mydb`.`person` ;
94
95CREATE TABLE IF NOT EXISTS `mydb`.`person` (
96 `id` INT NOT NULL ,
97 `first_name` VARCHAR(45) NOT NULL ,
98 `middle_name` VARCHAR(45) NULL ,
99 `last_name` VARCHAR(100) NOT NULL ,
100 `is_mentor` BINARY NULL ,
101 `is_student` BINARY NULL ,
102 `contact_information_id` INT NOT NULL ,
103 PRIMARY KEY (`id`, `contact_information_id`) ,
104 INDEX `fk_person_contact_information1_idx` (`contact_information_id` ASC) ,
105 CONSTRAINT `fk_person_contact_information1`
106 FOREIGN KEY (`contact_information_id` )
107 REFERENCES `mydb`.`contact_information` (`id` )
108 ON DELETE NO ACTION
109 ON UPDATE NO ACTION)
110ENGINE = InnoDB;
111
112
113-- -----------------------------------------------------
114-- Table `mydb`.`mentor`
115-- -----------------------------------------------------
116DROP TABLE IF EXISTS `mydb`.`mentor` ;
117
118CREATE TABLE IF NOT EXISTS `mydb`.`mentor` (
119 `mentor_id` INT NOT NULL ,
120 `is_active` BINARY NOT NULL DEFAULT true ,
121 PRIMARY KEY (`mentor_id`) ,
122 CONSTRAINT `fk_mentor_id`
123 FOREIGN KEY (`mentor_id` )
124 REFERENCES `mydb`.`person` (`id` )
125 ON DELETE NO ACTION
126 ON UPDATE NO ACTION)
127ENGINE = InnoDB;
128
129
130-- -----------------------------------------------------
131-- Table `mydb`.`program_track`
132-- -----------------------------------------------------
133DROP TABLE IF EXISTS `mydb`.`program_track` ;
134
135CREATE TABLE IF NOT EXISTS `mydb`.`program_track` (
136 `program_track_id` INT NOT NULL ,
137 `program_name` VARCHAR(45) NOT NULL ,
138 `program_description` VARCHAR(45) NOT NULL ,
139 PRIMARY KEY (`program_track_id`) )
140ENGINE = InnoDB;
141
142
143-- -----------------------------------------------------
144-- Table `mydb`.`student`
145-- -----------------------------------------------------
146DROP TABLE IF EXISTS `mydb`.`student` ;
147
148CREATE TABLE IF NOT EXISTS `mydb`.`student` (
149 `student_id` INT NOT NULL ,
150 `enrollment_date` DATE NOT NULL ,
151 `start_date` DATE NULL ,
152 `enrollment_current` BINARY NULL ,
153 `program_track_program_track_id` INT NULL ,
154 `mentor_id` INT NULL ,
155 `student_program_track_program_track_id` INT NOT NULL ,
156 PRIMARY KEY (`student_id`, `program_track_program_track_id`) ,
157 INDEX `fk_mentor_id_idx` (`mentor_id` ASC) ,
158 INDEX `fk_student_id_idx` (`student_id` ASC) ,
159 CONSTRAINT `fk_student_program_track1`
160 FOREIGN KEY (`program_track_program_track_id` )
161 REFERENCES `mydb`.`program_track` (`program_track_id` )
162 ON DELETE NO ACTION
163 ON UPDATE NO ACTION,
164 CONSTRAINT `fk_mentor_id`
165 FOREIGN KEY (`mentor_id` )
166 REFERENCES `mydb`.`mentor` (`mentor_id` )
167 ON DELETE NO ACTION
168 ON UPDATE NO ACTION,
169 CONSTRAINT `fk_student_id`
170 FOREIGN KEY (`student_id` )
171 REFERENCES `mydb`.`person` (`id` )
172 ON DELETE NO ACTION
173 ON UPDATE NO ACTION)
174ENGINE = InnoDB;
175
176USE `mydb` ;
177
178
179SET SQL_MODE=@OLD_SQL_MODE;
180SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
181SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
182
183
184Requirements for the exercise were sketchy, so many requirements described here are derived.
185
1861. Person table contains information on student/mentor. There is a single identifier for a student/mentor
187 which is the primary key in the Person table. Identifier is a derived requirement.
1882. Person information includes first name, last name, middle name, a flag indicating if the
189 person is a student or a mentor (can be both) Note: this is a derived requirement.
1903. Each person has contact information which is recorded in the contact_information table. A
191 foreign key reference to contact_information is part of Person. The person to contact_information
192 is a one-to-one relationship. Derived requirement
1934. Contact information includes address, city, state, nation, and postal code.
1945. Nation is a limited value (for data integrity and efficiency) that is recorded in a code table. Assumption: when the user
195 enters the nation, the nation will be validated against the code table or the code table will be used to
196 prompt the user's choice. Derived requirement
1976. Student information is recorded in the student table. This includes student_id (a foriegn key into the
198 person table) enrollment_date, start_date (both from requirements), enrollment_current (derived: assuming students
199 may not be active), mentor_id (a foreighn key to the mentor table, nullable because the mentor may not yet be assigned).
2007. The student table has a one=to-one relationship to a code table containing the program track information for the
201 student's enrollment
2028. Mentor information is recorded in the mentor table. This consists of an id (foriegn key to person table) and a
203 binary value indicating if the mentor is active (a derived requirement)
204 There is a many to one relationship between mentor and student, but a mentor may have no students assigned.
205
206
207
208Question #4
209What does it mean to you to be a good software engineer?
210
211This is an open-ended question, so I will answer with what I think are some of the attributes and behaviors of
212a good software engineer.
213
214Attributes
215
2161. Detail-oriented, but able to comprehend the greater picture of where her code fits into an overall architecture.
2172. Able to understand and communicate the cost/benefit trade-offs between various approaches to a problem solution;
218 for example, where a piece of code has a strict time performance requirement such that a more complex implementation
219 may be warraned, against where performance is not (so much) of an issue and a simpler approach is clearer.
2203. Conversant with good software engineering practices, e.g., encapsulation, single responsibility principal, etc.
2214. Actively engaged in expanding her capabilities and keeping up with emerging practices in the field.
222
223Behaviors
224
2251. Able to model abstractly the code which she is to write or the code which she is analyzing so as to identify the
226 essential components and understand their interaction.
2272. Able to implement a solution that meets all explicit and derived requirements.
2283. Able to create the unit tests that demonstrate requirement satisfaction.
2294. Fast and efficient developer, able to meet deadlines and identify where deadlines are inaccurately reflexive of the
230 task.
231
232
233Obviously, there are a lot more attributes and behaviors. These are just a few I look for.
234
235
236Question #5
237Are you currently authorized to work in the United States?
238
239Question #6:
240This is an in-person position (not remote). Do you currently live in, or open to relocating to the San Francisco Bay Area?
241
242No
243Question #7
244
245Please rate your English language fluency:
246
247I am not fluent in English
248I am somewhat fluent in English
249I am fluent in English
250
251I am very, very fluent in English!