Why, oh why was this added?
zigamiklic.com
zigamiklic.com
I've come across so many of these in my career. It's not even a rare occurrence (and the author gets this, "And just like that, we are again at step 1 of our debugging journey.") While in the author's case there was a reason for the fence to exist, IME quite often there just isn't. But I've also spent a lot of time working at startups where the mentality was "move fast and clean nothing up".
Sometimes, ^F the thing you're interested in Slack. I've solved a number of code archeology mysteries with that. (But, I doubt it would help here. The author's problem lacks enough context / good search terms. It works better when you have something with a solid name, like a VM.)
I have a somewhat embarrassing confession: I've done this with code I've written more than once. I've learned to thoroughly comment anything unintuitive even when I know I'm going to be the only one reading it.
One says "if you don't know what it does, don't delete it", the other says "if you don't know what it does, don't keep it".
The whole point of Chesterton's Fence is that there's wisdom encoded in the way things have been done. The previous guy who worked on the same module was probably somewhat competent, and in any case, the component was fulfilling business needs for all that time, so they were doing something right.
But the person who removes it have to deal with the aftermath. Midnight callout, fixing corrupted data, etc.
I.e., you manage the risk.
The alternative — following Chesterton's parable absolutely — means you'll be dragging along, and critically, paying for — both in cash and in complexity of understanding —, an ever-accumulating Katamari of junk that, in all probability, serves no purpose whatsoever. Trying to justify "we want to continue to paying indefinitely for this thing that we don't thing does anything important, but we're not at all sure" — well, at the very least, you're going to look like a clown if you try to pass that by any sort of management that's not asleep at the wheel.
I've removed an awful lot of this stuff in my career. I've gotten remarkably good at deleting a lot of infra with minimal to no impact. Mostly, that comes from first knowing how the actually important infra works, which helps rule out that the odd end over here is going to have any impact at all. Occam's razor helps greatly: asking, "if it did have an impact, how?".
Graceful decoms, such as imaging a VM, or just stopping it for a month prior to out-right deletion, again help build confidence in the non-impact, and reduce the risk if you're wrong: you just turn that VM back on. I.e., having a rollback plan such that if there is some unforeseen contingency, that you can get back to the original state. (Though every now and then, there is an odd service for which you can't do this. Those are annoying.) But even a rollback is good: it provides a valuable clue as to what the unknown thing does, and now you know where to start digging.
It's one of those things where the pragmatic view is the middle ground: wildly deleting things is a poor choice, but so too is blindly keeping things.
Particularly when corps these days want to retain nobody past ~2 years, you end up with a lot of knowledge getting bus factored. If you don't want to get stuck in that quagmire, you've got to be able to clean house.
Our video player has a specific use case where it needs to run at 10x speed. At some point we started seeing decoder underflow issues in Chrome. After banging my head against it for a couple of days, I discovered that setting playbackRate to something just below 10, like 9.9 would make the issue disappear. We didn't have a hard requirement to have it play at exactly 10x, and I didn't want to spend more time on the issue, so I left a descriptive comment next to the fix. Our team now refers to this as "the Warp 10 workaround".
This is something I've been training and forcing myself to do. If I spend 10 - 15 minutes thinking about some piece of code or infrastructure to understand why it's here and what it does... add whatever you learned and found out as a comment. Even, or especially if it wasn't fruitful, and your only answer is "the system is being weird here in the following way, and this mess is here to fix it, kind of, in most cases - and since you're here, I guess not in this case".
And I can confidently say that pretty much every descriptive comment I've ever written was out-of-date shortly after it was written, but the "hey, this weird because of X and if you think you are going to optimize or fix something you need to be aware of this special case" have saved me numerous times.
Not knowing why some particular piece of code is there, or why it’s coded in that specific way, impedes refactoring and adding/changing features, and in the long run contributes to the ossification of the codebase.
I have the benefit of working on a team with impressively rigorous review habits, and the detriment of being comment-averse when I write code (because I’ve more often than not been bitten by comments that are plainly wrong but only in retrospect).
So this probably doesn’t apply to most, but here’s my heuristic for when to add a code comment: did someone ask a question about it, or something which could be traced back to it? That’s it, the whole comment strategy. I answer questions people actually asked. At which point I generally provide a lot of detail, because if it’s worth asking, it’s worth answering in one place or at least providing a single frame of reference to jump off to other contextually pertinent details.
If you only add stopPropagation() when there's a reason, then at least later you know there had to be a reason.
With enums/static variables are you referring to custom events or also DOM events? For custom-based events we use that approach but not for DOM events. If you do use it for DOM events, I'm curious to know more about it. Thank you!
Why? This way you switch from “an event finds its deepest control” mentality to “anything at these coords receives it”, which may have much broader effect under different situations than any reasonable sense may suggest. Is there any programming benefit except pleasing some hacky techniques which go against the fundamental idea?
So with native events, I don't bother to write enums but I do namespace them and listen for them through the JQ event chain. With custom events I write the enums and listen for them through JQ on the component instance, without having to listen on window or make the component extend EventTarget.
tl;dr I only use custom or namespaced events and never run anything between components/controllers through the DOM's native event chain.
Just because Chesterton’s Fence is a thing doesn’t mean you have to build new ones without signs on them.
Not optimal. Better, to make sure you don’t forget, write a test for the case that needs event.stopPropagation() to be there.
I'm fixing up some old shell scripts - any single quotes with variables now get documented - sometimes you want to pass them to another shell or program so it IS intentional.
function DatePicker() {
function handleDateChange(event) {
preventDialogFoobarFromClosing(event);
...
}
return (
<ThirdPartyDatePicker
onChange={handleDateChange}
/>
);
}
function preventDialogFoobarFromClosing(event) {
event.preventDefault();
} doNotTriggerEventInFoobarJS()This phenomenon is one of my favorite terms in software: Cargo Cult Programming https://en.wikipedia.org/wiki/Cargo_cult_programming
That phase is over sooner or later, but the code produced in the meantime tends to survive even in production for longer than that. Including the occassional cargo cult shrines.
Date Picker is one of those things that seem like a big complicated thing but is actually very very very simple to implement.
Honest advice: implement one yourself and use it in your projects. It doesn't even take 600 lines (even when you include the css).
The "hardest" part is displaying a calendar month (for a given year/month combination), in a grid layout, where columns represent week days. But that is actually not hard at all, because the builtin Date class has all the building blocks necessary to make this work. Even the i18n can be done with the builtin Date class.
Given a (year, month) combination, where month is specified from 1-12, this is how you get the weekday of the first day in the month:
let firstWeekDay = new Date(year, month - 1).getDay()
This will be a number from 0 to 6, where 0 is sunday.The other bit of information you need is the last day of the month, which can be obtained thus:
let lastday = new Date(year, month, 0).getDate()
Now just loop over the range 1...lastday and fill in the grid of the days of the week.It's that simple.
About 2/3 of the people on this planet do not agree with the west about when the year starts, what are the months, and things like that. This may be a huge roadblock for you, or just ignoring it may be perfectly fine.
India and much of Northern Africa do not adopt the Gregorian calendar. By my estimate, that would be 1/5 of the population as opposed to 2/3.
Most of the world officially adopted the Gregorian calendar (one of the regions you missed, the Middle East is on the process of changing, with some countries further than others), but most of those countries have a dual calendar system, so depending on what you do, you may need one or the other.
Yes, for counting population, China is what weights the most, and they almost completely moved already.
It’s partly my own fault for using the English version of software since I don’t want to use localized GUI navigation guides (they might not exist).
How does this justify installing a 500kb javascript dependency?
Saying this is "not that simple" is just you mentally deciding to lose for no reason.
<input type="date">
and let the user agent deal with that complexityJob done!
This is one of the reasons why I only ever touch React or similar frameworks when forced to do so at gunpoint. If a library author is on their 17th major version and is still deciding how core stuff like this works, I have no confidence they're ever going to settle on a long-term solution.
Just give me the standardised web APIs thanks, that's a perfectly suitable framework. At least these converge towards consistency and have been (and will remain) stable for decades. The last thing I want to spend my time on is constantly chasing API breakages.
Did you follow the link to understand what the change is, and why they made it? [link]
This isn’t some sweeping rewrite of an entire subsystem for the fourth time (I’m looking at you, Angular); it’s just changing React’s synthetic events to be attached to the react tree’s root node in the DOM instead of directly on the document. They have always been on the document until now. So there is no “still deciding” flip-floppery here, there was a single decision made to better support developers by making one low-impact change. How low-impact?
> We’ve only had to change fewer than twenty components out of 100,000+ in the Facebook product code to work with these changes…[link]
React is very good about semantic versioning. This change, small as it is, is a breaking change for a very small number of users. And that’s why it gets a new major version number.
https://reactjs.org/blog/2020/10/20/react-v17.html#changes-t...
The entire purpose of what people do with state management and contexts is to decouple this.
Yes, I do front-end development every day. No, I have not done any React/Angular/Vue development recently. The tunnel-vision idea that "front-end development" must mean using one of the Big Frameworks is exactly the idea I'm pushing back against. I tried them for a while (Angular and Knockout), but wrote them off because they couple the logical organization of your app to the DOM tree and they've never taken any steps to improve that (nor even accept that it's a problem).
If you're talking about Redux, there are good ideas there, but it's really just trading one kind of global state for another.
I think I now understand what you're saying. You're saying people spend lots and lots of time trying to work around this exact problem, which is introduced by Angular, React, Vue, et al. Realize that this is entirely an extrinsic problem introduced by "component-based" architecture and that a different approach (HTML as one output of the program) avoids this entirely. Managing state is still hard (as it always is), but there's nothing that needs to be decoupled in the first place. It's similar to how "design patterns" are really workarounds for the limitations of OO programming: Redux is a workaround for the limitations of React.
The example could be any code that interacts with dependencies which get updated from time to time. Instead of “why do we stop propagation here?” the question could have been “why is this float converted to a string here?” If the answer is not clear from within the same function call, it may (may!) need a comment to clarify it.