Showing 159 to 162

Emacs timer gotchas

Emacs gotchas

  1. Gotcha: If you use a repeating timer and suspend the computer, all the queued repeats will execute simultaneously when you come back. If you only want it to be called once at a given time regardless of computer sleep, make a function that passes itself to (run-with-timer) as suggested in the manual. So instead of using a repeating timer, you make a chain of once-off timers.

    (Given that you want this behavior in almost all use cases of repeating, (run-with-timer) is a too low-level function to recommend to programmers – it's only solid if you avoid the REPEAT argument. Repeating safely requires boilerplate which you can skip with named-timer, a 70-line library.)

    a. With the usage pattern suggested in the manual, you'll run into a different gotcha: a bug anywhere in your function body will stop it from restarting the timer. So you thought you'd set up a repeating timer but the chain of restarts died at some point and never gets back up and running. Either restart the timer first of all, or wrap the work in (unwind-protect). The boilerplate goes something like:

    (defvar my-timer nil)
    (defun my-next-tick ()
      (unwind-protect
          (progn
            (do work)
            (do more work)
            (work. work never changes))
        (when (timerp my-timer)
          ;; prevent duplicates
          (cancel-timer my-timer))
        (setq my-timer (run-with-timer 60 nil #'my-next-tick))))
    (my-next-tick)
    

    Note how we never specify the REPEAT argument!

    We cancel the timer just in case something has run (my-next-tick) more than once (one culprit is reloading your library), which would spawn more than one series of timers visible in M-x list-timers even though the variable my-timer only holds a reference to one of them. The library named-timer takes care of this boilerplate as well as the need for the defvar.

  2. Gotcha: If you use a repeating idle timer, it will not repeat after the first invocation, for as long as you stay idle. If you want it to continue repeating while idle, don't use an idle timer. If you want behavior to be different while idle (especially if you want the repeat interval to differ), use two different functions plus a third that checks whether you're idle and selects the appropriate function. For an example how you may do this, go to eva.el and search for eva--start-next-timer. Again, this never involves an actual idle timer, just standard once-off timers.
  3. Gotcha (and duh): don't use the private getter (timer--triggered my-timer). How to check that your chain of timers got killed and hasn't restarted? Eval (member my-timer timer-list) or (member my-timer timer-idle-list). It'd help discoverability if there was a descriptively named builtin function that just did this. However, this method isn't foolproof, see #4.
  4. Gotcha: I had a "keepalive" timer that would respawn the first timer if there was a problem. Being a bona fide repeating timer, it was invoked many times upon return from a laptop-suspend state, which should have been fine because it checked (member my-timer timer-list) – but it went ahead and spawned many copies of this timer; in other words, the conditional failed. Clearly the variable timer-list is not always updated in time. In summary, even if your code looks foolproof, it isn't. Make it verifiably foolproof with a safety wrapper like named-timer. And when you have a repeating timer, check and set some boolean to ensure you only start one on laptop wakeup.

What links here

  • 2021-01-10
Created (5 years ago)

Pinch hitter syndrome

(statmodeling.stat.columbia.edu/2005/01/26/the_pinchhitter/)

The syndrome where you find that people whose sole job it is to edit articles aren't even very good at editing articles. Like a pinch-hitter in baseball who also have one job but isn't the best player at that.

One explanation: "Traditionally, comparative advantage is used to explain why trade is beneficial to both parties even if one party is more efficient at producing everything."

What links here

Created (5 years ago)

Norman door

A Norman door is a nonintuitive #design feature that needs extra instructions for how to use. Like a door that needs stickers saying "pull" or "push" because the handles look the same on both sides.

The #R Tidyverse designers try to make a consistent API so that the whole ecosystem starts to feel intuitive when you learn a part. They follow the principle "avoid making Norman doors" among others. I guess some software ecosystems are nothing but Norman doors.

Created (5 years ago)

To enumerate Mass Effect plot holes

  • The usual injunctions against space opera
    • There seems to be an upper limit to technology everyone lands on, because human tech can face Turian tech and not be wiped with the floor. Yet the player sees cases of "new and experimental" tech that is much better than what came before, so is there a limit or isn't there?
      • Since the ME races have been around for tens of thousands of years, they ought to have invented the new and experimental thing already. It's a massive plothole that everyone has a roughly competitive level of tech (even the Protheans and races that haven't had first contact are roughly on a playing field with Citadel races).
        • Plus there appears to be no difference between the Protheans of 49.000 years ago and those of 50.000 years ago.
    • Apparently everyone just settles on what the "dreadnought" size class is, even before first contact
    • Language, but on this everything has been said already
    • Manned ships; space as a sea; not enough room given to AI (or VI) and drones
      • Think about it, you don't need to send a ship to your enemy homeworld to bombard it, you can just start lobbing missiles right from your own homeworld to theirs. Call them ISBM (interstellar ballistic missile). Warp is not needed because what's the hurry, the missiles can jump thru mass relays to cover most of the distance
      • In ME and most space opera, the design of manned ships is 90% accommodation for the beings inside. More realistic is the Foundation trilogy with kilometers-long battleships that carry a crew of three (3) hanging out in a tiny livable part of it.
        • So, in the ME universe you could for the cost of one manned ship build dozens of unmanned ships, each packing the same firepower, plus they'd be tiny and take a lot less fuel. But nobody comes up with this innovation.
      • That you have to get within eyeball distance of the enemy to engage in space combat is just weird. Even in sea and air battle here on Earth, we don't need to do that.
      • Why do we see ships oriented the "right way up" all the time?
  • Why did humanity have five "battlefleets" before meeting the Turians? What were they for?
  • The Migrant Fleet…
    • A hundred years in space? In the whole galaxy with you tell me how many livable worlds, nobody can spare a patch of land somewhere? Even though the Council forbade aiding the Quarians, realistically, they would have found a deal with some shady organization… and can we talk about what a weird kind of punishment it is for the Council to hand out in the first place?
  • Why are Geth platforms just humanoids with handguns? Where are the flying Gatling guns, or the little grenades with legs, or other sensible units? Why have AI in a story if they won't be their AI nature (Answer: everyone would lose)? They're metal men but still men.
  • Reapers
    • Why do they have to land on a planet and slowly raze building after building? It would take years to finish off a planet this way.
    • What is "harvesting"? This is probably the central question mark in ME.
  • Why don't biotics just crush enemies' lungs? Seems it would take less effort than lifting their whole bodies and throwing them about.
  • Why does it work to take cover behind boxes in close-quarters combat? They're hollow boxes, not solid cubes of steel.
  • Where's all the chemical and biological warfare?
  • Where are the landmines?
  • Why don't unshielded and unarmored Rachni turn into so much bloody mush the moment anyone points their super-deadly future-pistol at them? If Rachni cause the Citadel races trouble, it would logically be because they are too many, too small and come crawling out of the vents (and Krogan would not be the solution), but instead we see essentially "battle tank Rachni" shrugging off direct fire. What kind of useless guns are those they have in the future?

The other races have multiple worlds with dense populations, while humans are mostly on Earth, with a few scattered colonies. On a galactic scale, the other races are the United States, China, and Germany, while Humans are (say) Iceland. Awesome, skilled, and empowered by good home resources, sure. But there’s no scenario where, over a single generation, Iceland becomes so powerful that a single fringe group within Iceland can become a standalone superpower capable of conquering the capital city of one of the major nations.

www.shamusyoung.com/twentysidedtale/?p=30943

www.shamusyoung.com/twentysidedtale/?p=30968

Created (5 years ago)
Showing 159 to 162