I'm creating a new workshopper on Workshopper 2.3.1. In creating my first exercise I came across the solution dir. I'm using learnyounode for examples so I checked what was in these directories.
$ ls */solution
baby_steps/solution:
solution.js
filtered_ls/solution:
solution.js
hello_world/solution:
solution.js
http_client/solution:
solution.js
http_collect/solution:
solution.js
http_file_server/solution:
solution.js
http_json_api_server/solution:
solution.js
http_uppercaserer/solution:
solution.js
juggling_async/solution:
solution.js
make_it_modular/solution:
solution.js solution_filter.js
my_first_async_io/solution:
solution.js
my_first_io/solution:
solution.js
time_server/solution:
solution.js
It didn't seem to be that there was much in these dirs besides a solution.js.
I checked to find out what was going on & saw that it's for translated solution files. This confused me because I wondered what would need translating in a solution file. I found some translated solutions in my_first_io & took a look:
==> solution/solution.js <==
var fs = require('fs')
var contents = fs.readFileSync(process.argv[2])
var lines = contents.toString().split('\n').length - 1
console.log(lines)
// note you can avoid the .toString() by passing 'utf8' as the
// second argument to readFileSync, then you'll get a String!
//
// fs.readFileSync(process.argv[2], 'utf8').split('\n').length - 1
==> solution_fr/solution.js <==
var fs = require('fs')
var contents = fs.readFileSync(process.argv[2])
var lines = contents.toString().split('\n').length - 1
console.log(lines)
// remarquez que vous pouvez éviter d’avoir à appeler `.toString()`
// en précisant un encodage 'utf8' comme second argument pour
// `readFileSync`, ce qui vous renverrait une `String` !
//
// fs.readFileSync(process.argv[2], 'utf8').split('\n').length - 1
==> solution_ja/solution.js <==
var fs = require('fs')
var contents = fs.readFileSync(process.argv[2])
var lines = contents.toString().split('\n').length - 1
console.log(lines)
// 注:'readFileSync' の二つ目の引数に 'utf8' を渡すと、
// '.toString' を使わずに文字列を受け取ることが出来ます!
// fs.readFileSync(process.argv[2], 'utf8').split('\n').length - 1
The only thing translated seems to be... the comments? 😕
I looked further to see if I could find the exercise that needed to have translated versions of the solution.
==> solution/solution.js <==
console.log("HELLO WORLD")
==> solution_fr/solution.js <==
console.log("Bonjour, Monde");
==> solution_ja/solution.js <==
❓ ❔ ❓ There's an i18n framework in place for this.
My Point
I believe that the "translated solutions" is a 👎 bad idea. Here's why:
- In introduces a ton of unneeded maintenance work. Each solution must now be maintained separately for every language supported. If someone submits a patch against an
en solution file, do you hold the PR & tell them to go update all 7 or however many translation files?
- It introduces a big entrance for bugs. What if the
en solution is patched & the others are overlooked because maintainer only speaks en? Now the solution behavior has diverged by language.
- It makes the translator's job way more complicated. Say I patch a solution & add a comment in English, now in addition to
lang.json & problem_lang.md, the translators need to comb thru every exercise looking for untranslated/updated comments? 😦
- I can't imagine the scenario where a solution should need to be different by language. I'm sure someone could be contrived but do they exist in the wild? I strongly suspect that if you need different solutions per language you are probably doing something wrong. If this corner-case should occur, is there any reason the author can't handle it (switch on languages) in the
solution.js?
- Regarding comments:
solution.js is not the place to put exercise hints! How would the average nodeschooler even know to look here? If // note you can avoid the .toString() by passing 'utf8' as the second argument to readFileSync, then you'll get a String! is important for people to read, put it in the problem.md where people can find it.
❓ What problem is this feature solving?
Proposal
Load exercises/my_foo/solution.js & call it a day. I will try to submit a PR given the green light.
Why I even care about this
Because I'm authoring a workshopper & it's bothersome to me, but more importantly, stuff like this needlessly makes it more difficult & complex to create a workshopper! The new workshopper & workshopper-excercise APIs have introduced a lot of complexity & I am arguing for the potential author who just wants to make a new workshopper easily.
I'm creating a new workshopper on Workshopper 2.3.1. In creating my first exercise I came across the
solutiondir. I'm usinglearnyounodefor examples so I checked what was in these directories.It didn't seem to be that there was much in these dirs besides a solution.js.
I checked to find out what was going on & saw that it's for translated solution files. This confused me because I wondered what would need translating in a solution file. I found some translated solutions in
my_first_io& took a look:==> solution/solution.js <====> solution_fr/solution.js <====> solution_ja/solution.js <==The only thing translated seems to be... the comments? 😕
I looked further to see if I could find the exercise that needed to have translated versions of the solution.
==> solution/solution.js <====> solution_fr/solution.js <====> solution_ja/solution.js <==❓ ❔ ❓ There's an i18n framework in place for this.
My Point
I believe that the "translated solutions" is a 👎 bad idea. Here's why:
ensolution file, do you hold the PR & tell them to go update all 7 or however many translation files?ensolution is patched & the others are overlooked because maintainer only speaksen? Now the solution behavior has diverged by language.lang.json&problem_lang.md, the translators need to comb thru every exercise looking for untranslated/updated comments? 😦solution.js?solution.jsis not the place to put exercise hints! How would the average nodeschooler even know to look here? If// note you can avoid the .toString() by passing 'utf8' as the second argument to readFileSync, then you'll get a String!is important for people to read, put it in theproblem.mdwhere people can find it.❓ What problem is this feature solving?
Proposal
Load
exercises/my_foo/solution.js& call it a day. I will try to submit a PR given the green light.Why I even care about this
Because I'm authoring a workshopper & it's bothersome to me, but more importantly, stuff like this needlessly makes it more difficult & complex to create a workshopper! The new workshopper & workshopper-excercise APIs have introduced a lot of complexity & I am arguing for the potential author who just wants to make a new workshopper easily.