A Caught Return

by in CodeSOD on

When John takes on a new codebase, he always looks for low-risk ways to learn the code by changing it. Things like beefing up the unit tests, tracking down warnings that have been left to languish, minor quality-of-life changes.

Well, a few years back, John inherited some C# code, and started tracking down some warnings. That lead to this method.


Free From Space

by in CodeSOD on

Henrik H is contracting with a client, and that client uses a number of other contractors. Some of them have… interesting approaches to problem solving.

For example, one of the servers is a Windows server, which stores a lot of temp files on the D: drive. So someone needed to write a C# function that would check the available space, and if it exceeded some threshold, delete the temp files.


Zero Failures

by in CodeSOD on

Parsing strings into other data types is always potentially fraught, what with the edge cases and possible errors. This is why most languages provide some kind of helper methods that try and solve those hard problems.

C# has a number of them. One, for example, would be Int32.Parse- it attempts to parse a string into an integer, and throws an exception when it fails. Similarly, there's an Int32.TryParse function, which avoids throwing an exception and returns an error code instead.


Here We Go Again

by in Error'd on

This week has been mostly centered on a holiday for the USians. In the era of online retail and the global dominance of Amazon, the notion of "Black Friday" seems to have spread further than the harvest festival itself. The practice of mass national migrations thankfully has not.

Migrating Maia exclaims "Oh wow, I can change my flight for a fee of only [AMOUNT]! What a deal!"


Classic WTF: Worse Than Failure

by in Best of… on
So, it's a holiday in the US, and I'll be honest: the way I pick my holiday posts is by hitting the "Random Article" button until something fun pops out. And this time around, it gave me something to be thankful for: that this remains "The Daily WTF" and not… something Worse Than Failure. --Remy

Final Update: thankfully this is all nothing but an embarrassing memory.

As you can probably tell by now, The Daily WTF is now named Worse Than Failure. Don’t worry – nothing else is changing – it’s still the same ole’ WTF.


Lines of Code

by in CodeSOD on

Brittany is a game developer, and frequently ends up working on contracts for other companies. One company wanted her to add some features to their trading-card based game, and they offered her an option: she could either do a fixed-rate contract or a paid-per-line contract.

Brittany went with the fixed-rate.


Limited Space

by in CodeSOD on

While XML is a complicated specification, and incredibly bureaucratic and verbose, it's also powerful enough that many languages, from Java to Python, have XML helper classes in their standard library.

C# is one of those languages. But just because there's a built-in library (and a wealth of 3rd party libraries with richer features) doesn't stop people from reinventing the wheel.


Constant Adventure

by in CodeSOD on

