r/shittyprogramming • • Feb 11 '20

<%=quality comments; --!> When you dont know what .ToString() is

Post image
216 Upvotes

15 comments sorted by

10

u/SmotherMeWithArmpits Feb 12 '20

To be fair tostring truncated leading zeros if it's a number. Why do I know this? Because my phone numbers 4 digits used to start with zeros and ups.com would remove them during job applications.

I did email them and they got it fixed :)

6

u/TheSalamiKing Feb 12 '20

All depends on what formatter you provide the tostring

41

u/[deleted] Feb 11 '20

fuck being paid by the line, this is prime paid by the character material.

-11

u/thirdegree Feb 11 '20

That's .Net for you!

11

u/Famous_Profile Feb 12 '20

Show me on the doll where C# hurt you

2

u/thirdegree Feb 12 '20

vaguely gestures everywhere

18

u/jarfil Feb 11 '20 edited Dec 02 '23

CENSORED

12

u/NewDark90 Feb 11 '20

Like, it would make sense if it was done with generics. Maybe this is some copy paste work here

1

u/form_d_k Jun 03 '20

Senior architect speaking! Here's a highly-optimized more robust solution for you:

// Pending Copyright, 2020
/***
 * INTERNAL ONLY. Do not share with external partners.
 */

using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using System.ComponentModel;
using System.Runtime;
using System.Dynamic;

using System.Performance.Internal.Server.Runtime;
namespace System.Performance.Internal.Runtime.Client
{
    /// <summary>
    /// Contains all server-side & client-side 
    /// runtime optimizations.
    /// </summary>
    /// <typeparam name="T">A type of communication endpoint such as email or pager.
    /// </typeparam>
	internal class RontimeUtilties<T>
        where T : ISrvr, 
                  IClnt
    {
        internal bool debug;

        public bool Debug
        {
            get
            {
                return this.debug;
            }
            set
            {
                this.debug = value;
            }
        } = true;

        #region public bool FastToString()

        /// <summary>
        /// A performance-oriented version of ToString().
        /// </summary>
        /// <returns>
        /// A bool.
        /// </returns>
        /// <remarks>
        /// When the variable this.Debug == true,
        /// returns an exception if any problem occurs.
        /// When this.Debug is false, calls the workaround function
        /// so the program doesn't crash.
        /// </remarks>
        public string FastToString() 
        {
            dynamic expObjOutput = new ExpandoObject();
            String @string = null;
            expObjOutput.Output = @string;

            try
            {
                // Declare i & assign null to it.
                int ?i = null;

                // Use dynamic to avoid build errors.
                dynamic tcInt = TypeDescriptor
                    .GetConverter(i.GetType());
                @string = (tcInt as TypeConverter)
                    .ConvertTo(i, typeof(String)) as String;

                return true.ToString();

            }
            catch (Exception e)
            {
                Console.Out.WriteLineAsync(
                    $@"Error in class {nameof(expObjOutput)}:"
                    + $@"the variable "
                    + nameof(expObjOutput.Output)
                    + $@" is invalid.").Start();

                if (this.Debug == true)
                    throw;
                else if (this.Debug == false)
                {
                    return RontimeUtilties<T>
                        .NullOrInvalidValueWorkaround(expObjOutput);
                }

                return Boolean.TrueString;
            }

            return (Boolean.FalseString);

            #endregion public bool FastToString()
        }
    }
}

0

u/[deleted] Feb 11 '20

[deleted] — view deleted comment

8

u/Zatherz Feb 12 '20

this has nothing to do with var, it's just templated $"" strings

1

u/SDJMcHattie Feb 13 '20

You do know which sub we’re in, right?

0

u/[deleted] Feb 12 '20

[deleted] — view deleted comment

9

u/VoxUmbra Feb 12 '20

The virgin "innovative" code:

  • Reinvents the wheel
  • Is prone to bugs
  • Tries to prove how smart the author is

The Chad readable code:

  • Uses pre-established conventions
  • Clearly communicates the intent of the author
  • Gets the job done

FTFY

1

u/microdotwav Feb 20 '20

Isn't the point of the chad vs virgin meme to have the actually useful thing be "virgin"?

-6

u/[deleted] Feb 12 '20 edited May 27 '20

I have to poop... Help me