3 ms·
Show HN: 5-lines – submit your useful utils of 5 lines of code or less
- Jemaclus 9y agoInteresting idea, but I find this (https://github.com/dosyago-coder-0/5-lines/blob/master/javascript.js#L11 https://github.com/dosyago-coder-0/5-lines/blob/master/javas...) to be disingenuous, at best. That's a multiline function that has been minified. You can theoretically make any function a 1 line file if you minify it. I could buy a simple chain like this (https://github.com/dosyago-coder-0/5-lines/blob/master/javascript.js#L15 https://github.com/dosyago-coder-0/5-lines/blob/master/javas...) as a one-liner, but not the RNG. The seq() function is a little more impressive for being just "five" lines.
- projectant 9y agoHey there, Jemaclus! You are definitely welcome to submit a PR that includes the RNG as a multiline function. I'd merge it but I'd also keep the single line version. Why? Generally, I'll prefer code that can keep it's useful functionality within 5 lines, and this does. Is the line "too long"? Not to me. My rule of thumb is if it is more than the width of Github atom editor on a non-handheld screen then it's too long. On my laptop it's 132 chars, but fits. Maybe another way to say it is, 140 chars or less, but I haven't decided about that! And also, it's not disingenuous because, and this may be hard for you to believe but, I didn't actually write the rng as a multiline function then minify it. I'm good at writing RNGs, and I literally just wrote it on 1 line, tweaked in til it worked, and cut spaces. You can see history, here: https://gist.github.com/dosyago-coder-0/094497fdda0dbd7ef7f62e088543bd40/revisions https://gist.github.com/dosyago-coder-0/094497fdda0dbd7ef7f6... and the first change with the RNG is my first try, but it had some typos. The rng might look complex to you, but it's not. In my experience, it's a very simple generator, just looping endlessly over a state update function that uses xor, add and shift. I'm good at writing RNGs and I've had a lot of experience passing dieharder / practrand / smhasher etc. So it's easy for me to write an okay so-so "rng", in 1 line, like this. Impressive, right? To you, it seems like it had to have been / should be a multiline function. But to me, I'm fine to write it as a concise 1 liner, because I have more experience and aptitude at writing RNGs than you. That's all. And I want this repo to be about that. People shouldn't have to dumb down their own code so everyone can understand it at first glance or agree that they would write it in the same way. The files ought not be constrained by 1 style, but everyone is free to have their own contribution, within some limits. The main ones being: it works, and it's 5 lines. This is not "code golf", and we're not trying to obfuscate, just keep it in 5 lines. Ultimately, I'll be the judge of what's too complex or not, and I'll make a note on your PR if I reject it. Meant to be a celebration of diverse styles and thinking, in concise little packages. If you have some you feel are impressive, hit me up with a PR. I'd love to merge them in! Any language, py, java, whatever. Keep it coming :) My ultimate aim is to make this a useful resource, and maybe an object of curiosity. Something people can browse on a Sunday afternoon, not too taxing, but maybe a place you can discover / get inspiration for some interesting code in a tiny package. I think keeping them 5 lines or less makes it easier to digest, and maximises the chance you can actually get influenced by some new way of coding or thinking that someone else does -- or just find a useful util. Anyway, I thought it was fun to do last night at 3 am, so let's see what happens. You and everyone are welcome to join in. Don't be shy with your good utils!