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 2 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.
  • 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