OLD | NEW |
| (Empty) |
1 Jeremy started by sketching out the desired user experience for a file chooser, | |
2 which I thought was great. Many other candidates do not start here, they often | |
3 jump right into code. I liked that Jeremy tried to get a larger view of the | |
4 problem before diving into design. He drew a picture of the file chooser panel | |
5 on the whiteboard - it had a n area for displaying files and directories, a text | |
6 field for typing in a file name, an Open button, and a combo box for filtering. | |
7 Jeremy then started enumerating the methods in his class, and came up with this | |
8 pseudo-code: | |
9 | |
10 class FileChooser { | |
11 SetCurrentDir(str dir); // Sets the root directory for the chooser. | |
12 SetFilterPatterns(vector<str> regexs); | |
13 ConvertToAbsURL(str path); // Convert the selected file path to a URL that | |
14 can be opened by other API. | |
15 vector<str> GetFiles(); // Enumerate all the files in the root dir | |
16 vector<str> GetDirs(); // Enumerate all the dirs under the root dir. | |
17 }; | |
18 | |
19 While Jeremy was talking about the synchronous GetFiles() method, he realized | |
20 the JavaScript programs are usually very asynchronous and event-driven, and so | |
21 he added this methods: | |
22 AsyncGetFiles(js_closure); // js_closure is a JS function object that takes | |
23 two parameters: (name, is_dir). | |
24 | |
25 The closure (or event handler) is called for each file or dir under the root | |
26 dir. | |
27 | |
28 Jeremy then thought about the case where you type in a filename, and it requires | |
29 validating, so he added: | |
30 ValidateUserFile(str path); // returns an enum indicating one of four states: | |
31 exists & is_file, exists & is_dir, does not exist, cannot exist (this last state | |
32 means there is an invalid dir in the path). | |
33 | |
34 He then thought about autocomplete, and added: | |
35 GetAsyncAutoComplete(str partial_path, js_closure); // The closure is called | |
36 with an array of possible filenames. | |
37 | |
38 He made the good observation that all the GUI element handling (popping up the | |
39 combo box, highlight, etc. of the Open button, getting text from the text field) | |
40 would be done in the JavaScript. | |
41 | |
42 He through we could remove the synchronous API, which I thought was a good | |
43 observation. | |
44 | |
45 His final API: | |
46 | |
47 class FileChooser { | |
48 SetCurrentDir(str dir); // Sets the root directory for the chooser. | |
49 SetFilterPatterns(vector<str> regexs); | |
50 ConvertToAbsURL(str path); // Convert the selected file path to a URL that | |
51 can be opened by other API. | |
52 AsyncGetFiles(JSObject closure); // Enumerate all the files and dirs in the | |
53 root dir, call the closure with each file. | |
54 ValidateUserFile(str path); // returns an enum indicating one of four states: | |
55 exists & is_file, exists & is_dir, does not exist, cannot exist (this last state | |
56 means there is an invalid dir in the path). | |
57 GetAsyncAutoComplete(str partial_path, js_closure); // The closure is called | |
58 with an array of possible filenames. | |
59 }; | |
60 | |
61 | |
62 He was asked, What if there are 1,000,000 files? He responded, Have the | |
63 AsyncGetFiles() method respond to a bool from the JS closure and stop when the | |
64 bool is false, or have another API which stops the file enumeration. | |
65 AsyncGetFiles() would pass a third parameter to the JS indicating that all the | |
66 files have been enumerated (is_done). | |
67 | |
68 He was asked, What is the first dir? He responded that we could use a default, | |
69 and that that default could come from a list of Special Dirs (e.g. the user's | |
70 documents dir), or it could be the last visited dir. He suggested adding API to | |
71 get the list of special dirs, and have that API return a dictionary that can be | |
72 extended across versions. | |
73 | |
74 He was asked about testing. He responded that he would unit test the JavaScript | |
75 to know that the end-to-end process worked. He said he would either have a FS | |
76 populated with known files, or (better) mock the file system that this class | |
77 talked to. I thought this was a fantastic answer. | |
78 | |
79 Score: 3.8 (relative to other candidates, Jeremy basically hit this one out of | |
80 the park). | |
OLD | NEW |