We know that June 7th, 2006 was a long day for Jonas, Rusty's long-ago predecessor. We know that, because Jonas made a big commit that day. It was the day someone told him to stop using magic numbers and switch to named constants.

    public static final float FLOAT_0NE_HUNDRED_FIFTY = 150.0f;
    public static final float FLOAT_EIGHT = 8.0f;
    public static final float FLOAT_EIGHTY_FIVE_HUNDREDTH = 0.85f;
    public static final float FLOAT_EIGHT_HUNDREDTH = 0.08f;
    public static final float FLOAT_EIGHT_HUNDRED_SIX = 806.0f;
    public static final float FLOAT_TEN_HUNDREDTH = 0.10f;
    public static final float FLOAT_ELEVEN = 11.0f;
    public static final float FLOAT_ELEVEN_HUNDREDTH = 0.11f;
    public static final float FLOAT_FIFTEEN = 15.0f;
    public static final float FLOAT_FIFTY = 50.0f;
    public static final float FLOAT_FIFTY_NINE_HUNDREDTH = 0.59f;
    public static final float FLOAT_FIVE = 5.0f;
    public static final float FLOAT_FIVE_HUNDRED = 500.0f;
    public static final float FLOAT_FIVE_HUNDRED_SIXTY = 560.0f;
    public static final float FLOAT_FIVE_TENTH = 0.5f;
    public static final float FLOAT_FIVE_THOUSANDTH = 0.005f;
    public static final float FLOAT_FORTY = 40.0f;
    public static final float FLOAT_FOURTEEN_HUNDREDTH = 0.14f;
    public static final float FLOAT_FOUR_HUNDRED_EIGHTY = 480.0f;
    public static final float FLOAT_FOUR_HUNDRED_NINETY = 490.0f;
    public static final float FLOAT_FOUR_TENTH = 0.4f;
    public static final float FLOAT_NINE = 9.0f;
    public static final float FLOAT_NINETY = 90.0f;
    public static final float FLOAT_NINETY_EIGHT_HUNDREDTH = 0.98f;
    public static final float FLOAT_NINETY_NINE_HUNDREDTH = 0.99f;
    public static final float FLOAT_NINE_HUNDREDTH = 0.09f;
    public static final float FLOAT_ONE_DOT_TWO_TENTH = 1.2f;
    public static final float FLOAT_ONE_HUNDRED = 100.0f;
    public static final float FLOAT_ONE_HUNDREDTH = 0.01f;
    public static final float FLOAT_ONE_HUNDRED_NINETY_FIVE = 195.0f;
    public static final float FLOAT_ONE_TENTH = 0.1f;
    public static final float FLOAT_SEVENTY = 70.0f;
    public static final float FLOAT_SEVEN_HUNDREDTH = 0.07f;
    public static final float FLOAT_SIX_HUNDREDTH = 0.06f;
    public static final float FLOAT_SIX = 6.0f;
    public static final float FLOAT_SIXTEEN = 16.0f;
    public static final float FLOAT_TEN = 10.0f;
    public static final float FLOAT_THIRTY = 30.0f;
    public static final float FLOAT_THREE_HUNDRED = 300.0f;
    public static final float FLOAT_THREE_TENTH = 0.3f;
    public static final float FLOAT_TWELVE = 12.0f;
    public static final float FLOAT_TWENTY = 20.0f;
    public static final float FLOAT_TWENTY_FIVE = 25.0f;
    public static final float FLOAT_TWENTY_FIVE_THOUSANDTH = 0.0025f;
    public static final float FLOAT_TWO = 2.0f;
    public static final float FLOAT_TWO_HUNDREDTH = 0.02f;
    public static final float FLOAT_TWO_TENTH = 0.2f;

    public static final int INT_EIGHT = 8;
    public static final int INT_ELEVEN = 11;
    public static final int INT_FIFTEEN = 15;
    public static final int INT_FIFTY = 50;
    public static final int INT_FIVE = 5;
    public static final int INT_FORTY = 40;
    public static final int INT_FOUR = 4;
    public static final int INT_FOURTEEN = 14;
    public static final int INT_NINE = 9;
    public static final int INT_NINETEEN_HUNDRED = 1900;
    public static final int INT_ONE_HUNDRED = 100;
    public static final int INT_ONE_HUNDRED_FIFTY_SEVEN = 157;
    public static final int INT_ONE_THOUSAND = 1000;
    public static final int INT_ONE_THOUSAND_EIGHT = 1008;
    public static final int INT_ONE_THOUSAND_ELEVEN = 1011;
    public static final int INT_ONE_THOUSAND_FIVE = 1005;
    public static final int INT_ONE_THOUSAND_FOUR = 1004;
    public static final int INT_ONE_THOUSAND_NINE = 1009;
    public static final int INT_ONE_THOUSAND_SEVEN = 1007;
    public static final int INT_ONE_THOUSAND_SIX = 1006;
    public static final int INT_ONE_THOUSAND_THIRTEEN = 1013;
    public static final int INT_ONE_THOUSAND_THIRTY_FIVE = 1035;
    public static final int INT_ONE_THOUSAND_THIRTY_FOUR = 1034;
    public static final int INT_ONE_THOUSAND_THREE = 1003;
    public static final int INT_ONE_THOUSAND_TWELVE = 1012;
    public static final int INT_ONE_THOUSAND_TWO = 1002;
    public static final int INT_SEVEN = 7;
    public static final int INT_SIX = 6;
    public static final int INT_SIXTEEN = 16;
    public static final int INT_SIXTY_THREE = 63;
    public static final int INT_TEN = 10;
    public static final int INT_THIRTEEN = 13;
    public static final int INT_THIRTY = 30;
    public static final int INT_THIRTY_EIGHT = 38;
    public static final int INT_THIRTY_ONE = 31;
    public static final int INT_TWENTY_FIVE = 25;
    public static final int INT_THREE = 3;
    public static final int INT_THREE_HUNDRED_SIXTY_FIVE = 365;
    public static final int INT_TWELVE = 12;
    public static final int INT_TWENTY = 20;
    public static final int INT_TWENTY_FOUR = 24;
    public static final int INT_TWO = 2;
    public static final int INT_TWO_HUNDRED = 200;
    public static final int INT_TWO_HUNDRED_SEVENTY = 270;

    public static final long LONG_ONE = 1L;
    public static final long LONG_SEVEN = 7L;
    public static final long LONG_TWO = 2L;

Archives