Back to basics


Palemina - Living on sky juice

I have no rice
But the pots are boiling hot
Three children hold my skirt
There’s nothing in the pot

The men I had before
Left me nothing but these kids
A new man at the door
Yet I still feed all those kids

But what can I do?
What can I do?
We can’t live on sky juice and fresh air though

His sweet bitter words
“Prove you love me with a child”
And just before the baby’s born
He’s still out running wild

He said he want that love
Not kids who push and shove

I met a social worker
She wouldn’t understand
Why I had three children by three different men

But what can I do?
What can I do?
We can’t live on sky juice and fresh air though

- “Living On Sky Juice “ by Palemina [YouTube]


What happened to Facebook?

I recently deactivated my Facebook account, for maybe the 3rd time. I don’t really use it, most of my friends don’t really use it (or at least, don’t post). But one thing that Facebook does well is that it reminds you that you regularly used it! It would show me posts I either wrote or was tagged in years ago.

Once upon a time, Facebook was pretty good. Privacy/ethical issues aside, your feed was full of things your friends were doing, and people invited you to events, and you can write whatever you wanted and people you haven’t spoken to for months/years would reply! Today, it doesn’t feel like any of those things. I say “feel” because I don’t actually know for sure — I stopped posting there a while ago. I don’t remember when/why I stopped posting.

What makes going back to Facebook impossible today is that it is completely overrun by AI and bots. Not only did I stop enjoying it, the AI generated art was starting to get emotionally draining because that’s the posts that get engagement. Recently I learned there was a subreddit to showcase the AI “art” that has taken over my newsfeed - r/FacebookAIslop

What a shame


LINQ is a footgun

Here’s something that I didn’t expect:

IEnumerable<int> list = Enumerable.Range(1,10);
Assert.That( list.Take(5), Is.EquivalentTo( new int[] { 1, 2, 3, 4, 5 }) );
Assert.That( list.Take(5), Is.EquivalentTo( new int[] { 6, 7, 8, 9, 10 }) );
  Error Message:
     Expected: equivalent to < 6, 7, 8, 9, 10 >
  But was:  < 1, 2, 3, 4, 5 >

LINQ offers a number of helpful methods to IEnumerable<T> types. It can also be a giant ass footgun because, sadly, you have to be aware of it’s implementation - every call re-initializes the enumerable!

Let’s take some slightly fictious method:

public IEnumerable<long> RestoreSomeItem( long itemId ) {
  // updates something in the database
  // returns ids in the database that changed as a result, as a byproduct of that update
  while ( results.HasMoreItems ) {
    long relatedItemIds = results.ReadRow()
    yield return relatedItemIds;
  }
}

I had to call this method, but in my method I had to return whether any items changed. “Simple!” I thought, incorrectly:

IEnumerable<long> results = someClass.RestoreSomeItem( 1 );
bool hasChanged = results.Any();
// let others know that some items have changed
publisher.Publish( results );

But there was a bug! RestoreSomeItem() is not deterministic. If you restore the same item twice, only the first call will return results. The second one will return an empty list.

The call to .Any() ran the database query. When the publisher iterated over the results, it ran another query and got back an empty list.

Thankfully tests picked up my error. But this is when I learned these LINQ methods are generally not great to use - they have unintended side-effects, and honestly seem to defeat the purpose of using IEnumerable<T>. Unfortauntely I needed to convert this to a List<T>, which kinda sucks because the results could be tens of thousands of items.

So… uhhh.. I wrote something that I hope to use that will be less of a footgun


Newer Posts /