CodeSOD: Lucky Thirteen

Nov. 13th, 2025 06:30 am
[syndicated profile] the_daily_wtf_feed

Posted by Remy Porter

Wolferitza sends us a large chunk of a C# class. We'll take it in chunks because there's a lot here, but let's start with the obvious problem:

    private int iID0;
    private int iID1;
    private int iID2;
    private int iID3;
    private int iID4;
    private int iID5;
    private int iID6;
    private int iID7;
    private int iID8;
    private int iID9;
    private int iID10;
    private int iID11;
    private int iID12;
    private int iID13;

If you say, "Maybe they should use an array," you're missing the real problem here: Hungarian notation. But sure, yes, they should probably use arrays. And you might think, "Hey, they should use arrays," would be an easy fix. Not for this developer, who used an ArrayList.

private void Basculer(DataTable dtFrom, DataTable dtTo)
{
    ArrayList arrRows = new ArrayList();

    int index;

    DataRow drNew1 = dtTo.NewRow();
    DataRow drNew2 = dtTo.NewRow();
    DataRow drNew3 = dtTo.NewRow();
    DataRow drNew4 = dtTo.NewRow();
    DataRow drNew5 = dtTo.NewRow();
    DataRow drNew6 = dtTo.NewRow();
    DataRow drNew7 = dtTo.NewRow();
    DataRow drNew8 = dtTo.NewRow();
    DataRow drNew9 = dtTo.NewRow();
    DataRow drNew10 = dtTo.NewRow();
    DataRow drNew11 = dtTo.NewRow();
    DataRow drNew12 = dtTo.NewRow();
    DataRow drNew13 = dtTo.NewRow();
    DataRow drNew14 = dtTo.NewRow();
    DataRow drNew15 = dtTo.NewRow();

    arrRows.Add(drNew1);
    arrRows.Add(drNew2);
    arrRows.Add(drNew3);
    arrRows.Add(drNew4);
    arrRows.Add(drNew5);
    arrRows.Add(drNew6);
    arrRows.Add(drNew7);
    arrRows.Add(drNew8);
    arrRows.Add(drNew9);
    arrRows.Add(drNew10);
    arrRows.Add(drNew11);
    arrRows.Add(drNew12);
    arrRows.Add(drNew13);
    arrRows.Add(drNew14);
    arrRows.Add(drNew15);
    // more to come…

Someone clearly told them, "Hey, you should use an array or an array list", and they said, "Sure." There's just one problem: arrRows is never used again. So they used an ArrayList, but also, they didn't use an ArrayList.

But don't worry, they do use some arrays in just a moment. Don't say I didn't warn you.

    if (m_MTTC)
    {
        if (m_dtAAfficher.Columns.Contains("MTTCRUB" + dr[0].ToString()))
        {
            arrMappingNames.Add("MTTCRUB" + dr[0].ToString());
            arrHeadersTexte.Add(dr[4]);
            arrColumnsFormat.Add("");
            arrColumnsAlign.Add("1");

Ah, they're splitting up the values in their data table across multiple arrays; the "we have object oriented programming at home" style of building objects.

And that's all the setup. Now we can get into the real WTF here.

            if (iCompt == Convert.ToInt16(0))
            {
                iID0 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(1))
            {
                iID1 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(2))
            {
                iID2 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(3))
            {
                iID3 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(4))
            {
                iID4 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(5))
            {
                iID5 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(6))
            {
                iID6 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(7))
            {
                iID7 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(8))
            {
                iID8 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(9))
            {
                iID9 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(10))
            {
                iID10 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(11))
            {
                iID11 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(12))
            {
                iID12 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(13))
            {
                iID13 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
        }
    }

Remember those private iID* values? Here's how they get populated. We check a member variable called iCompt and pull the first value out of a dr variable (a data reader, also a member variable). You may have looked at the method signature and assumed dtFrom and dtTo would be used, but no- they have to purpose in this method at all.

And if you liked what happened in this branch of the if, you'll love the else:

    else
    {
        if (m_dtAAfficher.Columns.Contains("MTTHRUB" + dr[0].ToString()))
        {
            arrMappingNames.Add("MTTHRUB" + dr[0].ToString());
            arrHeadersTexte.Add(dr[4]);
            arrColumnsFormat.Add("");
            arrColumnsAlign.Add("1");

            if (iCompt == Convert.ToInt16(0))
            {
                iID0 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(1))
            {
                iID1 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(2))
            {
                iID2 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(3))
            {
                iID3 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(4))
            {
                iID4 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(5))
            {
                iID5 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(6))
            {
                iID6 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(7))
            {
                iID7 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(8))
            {
                iID8 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(9))
            {
                iID9 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(10))
            {
                iID10 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(11))
            {
                iID11 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(12))
            {
                iID12 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
            else if (iCompt == Convert.ToInt16(13))
            {
                iID13 = Convert.ToInt32(dr[0]);
                iCompt = iCompt + 1;
            }
        }
    }
}

I can only assume that this function is called inside of a loop, though I have to wonder about how that loop exits? Maybe I'm being too generous, this might not be called inside of a loop, and the whole class gets to read 13 IDs out before it's populated. Does iCompt maybe get reset somewhere? No idea.

Honestly, does this even work? Wolferitza didn't tell us what it's actually supposed to do, but found this code because there's a bug in there somewhere that needed to be fixed. To my mind, "basically working" is the worst case scenario- if the code were fundamentally broken, it could just be thrown away. If it mostly works except for some bugs (and terrible maintainability) no boss is going to be willing to throw it away. It'll just fester in there forever.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!
[syndicated profile] grrlpowercomic_feed

Posted by DaveB

It’ll probably be a few pages before we see Nthaniel again. He’s going to do a quick census of all humans in the universe. Or maybe just a statistically significant sample size.

I don’t know why the starforge is that close to the star. (Besides it looking cool.) I assume the solar panels also convert heat and every other form of radiation into electricity as well. If you’re wondering why everyone in space doesn’t have one of these, well, the startup time is a lot. They also contain a lot of materials that are hard to replicate, so a Starforge starter kit is really, really expensive. Like, GDP of a planet for like a decade. And granted, part of that is that the people who know how to make them don’t just put the specs out on Gal-net for anyone to try and build themselves. The galactic economy mostly revolves around energy, time, information, and entertainment, but it’s also well understood that if everyone had unlimited access to matter replicators and unlimited power, the economy would probably fall apart. So how did Dabbler get her hands on one? The short version is she got a good look at one and figured out how to build her own. It was fidgety and had a much longer start-up time than an industrial one that a multi-planet empire could afford, but she found a star out in BFE and let it do its thing.

Dabbler’s automated construction process didn’t build the entire base. Mostly it consumed a portion of that asteroid the base currently sits in, then constructed a few habital rooms, which she started stocking with computers and fabricators to accelerate the next steps, then made a huuuuuge cavern to stockpile base construction materials, set up a bunch of automated defenses, then went off adventuring for like thirty years and totally forgot about it. Then she came back, found the base all built, albeit a tenth the size of it is now, and that it had been taken over by space pirates who were mad at her because her automated defenses whittled them down to like 30% of their starting numbers. But they had built themselves back up to a respectable number, so it turned into a really fun side mission where she had to infiltrate their ships one at a time and hack the main computers so they’d accidentally target each other instead of destroying the base when she took it back. And by took it back, I mean a stealth mission that inevitably deteriorates to ultra violent room clearing when the stealth portion fails. Because Dabbler’s life is a video game. It’s obviously also a XXX hentai seduction game, because… you know.

And now that I’ve had five seconds to think about it, I think she’d be more into seducing the low-rank ensign pirates who have the Yellow Key in their inventory than seducing the grizzled captains who have main computer core access. Yeah. That feels right. Also… there’s less chance that the low rank pirate has gotten privileges with captured… stock. They’re space pirates. Dabbler is a fan of CNC, but not NC.

It’s a little odd that Cora is using the metric system, but I guess she’s doing conversions for the Terrans’ benefit. Unfortunately, they’re Americans, so if her conversions are off by a factor of ten… Actually they probably wouldn’t know. The metric system is kind of funny, though. 1 gram is supposedly 1 cm^3 of water. I assume fresh water at sea-level in 1 G of gravity at 4°C, which is for some reason when water is at its highest density. A lot of that in stuff that doesn’t really hit on a universal scale. The reason I say it’s funny is that while the metric system is all about powers of ten, a meter is defined as how far light travels in 1/299,792,458 of a second. That’s not a power of ten, and come to think of it, a second is pretty arbitrary. I mean, not arbitrary. It’s 1/60/60/24/365.25, of a year of the planet that happens to be in the habital zone of our solar system. Hardly a unit that would be adopted galaxy-wide. Of course, a second has retroactively been defined as 9,192,631,770 vibrations of a cesium atom, which is probably a pretty stable constant, but still feels a little arbitrary.

It got me thinking, what would be acceptable galactic standard units? I think the main problem with the metric system is that a meter is not terribly human friendly. People like round numbers and I think 90% of adult humans are between 5 and 6 feet tall. Which is 1.524 to 1.8288 meters tall. I think most metric countries actually use CM for height, but my point is, I think CMs are too small, Ms are too big. Decimeters aren’t bad actually. They’re almost 4 inches, so “a hand” in horse-imperial. I mean, I think literally the only time “hand” is used is for measuring horse-shoulder height, which is odd. Now that I think about it, it’s super odd that a foot is the length of some arbitrary king’s foot, while a hand is the width of a hand. Yeah, I’m not defending the imperial system either.

Anyway, I do like a measurement based on the speed of light, which is really just the universal speed limit for massless particles. You’d think that would be a pretty stable constant – except, the universe is expanding, and that expansion is accelerating, so a light-year from 14 billion years ago is a very different measurement than is it now. Which means even a light year isn’t a constant. So I don’t know what an actual proper constant would be. Probably molecular vibration, which is only good for time and not distance. Even that will change with the heat-death of the universe, but for now, it’s probably pretty stable. If you don’t factor gravity in. Something in a tall building does experience time at a different rate than something at sea level because its affected by less gravity. Granted, it’s probably somewhere in the septillionth decimal place, but the difference between a planet with 1 gravity and 1.1 gravities might be in the billionth decimal place. So there goes that constant.

Basically I’m pretty sure the way it would work is the dominant military or cultural race, or just the first one to spread across the galaxy gets to dictate what their standard units are, and everyone else has to do conversions.


Kobold Sydney vote incentive! Is finally done!

So… you know, check it out. Oh, and as usual, Patreon has a scales only version.

 

 

 


Double res version will be posted over at Patreon. Feel free to contribute as much as you like.

GRR

Nov. 12th, 2025 11:58 pm
fayanora: FB avatar NO (FB avatar NO)
[personal profile] fayanora
I hate it when I forget to put important notes in the character file. A character of mine has two gators as pets, and I know they have names, but I didn't write them down anywhere I can easily find. And it apparently hasn't come up in the story itself yet.
[syndicated profile] daily_illuminator_feed
For those looking to outfit their heroes with a bit of flavorful bling, there's a fun article on Open Culture about armillary sphere rings. When folded, these precious-metal rings fit on one's finger (just like most other rings), but they can unfold to make a little armillary sphere, useful for astronomy.

The article also includes a dangerous link to a modern-day creator of these rings, in case I had an extra thousand-plus dollars kicking around.

Steven Marsh

Warehouse 23 News: The City Never Sleeps Because Of All The Action

There are a million stories in the city, and they're all exciting! GURPS Action 9: The City shows how you can add GURPS City Stats to your GURPS Action campaigns. It also features six sample cities to use with your own action-packed adventures. Download it today from Warehouse 23!

Vocabulary: Carcinization

Nov. 12th, 2025 10:12 pm
ysabetwordsmith: Cartoon of me in Wordsmith persona (Default)
[personal profile] ysabetwordsmith
Carcinization is a form of convergent evolution in which non-crab crustaceans evolve a crab-like body plan. The term was introduced into evolutionary biology by Lancelot Alexander Borradaile, who described it in 1916 as "the many attempts of Nature to evolve a crab".

Crabs have evolved five separate times – why do the same forms keep appearing in nature?

... including at least one sexbot whose lower body is a mechanical battle crab. :D

Half-Price Sale in Polychrome Heroics

Nov. 12th, 2025 08:04 pm
ysabetwordsmith: Damask smiling over their shoulder (polychrome)
[personal profile] ysabetwordsmith
The  November 4, 2025 Poetry Fishbowl made its $300 goal, so there will be a half-price sale in Polychrome Heroics from Monday 17-Sunday 23.  Mark the dates on your calendar, and I hope to see you then! 
ysabetwordsmith: Cartoon of me in Wordsmith persona (Default)
[personal profile] ysabetwordsmith
Happy Monsterotica Launch Day!

The crowdfunding campaign to fund publishing of our next erotic anthology, Monsterotica: Tales of Unusual Courtship and Coupling, is now live on Kickstarter!

Now through December 2nd, 2025, we seek to raise $10,500 to cover publishing of the anthology and creation of the related merchandise. This awesome book contains 16 queer stories by 16 awesome authors, each story up to 7,500 words long. We encouraged authors to pitch us stories featuring unusual creatures and unconventional genitals; you won’t find any vampires or weres here, but you will find insectoid aliens, mountain cryptids, scales and feathers, tentacles, detachable anatomy, interspecies shenanigans, courtship confusion, and much more. And of course, in addition to featuring monster x monster and monster x human relationships, every single story also includes queer characters and queer relationships!


Read "GAMING"

Nov. 12th, 2025 05:29 pm
ysabetwordsmith: Cartoon of me in Wordsmith persona (Default)
[personal profile] ysabetwordsmith
My poem "GAMING" is up on [community profile] computerworld[personal profile] beavertech has been commissioning poems to be posted in The Freaks Club family of communities.

Cyberspace Theory

Nov. 12th, 2025 05:22 pm
ysabetwordsmith: Cartoon of me in Wordsmith persona (Default)
[personal profile] ysabetwordsmith
In praise of the small things in life: DDG Bangs!

DuckDuckGo is a privacy-respecting search engine launched in 2008 that has been slowly expanding into something else truly. (I mean, come on, Identity Theft Restoration?). Well, nevertheless, I still use DuckDuckGo because it's easy, their search results aren't polluted with all sorts of nonsense, they did introduce an AI summarize feature but I don't use it and it's easy to opt out thankfully. But all of that pales in comparison to the best DDG feature, Bangs!

Bangs are… well it's kinda hard to describe them, it's basically a shortcut from your search engine to wherever else, so if you have DuckDuckGo set as your search engine, you can basically search using other search engines quite easily
!

Shopping

Nov. 12th, 2025 02:32 pm
ysabetwordsmith: Cartoon of me in Wordsmith persona (Default)
[personal profile] ysabetwordsmith
Here is an interesting discussion about what it costs to buy kitchen equipment. None of this is how I'd go about it, unless someone handed me grant money earmarked for that purpose. (Fair disclosure: I could make a crude but usable knife by busting a rock, and I could cook on a flat rock or with sticks. Kitchen equipment is a beloved convenience for me.)

Read more... )

Conservation

Nov. 12th, 2025 02:08 pm
ysabetwordsmith: Cartoon of me in Wordsmith persona (Default)
[personal profile] ysabetwordsmith
Massachusetts is turning retired cranberry bogs into natural wetlands. They’re on track to rewild 1,000 acres

In November 2024, the DER funneled $6 million in grants to the restoration plan. According to the U.S. Fish & Wildlife Service, more than 500 acres of retired cranberry bogs have already been converted into wetlands — with hopes of restoring 1,000 acres in the next decade.

“These projects will transform degraded former cranberry bogs into thriving wetlands that will provide habitat to important species, flood control in time of storms, and access for all to beautiful natural areas,” Governor Maura Healey said in a statement.



This is a brilliant plan that will provide tremendous benefits for wildlife, as wetlands are among the most biodiverse communities. It will be especially helpful to migrating waterfowl of the Atlantic Flyway.


Birdfeeding

Nov. 12th, 2025 01:52 pm
ysabetwordsmith: Cartoon of me in Wordsmith persona (Default)
[personal profile] ysabetwordsmith
Today is sunny and mild, a beautiful fall day.

I fed the birds.  I've seen a mixed flock of sparrows and house finches plus a fox squirrel.

I put out water for the birds.

EDIT 11/12/25 -- I planted 4 clusters of Egyptian walking onions.

EDIT 11/12/25 -- I filled a trolley with dead weeds and dumped it in the firepit.

EDIT 11/12/25 -- I did a bit of work around the patio.

EDIT 11/12/25 -- I did more work around the patio.

EDIT 11/12/25 -- I filled another trolley with dead weeds and dumped it in the firepit.

As it is getting dark, I am done for the night.
 

2025 November Magpie (not Monday)

Nov. 12th, 2025 10:10 am
dialecticdreamer: My work (Default)
[personal profile] dialecticdreamer
Welcome to the November of 2025 Magpie Monday!

Yes, it’s Wednesday. Yes, I’m “running late.” I’m very sorry about that. Life keeps kicking me in the shins, on Mondays! So, I’m turning that recurring nonsense into an actual theme!
Read more... )

November 2025

S M T W T F S
      1
23456 78
9101112131415
16171819202122
23242526272829
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Nov. 13th, 2025 03:33 pm
Powered by Dreamwidth Studios