Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. What was I thinking

What was I thinking

Scheduled Pinned Locked Moved The Weird and The Wonderful
database
20 Posts 16 Posters 24 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Corporal Agarn

    While editing a much tweaked process that I wrote, I found this T-SQL:

    DECLARE @NumDays INT;
    SELECT @NumDays =
    CASE
    WHEN @Client = 'Client1' THEN @DaysBack
    WHEN @Client = 'Client2' THEN @DaysBack
    ELSE @DaysBack
    END;

    This is what happens when you go from actual numbers to a variable, without checking the code. :-O

    P Offline
    P Offline
    peterchen
    wrote on last edited by
    #4

    djj55 wrote:

    What was I thinking

    about Client3's perky assets?

    ORDER BY what user wants

    1 Reply Last reply
    0
    • C Corporal Agarn

      While editing a much tweaked process that I wrote, I found this T-SQL:

      DECLARE @NumDays INT;
      SELECT @NumDays =
      CASE
      WHEN @Client = 'Client1' THEN @DaysBack
      WHEN @Client = 'Client2' THEN @DaysBack
      ELSE @DaysBack
      END;

      This is what happens when you go from actual numbers to a variable, without checking the code. :-O

      G Offline
      G Offline
      G James
      wrote on last edited by
      #5

      My personal favorite from C#. Someone was testing the value of a boolean variable.

      if (someBooleanVariable == true)
      return true;
      else
      return false;

      Later they refactored it to this thinking it was an improvement. :)

      return someBooleanVariable == true ? true : false;

      C J 2 Replies Last reply
      0
      • G G James

        My personal favorite from C#. Someone was testing the value of a boolean variable.

        if (someBooleanVariable == true)
        return true;
        else
        return false;

        Later they refactored it to this thinking it was an improvement. :)

        return someBooleanVariable == true ? true : false;

        C Offline
        C Offline
        Chris Maunder
        wrote on last edited by
        #6

        You mean they missed the totally obvious contraction to

        return someBooleanVariable ? true : false

        They should hang their head in shame!

        cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

        3 A J N 4 Replies Last reply
        0
        • C Chris Maunder

          You mean they missed the totally obvious contraction to

          return someBooleanVariable ? true : false

          They should hang their head in shame!

          cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

          3 Offline
          3 Offline
          33deepak
          wrote on last edited by
          #7

          well, it should be just

          return someBooleanVariable

          :-D

          C J 2 Replies Last reply
          0
          • 3 33deepak

            well, it should be just

            return someBooleanVariable

            :-D

            C Offline
            C Offline
            Chris Maunder
            wrote on last edited by
            #8

            :rolleyes:

            cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

            1 Reply Last reply
            0
            • G G James

              My personal favorite from C#. Someone was testing the value of a boolean variable.

              if (someBooleanVariable == true)
              return true;
              else
              return false;

              Later they refactored it to this thinking it was an improvement. :)

              return someBooleanVariable == true ? true : false;

              J Offline
              J Offline
              Jonathan C Dickinson
              wrote on last edited by
              #9

              G James wrote:

              Later they refactored it to this thinking it was an improvement. :)

              return someBooleanVariable == true ? true : false;

              That's pretty poor refactoring, it should have been:

              interface IBooleanConverter {
              bool BooleanToBoolean(bool value);
              }

              class BooleanConverter : IBooleanConverter {
              public BooleanToBoolean(bool value) {
              return value == true ? true : false;
              }
              }

              interface IBooleanConverterFactory {
              IBooleanConverter CreateBooleanConverterFactory();
              }

              class ConfigurationBooleanConverterFactory : IBooleanConverter {
              public IBooleanConverter CreateBooleanConverter() {
              return (IBooleanConverter)
              Activator.CreateInstance(ConfigurationManager.AppSettings["Types.BooleanConverter"]);
              }
              }

              static class BooleanConverterFactoryFactory {
              public IBooleanConverterFactory CreateBooleanConverterFactory() {
              return (IBooleanConverterFactory)
              Activator.CreateInstance(ConfigurationManager.AppSettings["Types.BooleanConverterFactory"]);
              }
              }

              // ...

              return BooleanConverterFactoryFactory.CreateBooleanConverterFactory().CreateBooleanConverter().BooleanToBoolean(someBooleanVariable == true ? true : false);

              It is clear that this is more maintainable. There is currently this method in our code-base because some [one] of our developers is so bad that we need to hold his hand through everything:

              public static T As(this object obj) {
              return obj as T;
              }

              Yes guys, an extension method that replicates a keyword.

              He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chinese Proverb] Jonathan C Dickinson (C# Software Engineer)

              S R 2 Replies Last reply
              0
              • J Jonathan C Dickinson

                G James wrote:

                Later they refactored it to this thinking it was an improvement. :)

                return someBooleanVariable == true ? true : false;

                That's pretty poor refactoring, it should have been:

                interface IBooleanConverter {
                bool BooleanToBoolean(bool value);
                }

                class BooleanConverter : IBooleanConverter {
                public BooleanToBoolean(bool value) {
                return value == true ? true : false;
                }
                }

                interface IBooleanConverterFactory {
                IBooleanConverter CreateBooleanConverterFactory();
                }

                class ConfigurationBooleanConverterFactory : IBooleanConverter {
                public IBooleanConverter CreateBooleanConverter() {
                return (IBooleanConverter)
                Activator.CreateInstance(ConfigurationManager.AppSettings["Types.BooleanConverter"]);
                }
                }

                static class BooleanConverterFactoryFactory {
                public IBooleanConverterFactory CreateBooleanConverterFactory() {
                return (IBooleanConverterFactory)
                Activator.CreateInstance(ConfigurationManager.AppSettings["Types.BooleanConverterFactory"]);
                }
                }

                // ...

                return BooleanConverterFactoryFactory.CreateBooleanConverterFactory().CreateBooleanConverter().BooleanToBoolean(someBooleanVariable == true ? true : false);

                It is clear that this is more maintainable. There is currently this method in our code-base because some [one] of our developers is so bad that we need to hold his hand through everything:

                public static T As(this object obj) {
                return obj as T;
                }

                Yes guys, an extension method that replicates a keyword.

                He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chinese Proverb] Jonathan C Dickinson (C# Software Engineer)

                S Offline
                S Offline
                Sentenryu
                wrote on last edited by
                #10

                my eyes bleed and my head hurts X| it's so dificult to believe i'm seeing so well structured shit-code :doh:

                I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                J 1 Reply Last reply
                0
                • S Sentenryu

                  my eyes bleed and my head hurts X| it's so dificult to believe i'm seeing so well structured shit-code :doh:

                  I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                  J Offline
                  J Offline
                  Jonathan C Dickinson
                  wrote on last edited by
                  #11

                  Sentenryu wrote:

                  it's so dificult to believe i'm seeing so well structured sh*t-code

                  And a lesson has been learnt about GOF design patterns :D.

                  He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chinese Proverb] Jonathan C Dickinson (C# Software Engineer)

                  R 1 Reply Last reply
                  0
                  • C Corporal Agarn

                    While editing a much tweaked process that I wrote, I found this T-SQL:

                    DECLARE @NumDays INT;
                    SELECT @NumDays =
                    CASE
                    WHEN @Client = 'Client1' THEN @DaysBack
                    WHEN @Client = 'Client2' THEN @DaysBack
                    ELSE @DaysBack
                    END;

                    This is what happens when you go from actual numbers to a variable, without checking the code. :-O

                    T Offline
                    T Offline
                    Tomz_KV
                    wrote on last edited by
                    #12

                    This could make a good business sense when some decisions for different clients have not been made. Make the code structure ready and wait for the changes. I recently worked on a project in which different user role was supposed to have a different permission. But the decision was not made. Therefore all roles were assigned the same permission during development. Sometimes, the decision is never made. Several years later, when you look at the code, you would question why you did that.

                    TOMZ_KV

                    1 Reply Last reply
                    0
                    • C Chris Maunder

                      You mean they missed the totally obvious contraction to

                      return someBooleanVariable ? true : false

                      They should hang their head in shame!

                      cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                      A Offline
                      A Offline
                      Andrew Rissing
                      wrote on last edited by
                      #13

                      You're not following good form. You should use CONSTANTS for things that like.

                      return someBooleanVariable ? Boolean.Parse(Boolean.TrueString) : Boolean.Parse(Boolean.FalseString);

                      ;)

                      C 1 Reply Last reply
                      0
                      • A Andrew Rissing

                        You're not following good form. You should use CONSTANTS for things that like.

                        return someBooleanVariable ? Boolean.Parse(Boolean.TrueString) : Boolean.Parse(Boolean.FalseString);

                        ;)

                        C Offline
                        C Offline
                        Chris Maunder
                        wrote on last edited by
                        #14

                        You mean

                        return someBooleanVariable.ToString() == Boolean.TrueString? Boolean.Parse(Boolean.TrueString) : Boolean.Parse(Boolean.FalseString);

                        Right?

                        cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                        A 1 Reply Last reply
                        0
                        • C Chris Maunder

                          You mean

                          return someBooleanVariable.ToString() == Boolean.TrueString? Boolean.Parse(Boolean.TrueString) : Boolean.Parse(Boolean.FalseString);

                          Right?

                          cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                          A Offline
                          A Offline
                          Andrew Rissing
                          wrote on last edited by
                          #15

                          Good call. :D

                          1 Reply Last reply
                          0
                          • J Jonathan C Dickinson

                            Sentenryu wrote:

                            it's so dificult to believe i'm seeing so well structured sh*t-code

                            And a lesson has been learnt about GOF design patterns :D.

                            He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chinese Proverb] Jonathan C Dickinson (C# Software Engineer)

                            R Offline
                            R Offline
                            Ranjan D
                            wrote on last edited by
                            #16

                            I hope you are not one of those gang of 4 guys :omg:

                            Ranjan.D

                            1 Reply Last reply
                            0
                            • 3 33deepak

                              well, it should be just

                              return someBooleanVariable

                              :-D

                              J Offline
                              J Offline
                              James Lonero
                              wrote on last edited by
                              #17

                              It took this long to get this simple return?

                              1 Reply Last reply
                              0
                              • C Chris Maunder

                                You mean they missed the totally obvious contraction to

                                return someBooleanVariable ? true : false

                                They should hang their head in shame!

                                cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                J Offline
                                J Offline
                                Jecc
                                wrote on last edited by
                                #18

                                Chris Maunder wrote:

                                You mean they missed the totally obvious contraction to

                                return someBooleanVariable ? true : false

                                They should hang their head in shame!

                                No! Wrong!

                                return (someBooleanVariable == true)

                                1 Reply Last reply
                                0
                                • C Chris Maunder

                                  You mean they missed the totally obvious contraction to

                                  return someBooleanVariable ? true : false

                                  They should hang their head in shame!

                                  cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                  N Offline
                                  N Offline
                                  Nagy Vilmos
                                  wrote on last edited by
                                  #19

                                  Not good enough:

                                  if (((Boolean)someBooleanVariable).equals(true)) {
                                  return someBooleanVariable == true ? someBooleanVariable : false;
                                  } else {
                                  return someBooleanVariable == false ? someBooleanVariable : true;
                                  }

                                  it's called the Irish Method - to be sure, to be sure, to be sure.


                                  Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                                  1 Reply Last reply
                                  0
                                  • J Jonathan C Dickinson

                                    G James wrote:

                                    Later they refactored it to this thinking it was an improvement. :)

                                    return someBooleanVariable == true ? true : false;

                                    That's pretty poor refactoring, it should have been:

                                    interface IBooleanConverter {
                                    bool BooleanToBoolean(bool value);
                                    }

                                    class BooleanConverter : IBooleanConverter {
                                    public BooleanToBoolean(bool value) {
                                    return value == true ? true : false;
                                    }
                                    }

                                    interface IBooleanConverterFactory {
                                    IBooleanConverter CreateBooleanConverterFactory();
                                    }

                                    class ConfigurationBooleanConverterFactory : IBooleanConverter {
                                    public IBooleanConverter CreateBooleanConverter() {
                                    return (IBooleanConverter)
                                    Activator.CreateInstance(ConfigurationManager.AppSettings["Types.BooleanConverter"]);
                                    }
                                    }

                                    static class BooleanConverterFactoryFactory {
                                    public IBooleanConverterFactory CreateBooleanConverterFactory() {
                                    return (IBooleanConverterFactory)
                                    Activator.CreateInstance(ConfigurationManager.AppSettings["Types.BooleanConverterFactory"]);
                                    }
                                    }

                                    // ...

                                    return BooleanConverterFactoryFactory.CreateBooleanConverterFactory().CreateBooleanConverter().BooleanToBoolean(someBooleanVariable == true ? true : false);

                                    It is clear that this is more maintainable. There is currently this method in our code-base because some [one] of our developers is so bad that we need to hold his hand through everything:

                                    public static T As(this object obj) {
                                    return obj as T;
                                    }

                                    Yes guys, an extension method that replicates a keyword.

                                    He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chinese Proverb] Jonathan C Dickinson (C# Software Engineer)

                                    R Offline
                                    R Offline
                                    Rob Grainger
                                    wrote on last edited by
                                    #20

                                    Ah, now I see what people mean by maintainable code - code that will require maintenance, and hence pay the bills for years to come. Genius.

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups