Programmer in NYC

  • 0 Posts
  • 27 Comments
Joined 2 years ago
cake
Cake day: May 7th, 2023

help-circle


  • Yes, I like your explanations and I agree that’s the way to think about it. But either way you have some special exceptions because main.rs maps to crate instead of to crate::main, and a/mod.rs maps to crate::a instead of to crate::a::mod. I know that’s the same thing you said, but I think it’s worth emphasizing that the very first file you work with is one of the exceptions which makes it harder to see the general rule. It works just the way it should; but I sympathize with anyone getting started who hasn’t internalized the special and general rules yet.


  • Yeah, it’s tricky that the file for a module is in a subfolder under the file that declared it, unless the file that declared it is named main.rs, lib.rs, or mod.rs in which cases the module file is in the same folder, not in a subfolder. There is logic to it, but you have to connect multiple rules to get there.

    We see in the examples above that a module named whatever can be in whatever.rs or in whatever/mod.rs and you get the same result. mod.rs is a special name with a special lookup rule.

    whatever/mod.rs whatever/submodule_of_whatever.rs works exactly the same as whatever.rs whatever/submodule_of_whatever.rs. We use mod.rs so we don’t have to have both a folder and an .rs file with the same name. But that leads to the special exception where submodules declared in mod.rs are defined by files in the same folder as mod.rs.

    main.rs is like the mod.rs of the entire crate. main.rs has a special rule where it’s in the same folder as its submodules, instead of the normal rule where submodules are in a subfolder.

    lib.rs fellows the same special rule as main.rs. (You use main.rs to define an executable, lib.rs to define a library.)



  • One of my favorites is from Sisko, but I guess this one is more of a soliloquy than a dialogue,

    The trouble is Earth! On Earth, there is no poverty, no crime, no war. You look out the window of Starfleet Headquarters and you see paradise. Well it’s easy to be a saint in paradise, but the Maquis do not live in paradise! Out there, in the Demilitarized Zone, all the problems haven’t been solved yet! Out there, there are no saints! Just people! Angry, scared, determined people, who are going to do whatever it takes to survive, whether it meets with Federation approval or not!



  • git rebase --onto is great for stacked branches when you are merging each branch using squash & merge or rebase & merge.

    By “stacked branches” I mean creating a branch off of another branch, as opposed to starting all branches from main.

    For example imagine you create branch A with multiple commits, and submit a pull request for it. While you are waiting for reviews and CI checks you get onto the next piece of work - but the next task builds on changes from branch A so you create branch B off of A. Eventually branch A is merged to main via squash and merge. Now main has the changes from A, but from git’s perspective main has diverged from B. The squash & merge created a new commit so git doesn’t see it as the same history as the original commits from A that you still have in B’s branch history. You want to bring B up to date with main so you can open a PR for B.

    The simplest option is to git merge main into B. But you might end up resolving merge conflicts that you don’t have to. (Edit: This happens if B changes some of the same lines that were previously changed in A.)

    Since the files in main are now in the same as state as they were at the start of B’s history you can replay only the commits from B onto main, and get a conflict-free rebase (assuming there are no conflicting changes in main from some other merge). Like this:

    $ git rebase --onto main A B
    

    The range A B specifies which commits to replay: not everything after the common ancestor between B and main, only the commits in B that come after A.




  • I have a hard time getting over the thing where the story introduces some amazing new capability, and it’s never explored further. In this one it’s, “we found a way to get home instantly, but we’d have to do a thing in sick bay to reverse the side-effects.” A similar case is the episode with the planet of friendly hedonists with long range transporters that it turns out they can’t use because “the power systems are incompatible”.

    I’m sure if I weren’t so uptight I’d enjoy these episodes more.


  • This leads me to another thought: are station residents charged for using the replicators in their quarters? I imagine the replimat charging like other station businesses; so what about private replicators? Or maybe I’m wrong, and the replimat is a free public service?

    I’m guessing replicator use would be free under Federation jurisdiction the same way Quark isn’t charged rent. But on the other hand, it’s a Bajoran station - Starfleet only administers it. Now I’m wondering what kind of negotiating went on to get the struggling provisional government to pass up revenue from DS9 rental spaces.


  • Another time money comes up is the episode, In the Cards, where Jake wants to buy a Willie Mays baseball card to cheer up his dad. He talks Nog into paying for it because as a Federation citizen Jake doesn’t have any money.

    I found some of the dialogue on Memory Alpha:

    It’s my money, Jake! If you want to bid at the auction, use your own money.

    I’m Human, I don’t have any money.

    It’s not my fault that your species decided to abandon currency-based economics in favor of some philosophy of self-enhancement.

    Hey, watch it. There’s nothing wrong with our philosophy. We work to better ourselves and the rest of Humanity.

    What does that mean exactly?

    It means… it means we don’t need money!

    Well, if you don’t need money, then you certainly don’t need mine!

    I also imagine Starfleet officers in a non-Federation posting getting stipends. Or maybe Quark and other business owners bill the Federation for whatever Federation citizens buy? And maybe that arrangement doesn’t extend to the auction with the baseball card?

    There are references to Jake buying from some of the station’s businesses. I think I remember him buying jom-jom sticks, and dining at the Klingon restaurant. (Did Jake ever use a holosuite on his own?) I’m thinking either Jake has some sort of allowance or stipend, and is exaggerating when he says he “doesn’t have money”, or those businesses make special arrangements for Federation citizens.




  • rust-script looks like a neat way to use Rust for scripting. But I was coincidentally reflecting on how helpful Nix is for handling the same problem, where I want to write scripts in a compiled language, but managing builds is a lot to deal with in an ad-hoc setting. I can pair my script with a Nix expression that gets checked into either my project repo, or my Home Manager dot files, and then I don’t have to think about rebuilding on changes or on new machines.