1. 2

    I’m going to try and make general tsaos chicken.

    1. 10

      I’m not sure most people really think that “you don’t need comments if your code is self-documenting”, but rather think that “you don’t need many comments if your code is self-documenting”. There is a subtle – yet important – difference!

      So if you’re looking for self-documenting code without any comments at all, then yeah, you might not find it.

      I’m firmly in the “self-documenting” camp, but I often add a single line comment above a function to describe what it does in plain English. I also prefer to group things with comments, especially in slightly longer comments.

      But stuff like f = getFoo() // get a foo object from the database? Yeah nah.

      1. 3

        Indeed, excessively self documenting functions lead to 27 word function names. I do like the kind of comments that show up when I hover over a function in particular however.

        1. 8

          Names are about “What” comments are about “Why”.

          1. 3

            This one. You can encode logic, but not motivation.

      1. 3

        as soon as I read “in this article chris…” I knew it would be Chris Ford. I’ve loved everything I’ve ever seen from him, most specifically this talk and some other one I can’t seem to find right now.

        1. 3

          I dump my files into /var/www/html/ for Apache and that’s the end of it. I write all of the HTML, SVG, and whatnot by hand and when I want to add a new article I copy the HEAD and all of that from a previous article. Then, I add the article to index.html and that’s the end of it.

          There is one question I have, however. I’ve recently wanted to add the ability to comment on my website and the current mechanism is sending me an email, as explained here, but this seems a high enough barrier that I’ll receive very few, as I’ve received none so far. I figured it would be sufficient to add a form to that page, but I don’t know how to attach an arbitrary program to a form. As I’ll be doing this all manually, it would even be enough to simply have Apache log the POST requests sent to a certain URL, but every option I’ve come across so far requires me to either install something or perform some heavy configuration, both of which I’m reluctant to do.

          I suppose I could tell it to vomit the POST to a port I have listening, but surely there’s a better way, right?

          1. 3

            This is actually a great use case for php. Since you already have Apache set up, you would use it with mod_php and direct the post request to a php controller. From there you can do whatever you want in process, probably the simplest thing would just have the server itself email you and then optionally log the data or action somewhere. So no messing around with sockets or other processes on the host side or spinning up and managing arbitrary interpreters as the module handles those details.

            1. 1

              You can also write cgi modules for python and your favorite language, though php is basically made for this. So you have choices that can also lead to “easy to write scripts for single endpoints”

            2. 2

              This is close to the sort of thing I’m talking about. Static assets are easy - but what do you do when you just want to add a small dynamic part, like a contact form? A full “web app” with the accompanying sysadmin headaches just seems like massive overkill.

              1. 2

                Couldn’t you just use some plain JavaScript via XMLHttp​Request?

                POST Example

                var xhr = new XMLHttpRequest();
                xhr.open("POST", '/server', true);
                
                //Send the proper header information along with the request
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                
                xhr.onreadystatechange = function() { // Call a function when the state changes.
                    if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
                        // Request finished. Do processing here.
                    }
                }
                xhr.send("foo=bar&lorem=ipsum");
                // xhr.send(new Int8Array()); 
                // xhr.send(document);
                
                1. 2

                  I don’t know JavaScript and I don’t know PHP. I want to avoid adding something to Apache and if I were to use any JavaScript, then it wouldn’t work in Links, Lynx, w3m, Dillo, or Netsurf; it would be the only JavaScript on my entire website. I’ve taken special precaution to have my website be usable in every WWW browser I test with and so that’s not an option.

                  Really, I’m actually surprised this is so complicated, all to add a single form that wouldn’t even create a dynamic page.

                  1. 2

                    It sounds like you want cgi scripts then. https://httpd.apache.org/docs/2.4/howto/cgi.html which still take a touch of config.

                    Or you want to log the post data and just manually grep it later, this page gives you three options, two of which are modules and the other one is use an application layer: https://www.simplified.guide/apache/log-post#log-post-request-data-in-apache-in-application.

                    On the bright side you definitely don’t need js to send a simple post so that’s good.

              1. 15

                I’d never tell anyone what to do with their kid, but sleep training was enormously effective for us. If you’re at the end of your rope, and are okay with it; give it a shot.

                Note: n=1 for this

                1. 7

                  Both of our girls (2 and 4) responded really well to sleep training. TBH, actually, I think the wife and I were the ones who really needed the training.

                  1. 1

                    I hasten to add, we didn’t sleep train them at 2 and 4, but that’s how old they are now. The older girl was sleep trained at 11 months, because she had heart surgery at six months, and we were (understandably) loath to do anything out of her ordinary routine until we got the all clear from her cardiologist. The baby was trained at about eight months.

                  2. 4

                    Us too. And there are a lot of studies of how sleep training beginning at six months (I think; I need to double-check the exact age) has absolutely zero psychological side effects. Except on the parents of course, who may actually be somewhat sane.

                    1. 3

                      Got a link to any such studies other than the Middlemiss one? That study has been used again and again to reassure parents it’s okay to sleep train, but the study itself was deeply flawed [1]. I encourage anyone considering sleep training to read more than just that study, and to read more widely about sleep training in general. Here’s some articles (with lots more references in them) to get started [2], [3], [4].

                      We used “The No Cry Sleep Solution” [5] with middling success. Overall, I think you kinda just have to accept that it’s going to be a time of bad sleep, but that you’re making that sacrifice for your kiddo.

                      [1] https://expectingscience.com/2016/04/21/the-middlemiss-study-tells-us-nothing-about-sleep-training-cry-it-out-or-infant-stress/

                      [2] https://www.psychologytoday.com/us/blog/moral-landscapes/201407/parents-misled-cry-it-out-sleep-training-reports

                      [3] http://evolutionaryparenting.com/controlled-crying-cortisol-and-attachment-a-critical-look/

                      [4] https://www.laleche.org.uk/letting-babies-cry-facts-behind-studies/

                      [5] https://nocrysolution.com/

                      1. 2

                        I’ll find one in the morning. To be clear, I’m not recommending and didn’t practice cry-it-out; we just did some phased process that on cursory glance looks similar to no-cry. I’m in fact up at 5 am specifically because I’m getting our kid settled again.

                    2. 4

                      Cant plus one this enough, sleep training was one of the best parenting decisions we’ve made. It’s hard on everyone for like a week and then its soooooo much better for everyone. My 18 month old sleeps so well now, falls asleep on his own most of the time, sleeps through the night and sleeps like a rock unless he’s sick or otherwise agitated by something unrelated. Ymmv of course and ever kid and family is different but for my money it has been invaluable.

                      1. 2

                        sleep training

                        For all 4 of our kids, we used the training outlined in Save Our Sleep. Our eldest is ASD and had a lot of trouble with sleep - the training made the world of difference to him, and us. All the kids sleep well now between 10 and 12hrs depending on age.

                        I used to need to send my wife out of the house because she couldn’t stand the sound of my son crying. It was pretty brutal. The the difference in his (and our) mood stability during waking times was more than worth the pain.

                        1. 1

                          I would have thought sleep training would be standard practise by now… certainly our midwives talked about it in our prenatal.

                          1. 1

                            It is, like most things in the world of parenting, still A Thing. That’s OK, people should do what works for their family.

                        1. 0

                          this is a bit off topic, but I have run into this strange bug a lot recently where, if I am running two instances of firefox side by side using two different profiles, the personal profile one just crashes. It seems to be directly triggered by clicking a shortened link in twitter, which is extra weird, and I wonder if anyone else has this problem?

                          1. 5

                            totally off-topic :D But do you have a crash report submitted or a crash signature to share? Going to about:crashes might help you.

                            1. 4

                              Oh I totally do, 20 submitted so far :) will dm.

                          1. 4

                            FWIW this is one of the examples that made me “get” WebAssembly:

                            https://github.com/WAVM/WAVM/blob/master/Examples/echo.wast

                            It’s an implementation of /bin/echo, and is pretty readable if you stare at it for awhile.

                            • It “imports” _fwrite and _stdout from the environment. By default WASM is sandboxed, so it can only do I/O on injected “objects”.
                            • It exports main() for the wrapper to call (in this case, the command line, but more often the browser)
                            • It defines a strlen() function that does the obvious thing – loop over the characters until you get to NUL.
                            • it defines an fputs function that calls strlen() and _fwrite()
                            • The main program loops over the argv array and returns an integer status 0
                            • The keywords are mostly self explanatory:
                              • module, func, return
                              • import, export
                              • local, set_local
                              • if, loop
                              • data appears to be for global constants
                              • drop ignores a return value (since WASM is a stack machine I suppose)

                            It’s very verbose! But everything is pretty explicit which makes it readable for small examples like this. There are other examples in the same dir:

                            https://github.com/WAVM/WAVM/tree/master/Examples

                            The WebAssembly paper explained enough of the conceptual model, which made this example fairly readable:

                            Bringing the web up to speed with WebAssembly

                            1. 1

                              Hey thanks for these resources, I will look them over!

                              I think my next post will be about making minimum versions of all the sections the spec outlines and then trying to do something useful with them, so the echo example is a very good one.

                            1. 2

                              I have kept my distance from WebAssembly for the past few years. Your article has piqued my interest in it again; going to take a closer look now.

                              1. 2

                                I understand the distance, its elevator pitch is somehow both really compelling and also kind of superfluous at the same time. I’m really interested to see how it evolves long term though, and it being standardized and shipped in all relevant contexts is a big positive signal for that long term.

                              1. 2

                                Nice write up and interesting to see your e2e round tripping tool chain. Is this something you came up with? And is this a way to develop/debug?

                                1. 1

                                  If you mean wasm2wat and wat2wasm, they are part of wabt (web assembly binary toolkit) which I link to in the post. If you mean the xxd parts, that’s definitely useful in viewing binary files as visually understandable text without transforming it at all. Thanks for reading!

                                1. 9

                                  Have you checked out wasmer yet? I think it will come in quite handy.

                                  Also, I do quite a bit with WebAssembly. In fact, I’ve been using emscripten since before there even was WASM. Check out genact for a useless project I did that outputs to WASM as well as native platforms.

                                  1. 1

                                    I have not seen that, thanks for the link, I will check it out!

                                  1. 3

                                    I use DuckDuckGo, so in honour of Father Ted’s second greatest character, I Dougal.

                                    1. 0

                                      How do you make it return useful results? I can’t seem to get what I want. Either my search requirements are more stringent than yours (and the many others who cite success with DDG) or I’m doing it wrong :) I’m open to either answer.

                                      1. 6

                                        When I’m not happy with my DDG results, I throw a g! on the query and hit enter.

                                        Half the time, I’m not happy with the google results, either. (Maybe whatever I’m searching for doesn’t exist.)

                                        There is a specific class of queries that DDG doesn’t support well: those written in English. If my query is going to be “What was that thing John Smith was publicly embarrassed about a few years back?”, I might just go straight to Google.

                                        Wait a minute, do you search for “What is a client-side plugin for XYZserver to make thumbnails?”, or do you search for “xyzserver thumbnails clientside” ? DDG can’t handle the first option, AFAICT.

                                        1. 1

                                          Again I admire your adherence to principle. I do not have that much life to spend that I’m willing to have each query take 3X the time.

                                          1. 1

                                            I have not had the same problems with ddg which you complain about. I never use “english language” queries, and usually ddg has good results on the first page. Google tends to be much more verbose, so I often try it when there are few results on ddg, but it’s not my first choice. This is reflected in my history where I visit ddg around 4x as often as google.

                                            sqlite> select rev_host, sum(visit_count) from moz_places group by rev_host order by sum(visit_count) desc limit 15;
                                            ...
                                            'moc.ogkcudkcud.',13981
                                            ...
                                            'moc.elgoog.www.',3537
                                            ...
                                            

                                            (as an aside, why does firefox open places.sql exclusive?)

                                          2. 1

                                            Half the time, I’m not happy with the google results, either.

                                            That mirrors my experience. I don’t think the problem is DDG. I think if people can’t find what they want using Google, they conclude it doesn’t exist or is simply hard to find. If people can’t find what they want using DDG, they blame DDG.

                                          3. 5

                                            I’ve been using it for a few months and I’d say I get what I want about, hmm… 70 or 80 percent of the time? I can usually predict what searches will be too specific or niche to produce reliable results. imo it still makes me feel better about using Google when I really need to, almost like “well ok I will actively trade a tiny portion of my privacy for this data because it really is the only way to get it.” Feels more explicitly transactional to me.

                                            1. 4

                                              I just use old tricks. I guess what words writer is likely to use, put quotes around what should definitely be there, minus in front for filters, “site:” if I know domain, and !G if that doesn’t work. Rarely have to use Google.

                                              I miss being able to do advanced, boolean stuff to narrow it further. Wonder if it’s still there somewhere but hidden.

                                              1. 2

                                                Yeah I miss the boolean stuff from the old days too :) I wonder if it didn’t scale well?

                                                1. 1

                                                  Yeah, I thought it might be heavy on their servers. My other thought is that virtually nobody used advanced search. So, they simplified it into some common operators (eg time range). Two birds with one stone.

                                              2. 3

                                                Yeah, I’ve always found DDG’s results to be… pretty substandard. Have you tried Startpage? It uses Google’s search for its backend, so results great and at the same time, doesn’t invade your privacy.

                                                1. 1

                                                  I haven’t I’ll give it a look. Thanks!

                                            1. 4

                                              I appreciate this post, because while a lot of this is rudimentary information if you’ve been working with javascript for any length of time, it so often just glossed over in tutorials and blogs. “Oh just use create-react-app/[other scaffolding tools]” or “just bundle here is a conf” is a pragmatic answer, but doesn’t explain much about why those bundling, splitting, minifying, and etc. steps are desirable from first principles.

                                              1. 5

                                                Count them. That’s 22 script includes.

                                                Requesting this many scripts was a major network bottleneck, and as a result my site took a long time to load. Web performance matters — its importance has long been well-known and documented. What seems more efficient to you: downloading 1000 lines of code 10 lines at a time, or downloading 1000 lines of code all at once?

                                                …What?

                                                I know we need to measure things and not go with intuition on performance, but my intuition is that 22 scripts — in the grand scheme of things — is not particularly many. I mean, the webpage that this blog post is written on makes 77 requests, with the first ~25 of those happening in the first couple of seconds.

                                                Did he actually measure this “speed problem”? Was downloading 22 scripts verifiably a “major network bottleneck”?

                                                1. 1

                                                  I suspect it was a “time to first paint” issue, which would certainly make it feel like what the author describes. I agree that it is an imprecise way to say it though.

                                                  1. 1

                                                    good point - I didn’t measure the speed problem but probably should’ve. It’s much less of / not a problem now with http 2, but back in 2016 this was a bit more relevant. Regardless, “major network bottleneck” is an exaggeration and I’ll edit this a bit for clarity. Appreciate the feedback!

                                                  1. 1

                                                    buffers really are the fundamental unit of concern in vim, once I grasped them and started using them properly along with splits and tabs vim became a “place” more properly for me.

                                                    One missing command in that list is <C-w>q which closes the “view” on the buffer without closing the buffer itself. I use this all the time when I want to reorganize my splits or tabs and don’t want to close out everything and start over.

                                                    1. 1

                                                      I learned so much from this course, as a general overview of how everything fits together and all the connections between steps it’s just terrific.

                                                      1. 1

                                                        bravo, this is exactly the kind of thing I want to read, substantive explorations of concepts I have only a superficial understanding of. looking forward to the rest!

                                                        1. 3

                                                          what a load.

                                                          I don’t usually post complaints in public but the Macbook Pro I’ve been using lately has been a complete and utter disappointment. The keyboard is terrible, almost every key on the bottom row has either started doubling or just stopped working. It makes using it at all almost impossible!! and I really despise the touch bar, the only time I hit it on purpose is for volume keys and otherwise I just accidentally lock it all the time. I’m glad that seems to be cut out of the newest models at least.

                                                          It’s just… the hardware is so beautiful, so close to being ideal, it’s so frustrating. The last Apple I had that worked exactly how I wanted was a 2015 macbook pro. Such a good keyboard. It died in a tragic latte accident and I replaced it with a lenovo x1 carbon, and this keyboard is just such a joy to type on.

                                                          Anyway sorry for the negativity

                                                          /rant

                                                          1. 2

                                                            How is the x1 carbon compared to the 2015 mbp?

                                                            1. 2

                                                              I like it a lot, the keyboard is really great, even better than the mbp, which I was happy with.

                                                              really the x1 is a fantastic machine, I am really happy with it. the only negatives are: the screen isn’t super great, but I got the non-oled version because I didn’t want/need the touchscreen, so I imagine the next gen one I get in a few years will be much better. the speakers aren’t great, but I’m not too bothered by that either. the battery life on standby is pretty iffy, but this is documented behavior with this model using linux because of some weird hardware stuff put in to support some new windows standby mode. really this is the only thing about the computer that genuinely sucks, but there’s apparently a new firmware update that fixes it that I haven’t gotten around to flashing and the battery life when off or in use is terrific, so it’s a limited issue.

                                                              all that but also it’s a much newer machine and feels pretty snappy. I’m happy with it!

                                                            2. 1

                                                              I work for a company that uses Mac laptops for gigs and installations, and we exclusively use 2015 MacBook Pros. I’m not sure what we’ll do as they get harder and harder to find.

                                                              1. 3

                                                                you’d really think apple would pull their heads out of their asses on these pro models and offer something that actually caters to the enormous dev population that really wants to continue loving them.

                                                              2. 1

                                                                the hardware is so beautiful, so close to being ideal

                                                                Are you mainly referencing the past hardware? Seems lately stuff has been a bit rougher and even you said the keyboard is terrible.

                                                                (re: touchbar) I’m glad that seems to be cut out of the newest models at least.

                                                                It wasn’t.

                                                                1. 1

                                                                  re: touchbar, I was just going by a cursory glance at the apple landing page, I guess it’s still on the pro and I’m seeing the “air” or whatever? My mistake.

                                                                  Yeah I guess I am ultimately referencing the past hardware, though most of what makes the last few models so disappointing to me is that they really are well engineered in many respects, and most pieces fits together just right, and the weight is just so and the feel of the case is just right etc and on and on. I can look past things, the touchpad, the dongle situation, but the keyboard being so buggy and borky is just simply a no go, and that’s a shame! To be honest the very same computer I’m complaining about, I was super happy with it until the keyboard issues, and yeah it can be fixed and yeah they added the membrane but idk, it’s just disappointing.

                                                                  1. 1

                                                                    It’s just disappointing.

                                                                    I feel that is almost the word of the last for years for Apple hardware. Still “good”(ish) – still works for most people, but in so many ways disappointing to more hardcore fanbase, and random weird issues. The USB-C slowing down whole systems with certain cables / connected devices, keyboard issues, throttling issues, speaker issues.

                                                              1. 2

                                                                I like the rate of posts, plenty of interesting stuff to read but you can keep up checking in once or twice a day.

                                                                Also I like that when I submit my own posts I’m likely to get high quality feedback and probably be on the front page for a bit and it’s no big deal, whereas being on the front page of hacker news is like getting in a dunk tank.

                                                                1. 1

                                                                  obligatory http://bettermotherfuckingwebsite.com/

                                                                  I love the minimalist sentiment

                                                                  1. 27

                                                                    I disagree with the negative posts. Writing about something you’ve just learned is absolutely a wonderful way to cement the knowledge, record it as you understand it for posterity if only for yourself, and help you pull others up right behind you. It’s not your responsibility to keep your ideas to yourself until some magic day where you reach enlightenment and only then can convey blessed knowledge on the huddled masses, a lot of this stuff (the specific tech, for the most part) moves too damn fast for that anyway. Maybe we need better mechanisms for surfacing the best information, sure, but discouraging people (yes, even noobs) from sharing what they’ve learned only ensures we’ll have fewer people practiced in how to do it effectively in the future.

                                                                    That said, I do 1000% agree that people writing in public should be as up front as possible about where they are coming from and where they are at. I definitely get annoyed with low quality information that also carries an authoritative tone.

                                                                    1. 8

                                                                      There’s a world between documenting how you learned a thing, and writing a tutorial for that same thing. If you’re learning a thing, probably don’t write a tutorial. I agree with you, writing about a freshly learned lesson helps in making the learning more permanent, though.

                                                                      1. 5

                                                                        In the case of projects, I’d rather see people committing documentation changes back to the project, at least here the creator of the project can review it.

                                                                        It’s a free internet and nobody can stop someone from doing this, but, IMO, the problem with technology is not that there is too little poorly written tutorial out there. Maybe it’s worth finding other ways of being constructive.

                                                                        1. 4

                                                                          Writing it down can help the mind remember or think on things. If errors are likely, then maybe they just don’t publish it. They get the benefits of writing it down without the potential downsides.