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. This code may not quite do what it says it does.

This code may not quite do what it says it does.

Scheduled Pinned Locked Moved The Weird and The Wonderful
rubyregex
25 Posts 15 Posters 0 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.
  • W walterhevedeich

    BobJanova wrote:

    Even as it stands if it's a placeholder for something to be added later, it makes sense.

    I agree. But I find it funny to have a method called FinalValidation and does no validation at all. Maybe I just have a weird sense of humor.

    Good judgment comes from experience, and experience comes from bad judgment. Barry LePatner

    ...it's our division that makes us sane(r), and their unity that makes them crazy. Ian Shlasko

    R Offline
    R Offline
    RCoate
    wrote on last edited by
    #8

    Thing is, this code has been in production for as least 12 months.

    P 1 Reply Last reply
    0
    • R RCoate

      Thing is, this code has been in production for as least 12 months.

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #9

      So Final is obviously valid! ;P

      Software rusts. Simon Stephenson, ca 1994.

      1 Reply Last reply
      0
      • R RCoate

        In preparation for some redevelopment work, I was having a look through some legacy code provided by a contractor. I have a feeling that it does not do exactly what the comments suggest it does.

        /// <summary>
        /// Determines whether this person already has an application of that type
        /// </summary>
        /// <param name="appTypeID">The app type ID.</param>
        /// <param name="registrationNumber">The registration number.</param>
        /// <param name="app">The Application</param>
        /// <returns>
        /// 	true if they have an unfinished application of the given type
        /// </returns>
        
        private bool HasApplicationAlready(int appTypeID, int registrationNumber, ref Application app)
        {
        	bool foundOne = false;
        
        	List<Application> matches = new Application().GetApplicationListForContact(DataLocation.OnlineDataBase, Int32.Parse(Profile.RegistrationNumber));
        
        	// We now have all their applications
        	// Find their latest application of the correct AppType
        	Application bestMatch = null;
        	foreach (Application singleApp in matches)
        	{
        		// See if it's the correct type
        		if (singleApp.Application\_type\_id.GetValueOrDefault(0) == appTypeID)
        		{
        			// See if it's the most recent application of that type
        			if (bestMatch == null)
        			{
        				bestMatch = singleApp;
        			}
        			else
        			{
        				// There's already a match, but see if this one is more recent
        				if (singleApp.ApplicationId > bestMatch.ApplicationId)
        				{
        					bestMatch = singleApp;
        				}
        				else
        				{
        					bestMatch = singleApp;
        				}
        			}
        		}
        	}
        	if (bestMatch != null)
        	{
        		app = bestMatch;
        		foundOne = true;
        	}
        	else
        	{
        		foundOne = false;
        	}
        	return foundOne;
        }
        

        Another gem I found was:

        /// <summary>
        /// Does the Final validation.
        /// </summary>
        /// <returns></returns>
        protected bool FinalValidation()
        {
            return true;
        }
        
        C Offline
        C Offline
        chmod2222
        wrote on last edited by
        #10

        Why don't you just do...

        private bool HasApplicationAlready(int appTypeID, int registrationNumber, ref Application app)
        {
        app = Application().GetApplicationListForContact(DataLocation.OnlineDataBase, Int32.Parse(Profile.RegistrationNumber)).OrderByDescending(s=>s.ApplicationId).FirstOrDefault(s=>s.Application_type_id==appTypeID);
        return app==null?false:true;
        }

        ... or something similar?

        J 1 Reply Last reply
        0
        • C chmod2222

          Why don't you just do...

          private bool HasApplicationAlready(int appTypeID, int registrationNumber, ref Application app)
          {
          app = Application().GetApplicationListForContact(DataLocation.OnlineDataBase, Int32.Parse(Profile.RegistrationNumber)).OrderByDescending(s=>s.ApplicationId).FirstOrDefault(s=>s.Application_type_id==appTypeID);
          return app==null?false:true;
          }

          ... or something similar?

          J Offline
          J Offline
          James H
          wrote on last edited by
          #11

          Probably because it is a bitch to debug

          C 1 Reply Last reply
          0
          • J James H

            Probably because it is a bitch to debug

            C Offline
            C Offline
            chmod2222
            wrote on last edited by
            #12

            Not really.. You get null, or the result you wanted, nothing to debug.

            J 1 Reply Last reply
            0
            • C chmod2222

              Not really.. You get null, or the result you wanted, nothing to debug.

              J Offline
              J Offline
              James H
              wrote on last edited by
              #13

              But if it is null rather than the result you expected and you want to dig in a bit to find where it is going wrong it is a nightmare so you end up expanding it out a bit to trace then perhaps collapsing again once it is working (or more likely leaving well alone). While I like the concept of the single line solution until you can step through the parts I can see why you would validly avoid it.

              C 1 Reply Last reply
              0
              • R RCoate

                In preparation for some redevelopment work, I was having a look through some legacy code provided by a contractor. I have a feeling that it does not do exactly what the comments suggest it does.

                /// <summary>
                /// Determines whether this person already has an application of that type
                /// </summary>
                /// <param name="appTypeID">The app type ID.</param>
                /// <param name="registrationNumber">The registration number.</param>
                /// <param name="app">The Application</param>
                /// <returns>
                /// 	true if they have an unfinished application of the given type
                /// </returns>
                
                private bool HasApplicationAlready(int appTypeID, int registrationNumber, ref Application app)
                {
                	bool foundOne = false;
                
                	List<Application> matches = new Application().GetApplicationListForContact(DataLocation.OnlineDataBase, Int32.Parse(Profile.RegistrationNumber));
                
                	// We now have all their applications
                	// Find their latest application of the correct AppType
                	Application bestMatch = null;
                	foreach (Application singleApp in matches)
                	{
                		// See if it's the correct type
                		if (singleApp.Application\_type\_id.GetValueOrDefault(0) == appTypeID)
                		{
                			// See if it's the most recent application of that type
                			if (bestMatch == null)
                			{
                				bestMatch = singleApp;
                			}
                			else
                			{
                				// There's already a match, but see if this one is more recent
                				if (singleApp.ApplicationId > bestMatch.ApplicationId)
                				{
                					bestMatch = singleApp;
                				}
                				else
                				{
                					bestMatch = singleApp;
                				}
                			}
                		}
                	}
                	if (bestMatch != null)
                	{
                		app = bestMatch;
                		foundOne = true;
                	}
                	else
                	{
                		foundOne = false;
                	}
                	return foundOne;
                }
                

                Another gem I found was:

                /// <summary>
                /// Does the Final validation.
                /// </summary>
                /// <returns></returns>
                protected bool FinalValidation()
                {
                    return true;
                }
                
                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #14

                Now all of your applications are belong to us!

                1 Reply Last reply
                0
                • J James H

                  But if it is null rather than the result you expected and you want to dig in a bit to find where it is going wrong it is a nightmare so you end up expanding it out a bit to trace then perhaps collapsing again once it is working (or more likely leaving well alone). While I like the concept of the single line solution until you can step through the parts I can see why you would validly avoid it.

                  C Offline
                  C Offline
                  chmod2222
                  wrote on last edited by
                  #15

                  Well, when I write code, I write it so it doesn't have to be debugged(almost:). Only thing that can go wrong here, would be that the database connection is down, or some sore of foreign key exception. It would result in an exception(with a nice description), but that's a whole different story. My point is, that I would always rather write(and debug) 2 lines of code, than 22, no mather how complicated they may be...but that's just me...

                  A 1 Reply Last reply
                  0
                  • C chmod2222

                    Well, when I write code, I write it so it doesn't have to be debugged(almost:). Only thing that can go wrong here, would be that the database connection is down, or some sore of foreign key exception. It would result in an exception(with a nice description), but that's a whole different story. My point is, that I would always rather write(and debug) 2 lines of code, than 22, no mather how complicated they may be...but that's just me...

                    A Offline
                    A Offline
                    austin hamman
                    wrote on last edited by
                    #16

                    also im not sure the lambda notation existed(in c#) when this code was made. i may be wrong.

                    C 1 Reply Last reply
                    0
                    • A austin hamman

                      also im not sure the lambda notation existed(in c#) when this code was made. i may be wrong.

                      C Offline
                      C Offline
                      chmod2222
                      wrote on last edited by
                      #17

                      The "not so" good old days... :)

                      1 Reply Last reply
                      0
                      • B BobJanova

                        Yes, although if it were virtual, it could make sense. Even as it stands if it's a placeholder for something to be added later, it makes sense. (If public, I'd say it was probably an interface implementation; I often have trivial methods or property getters for that purpose.)

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #18

                        Unless it was filling in an interface (and you have no control over the interface definition; third party, etc.), it's just code bloat. YAGNI: you ain't gonna need it. The best designs have the minimum of moving parts.

                        B 1 Reply Last reply
                        0
                        • L Lost User

                          Unless it was filling in an interface (and you have no control over the interface definition; third party, etc.), it's just code bloat. YAGNI: you ain't gonna need it. The best designs have the minimum of moving parts.

                          B Offline
                          B Offline
                          BobJanova
                          wrote on last edited by
                          #19

                          As non-virtual, I agree. I'm just suggesting what reasonable thing the original code might have been trying to do.

                          1 Reply Last reply
                          0
                          • W walterhevedeich

                            BobJanova wrote:

                            Even as it stands if it's a placeholder for something to be added later, it makes sense.

                            I agree. But I find it funny to have a method called FinalValidation and does no validation at all. Maybe I just have a weird sense of humor.

                            Good judgment comes from experience, and experience comes from bad judgment. Barry LePatner

                            ...it's our division that makes us sane(r), and their unity that makes them crazy. Ian Shlasko

                            B Offline
                            B Offline
                            BrainiacV
                            wrote on last edited by
                            #20

                            At a former place of employment we were told "Names mean nothing." If the function name is "Print" it may not get around to doing any. And for this crapware it was true. Typically functions were not single purpose. They might do 10 different things. These functions would be called by other functions only interested in the output of two of the operations and with the hope that the other eight did not cause any problems. A colleague and I traced a subroutine down 25 levels making calls to these routines, we totally lost what the intended result was supposed to be and never reached bottom.

                            Psychosis at 10 Film at 11

                            1 Reply Last reply
                            0
                            • R RCoate

                              In preparation for some redevelopment work, I was having a look through some legacy code provided by a contractor. I have a feeling that it does not do exactly what the comments suggest it does.

                              /// <summary>
                              /// Determines whether this person already has an application of that type
                              /// </summary>
                              /// <param name="appTypeID">The app type ID.</param>
                              /// <param name="registrationNumber">The registration number.</param>
                              /// <param name="app">The Application</param>
                              /// <returns>
                              /// 	true if they have an unfinished application of the given type
                              /// </returns>
                              
                              private bool HasApplicationAlready(int appTypeID, int registrationNumber, ref Application app)
                              {
                              	bool foundOne = false;
                              
                              	List<Application> matches = new Application().GetApplicationListForContact(DataLocation.OnlineDataBase, Int32.Parse(Profile.RegistrationNumber));
                              
                              	// We now have all their applications
                              	// Find their latest application of the correct AppType
                              	Application bestMatch = null;
                              	foreach (Application singleApp in matches)
                              	{
                              		// See if it's the correct type
                              		if (singleApp.Application\_type\_id.GetValueOrDefault(0) == appTypeID)
                              		{
                              			// See if it's the most recent application of that type
                              			if (bestMatch == null)
                              			{
                              				bestMatch = singleApp;
                              			}
                              			else
                              			{
                              				// There's already a match, but see if this one is more recent
                              				if (singleApp.ApplicationId > bestMatch.ApplicationId)
                              				{
                              					bestMatch = singleApp;
                              				}
                              				else
                              				{
                              					bestMatch = singleApp;
                              				}
                              			}
                              		}
                              	}
                              	if (bestMatch != null)
                              	{
                              		app = bestMatch;
                              		foundOne = true;
                              	}
                              	else
                              	{
                              		foundOne = false;
                              	}
                              	return foundOne;
                              }
                              

                              Another gem I found was:

                              /// <summary>
                              /// Does the Final validation.
                              /// </summary>
                              /// <returns></returns>
                              protected bool FinalValidation()
                              {
                                  return true;
                              }
                              
                              M Offline
                              M Offline
                              Mark AJA
                              wrote on last edited by
                              #21

                              You need to replace the second bit of code with this:

                              protected bool FinalValidation()
                              {
                                var TimeStamp = new Date();
                                if(TimeStamp.getDate()%2==1){
                                  return false;
                                } else {
                                  return true;
                              }
                              

                              :~

                              1 Reply Last reply
                              0
                              • R RCoate

                                In preparation for some redevelopment work, I was having a look through some legacy code provided by a contractor. I have a feeling that it does not do exactly what the comments suggest it does.

                                /// <summary>
                                /// Determines whether this person already has an application of that type
                                /// </summary>
                                /// <param name="appTypeID">The app type ID.</param>
                                /// <param name="registrationNumber">The registration number.</param>
                                /// <param name="app">The Application</param>
                                /// <returns>
                                /// 	true if they have an unfinished application of the given type
                                /// </returns>
                                
                                private bool HasApplicationAlready(int appTypeID, int registrationNumber, ref Application app)
                                {
                                	bool foundOne = false;
                                
                                	List<Application> matches = new Application().GetApplicationListForContact(DataLocation.OnlineDataBase, Int32.Parse(Profile.RegistrationNumber));
                                
                                	// We now have all their applications
                                	// Find their latest application of the correct AppType
                                	Application bestMatch = null;
                                	foreach (Application singleApp in matches)
                                	{
                                		// See if it's the correct type
                                		if (singleApp.Application\_type\_id.GetValueOrDefault(0) == appTypeID)
                                		{
                                			// See if it's the most recent application of that type
                                			if (bestMatch == null)
                                			{
                                				bestMatch = singleApp;
                                			}
                                			else
                                			{
                                				// There's already a match, but see if this one is more recent
                                				if (singleApp.ApplicationId > bestMatch.ApplicationId)
                                				{
                                					bestMatch = singleApp;
                                				}
                                				else
                                				{
                                					bestMatch = singleApp;
                                				}
                                			}
                                		}
                                	}
                                	if (bestMatch != null)
                                	{
                                		app = bestMatch;
                                		foundOne = true;
                                	}
                                	else
                                	{
                                		foundOne = false;
                                	}
                                	return foundOne;
                                }
                                

                                Another gem I found was:

                                /// <summary>
                                /// Does the Final validation.
                                /// </summary>
                                /// <returns></returns>
                                protected bool FinalValidation()
                                {
                                    return true;
                                }
                                
                                G Offline
                                G Offline
                                Gates VP
                                wrote on last edited by
                                #22

                                So that second gem is not totally useless if it's trying to fill out an Interface of some type. In PHP I've done crazy stuff like this b/c PHP only supports functions in Interfaces so you end with "constants" as "functions". As to your first case, this has a full boat of failures. That whole block of if... elseif... else -> do the same thing is actually pretty comical. The fact that it's in a for loop and "finds something" but doesn't break is really just odd. But the kicker to me is that he has sets the app variable and then has a return value of true. Which basically says "hey check the app variable you passed me, I hammered it and returned the app I think I found" Thank goodness it's private and hopefully caused minimal destruction :)

                                1 Reply Last reply
                                0
                                • W walterhevedeich

                                  The second gem was really funny. :laugh:

                                  Good judgment comes from experience, and experience comes from bad judgment. Barry LePatner

                                  ...it's our division that makes us sane(r), and their unity that makes them crazy. Ian Shlasko

                                  T Offline
                                  T Offline
                                  timpattinson
                                  wrote on last edited by
                                  #23

                                  XKCD Deja-Vu Image tags wouldn't work

                                  1 Reply Last reply
                                  0
                                  • R RCoate

                                    In preparation for some redevelopment work, I was having a look through some legacy code provided by a contractor. I have a feeling that it does not do exactly what the comments suggest it does.

                                    /// <summary>
                                    /// Determines whether this person already has an application of that type
                                    /// </summary>
                                    /// <param name="appTypeID">The app type ID.</param>
                                    /// <param name="registrationNumber">The registration number.</param>
                                    /// <param name="app">The Application</param>
                                    /// <returns>
                                    /// 	true if they have an unfinished application of the given type
                                    /// </returns>
                                    
                                    private bool HasApplicationAlready(int appTypeID, int registrationNumber, ref Application app)
                                    {
                                    	bool foundOne = false;
                                    
                                    	List<Application> matches = new Application().GetApplicationListForContact(DataLocation.OnlineDataBase, Int32.Parse(Profile.RegistrationNumber));
                                    
                                    	// We now have all their applications
                                    	// Find their latest application of the correct AppType
                                    	Application bestMatch = null;
                                    	foreach (Application singleApp in matches)
                                    	{
                                    		// See if it's the correct type
                                    		if (singleApp.Application\_type\_id.GetValueOrDefault(0) == appTypeID)
                                    		{
                                    			// See if it's the most recent application of that type
                                    			if (bestMatch == null)
                                    			{
                                    				bestMatch = singleApp;
                                    			}
                                    			else
                                    			{
                                    				// There's already a match, but see if this one is more recent
                                    				if (singleApp.ApplicationId > bestMatch.ApplicationId)
                                    				{
                                    					bestMatch = singleApp;
                                    				}
                                    				else
                                    				{
                                    					bestMatch = singleApp;
                                    				}
                                    			}
                                    		}
                                    	}
                                    	if (bestMatch != null)
                                    	{
                                    		app = bestMatch;
                                    		foundOne = true;
                                    	}
                                    	else
                                    	{
                                    		foundOne = false;
                                    	}
                                    	return foundOne;
                                    }
                                    

                                    Another gem I found was:

                                    /// <summary>
                                    /// Does the Final validation.
                                    /// </summary>
                                    /// <returns></returns>
                                    protected bool FinalValidation()
                                    {
                                        return true;
                                    }
                                    
                                    K Offline
                                    K Offline
                                    KP Lee
                                    wrote on last edited by
                                    #24

                                    This code reads like someone who codes placeholders and doesn't add comments about why he put in a placeholder. It also reads like code written by certain co-workers who can't code, comes running to you for help, mashes your suggestions into unrecognizable pulp and then presents their "work". Leaving you wondering what they were thinking. I'll leave placeholders if I get requirements that are a confusing mishmash of illogical thinking. But I'll add comments about why my code is illogical.

                                    1 Reply Last reply
                                    0
                                    • R RCoate

                                      In preparation for some redevelopment work, I was having a look through some legacy code provided by a contractor. I have a feeling that it does not do exactly what the comments suggest it does.

                                      /// <summary>
                                      /// Determines whether this person already has an application of that type
                                      /// </summary>
                                      /// <param name="appTypeID">The app type ID.</param>
                                      /// <param name="registrationNumber">The registration number.</param>
                                      /// <param name="app">The Application</param>
                                      /// <returns>
                                      /// 	true if they have an unfinished application of the given type
                                      /// </returns>
                                      
                                      private bool HasApplicationAlready(int appTypeID, int registrationNumber, ref Application app)
                                      {
                                      	bool foundOne = false;
                                      
                                      	List<Application> matches = new Application().GetApplicationListForContact(DataLocation.OnlineDataBase, Int32.Parse(Profile.RegistrationNumber));
                                      
                                      	// We now have all their applications
                                      	// Find their latest application of the correct AppType
                                      	Application bestMatch = null;
                                      	foreach (Application singleApp in matches)
                                      	{
                                      		// See if it's the correct type
                                      		if (singleApp.Application\_type\_id.GetValueOrDefault(0) == appTypeID)
                                      		{
                                      			// See if it's the most recent application of that type
                                      			if (bestMatch == null)
                                      			{
                                      				bestMatch = singleApp;
                                      			}
                                      			else
                                      			{
                                      				// There's already a match, but see if this one is more recent
                                      				if (singleApp.ApplicationId > bestMatch.ApplicationId)
                                      				{
                                      					bestMatch = singleApp;
                                      				}
                                      				else
                                      				{
                                      					bestMatch = singleApp;
                                      				}
                                      			}
                                      		}
                                      	}
                                      	if (bestMatch != null)
                                      	{
                                      		app = bestMatch;
                                      		foundOne = true;
                                      	}
                                      	else
                                      	{
                                      		foundOne = false;
                                      	}
                                      	return foundOne;
                                      }
                                      

                                      Another gem I found was:

                                      /// <summary>
                                      /// Does the Final validation.
                                      /// </summary>
                                      /// <returns></returns>
                                      protected bool FinalValidation()
                                      {
                                          return true;
                                      }
                                      
                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #25

                                      this made my day

                                      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