• Sanhadrin (unregistered) in reply to xtremezone
    xtremezone:
    Anonymouse:
    xtremezone:
    * Static means global state which means bad.
    You are obviously either trolling, or you have no idea what "static" means.
    "Static" has different meanings in different languages and platforms. In C# or Java, static basically means global state (i.e,. aside from parameters the only other access it has is to global state i.e., static member variables). There doesn't happen to be any global state here, but that's irrelevant. The point is that there's no good reason for this method to be static and it would be a poorer design for it to be.

    Six things are readily apparent here.

    1. You have absolutely no clue what "global" means.
    2. You have absolutely no clue what "static" means.
    3. You use two languages with very clean, similar, well-defined meanings for the word "static" - and get the definition so completely wrong, it makes me think you were trying to talk about C, and meant to say you were excluding C# and Java from your definition.
    4. You use the argument that making it static would be bad in this specific case because you're introducing "global state" (on a lookup of constant data?), then say that it might not involve global state in this case, but that's irrelevant.. and you actually think you actually made a point somewhere.
    5. You have no clue about design, even in the most basic cases.
    6. You should probably rethink whether you have the knowledge to criticize other people's code when I would think you'd be clueless for a second-year student.
    7. As usual, TRWTF is in the comments.

    In short, there's no way your comments aren't well-crafted jokes, and I bow to your intentionally hilarious mock ignorance.

  • (cs)

    Consider 7) bonus to the "six things" specific to your post. Almost like a global truth that actually needs no individual enumeration. Global - or "static", in Java/C# terms.

  • pikki (unregistered) in reply to Larry

    I hope this is a joke. otherwise AL = 0.5

  • Brian (unregistered) in reply to Larry

    Haha! I hope this is a joke and not meant to be a real solution. I guess it might make sense that Louisiana evaluates to 0.5

  • Brian (unregistered) in reply to pikki

    And what's even funnier is that I didn't even SEE this comment until AFTER I posted!

  • Dave the Snave (unregistered) in reply to Larry

    Doesn't work for "LA"

  • McFly (unregistered) in reply to Larry
    Larry:
    return index('ALAKAZARCA...', $state) / 2;

    Nice try, this could terribly go wrong.

  • Gobzo (unregistered) in reply to Larry
    Larry:
    return index('ALAKAZARCA...', $state) / 2;

    Louisiana screws that up:

    f("LA") = 0.5

  • Petr (unregistered) in reply to Larry

    Nope. If you search for Louisiana, i.e., 'LA', you'll get 0.

  • Shinobu (unregistered)

    TRWTF are all the people who think they're quite something for pointing out Larry's mistake, even though it was already spotted on page one, the third comment after Larry's.

  • Shark8 (unregistered)

    Here's a solution in Ada.

    United_States.ads:

    Package United_States is
    
        -- States are enumerated by their name, with any spaces being replaced
        -- by underscores.
        Type State is
        (	Alabama,	Alaska,		Arizona,	Arkansas,
    	California,	Colorado,	Connecticut,	Delaware,
    	Florida,	Georgia,	Hawaii,		Idaho,
    	Illinois,	Indiana,	Iowa,		Kansas,
    	Kentucky,	Louisiana,	Maine,		Maryland,
    	Massachusetts,	Michigan,	Minnesota,	Mississippi,
    	Missouri,	Montana,	Nebraska,	Nevada,
    	New_Hampshire,	New_Jersey,	New_Mexico,	New_York,
    	North_Carolina,	North_Dakota,	Ohio,		Oklahoma,
    	Oregon,		Pennsylvania,	Rhode_Island,	South_Carolina,
    	South_Dakota,	Tennessee,	Texas,		Utah,
    	Vermont,	Virginia,	Washington,	West_Virginia,
    	Wisconsin,	Wyoming
        );
    
    
        -- Abbriviations are 2-character strings.
        SubType Abbriviation is String(1..2);
    
        -- State codes are abbriviations, there is a one-to-one relationship for
        -- abbriviations and state-names. -- Any change in the [number of]
        -- enumerations for States will force the compiler to reject this constant
        -- until the entries are reconciled.
        State_Code	: Constant Array(State) of Abbriviation:=
          (	"AL",	"AK",	"AZ",	"AR",	"CA",
    	"CO",	"CT",	"DE",	"FL",	"GA",
    	"HI",	"ID",	"IL",	"IN",	"IA",
    	"KS",	"KY",	"LA",	"ME",	"MD",
    	"MA",	"MI",	"MN",	"MS",	"MO",
    	"MT",	"NE",	"NV",	"NH",	"NJ",
    	"NM",	"NY",	"NC",	"ND",	"OH",
    	"OK",	"OR",	"PA",	"RI",	"SC",
    	"SD",	"TN",	"TX",	"UT",	"VT",
    	"VA",	"WA",	"WV",	"WI",	"WY"
          );
    
        -- The exception No_State will be raised if there is an attempt to get a
        -- State from an Abbriviation that is not a State code.
        No_State	: Exception;
    
        -- Function To_State may raise No_State.
        Function To_State( Code : Abbriviation ) Return State;
        
    private
        -- We don't need no private portion for this!
    End United_States;
    

    United_States.adb:

    With
      Ada.Strings.Maps.Constants;
    
    Use
      Ada.Strings.Maps;
    
    Package Body United_States is
    
        -- Apply takes a character mapping and applies it to a string.
        Function Apply( Str : String; Map : Character_Mapping ) Return String is
        begin
    	-- We use the extended return syntax because the return-value is
    	-- is unconstrained and all the information needed for constraint comes
    	-- from the parameter itself.
    	Return Result : String:= Str do
    	    For Index in Result'Range Loop
    		Result(Index):= Value(
    				       Element => Result(Index),
    				       Map     => Map
    				      );
    	    end loop;
    	End Return;
        end Apply;
    
        -- Returns a State when given an abbriviation, otherwise it raises No_State.
        Function To_State( Code : Abbriviation ) Return State is
    	Use  Ada.Strings.Maps;
    	Map : Character_Mapping	Renames Constants.Upper_Case_Map;
    
    	This : Abbriviation:= Apply( Map => Map, Str => Code );
        begin
    	-- Search the State_Codes array for the given abbrivation.
    	For Index in State_Code'Range loop
    	    if This = State_Code(Index) then 
    		Return Index;
    	    end if;
    	end loop;
    
    	-- The state was not found, so...
    	Raise No_State;
        end To_State;
    
        
    End United_States;
    
  • Shark8 (unregistered) in reply to chubertdev
    chubertdev:
    1) Readability 2) Case-insensitivity 3) Background compilation

    It's the future (and also a tangent here). :)

    Ada's got #1 down (it was a design goal, after all), and #2. #3... I'm not sure; I don't think there's anything in the language preventing it, I've just not had a compiler that does it.

  • Shinobu (unregistered)

    What strikes me is how similar ADA looks to VB. I think it could be extremely fruitful to create a cross-breed.

  • Shark8 (unregistered) in reply to Shinobu
    Shinobu:
    What strikes me is how similar ADA looks to VB. I think it could be extremely fruitful to create a cross-breed.

    I do think a good RAD-IDE would be a nice addition to the available tools. I was thinking of writing one in Delphi; and if it were released as freeware [or perhaps shareware], would make a plausible alternative/addition to the few free Ada compilers/toolchains out there.

  • Dan (unregistered) in reply to Larry

    So, Alaska and Louisiana have the same index? Nice try, but no cigar.

  • Russell (unregistered) in reply to Larry

    Great, So Louisiana is 0.5

  • Joe (unregistered) in reply to Larry
    return index('ALAKAZARCA...', $state) / 2;
    get_state_index("AL") == get_state_index("LA")
  • Joe (unregistered) in reply to Shinobu
    Shinobu:
    TRWTF are all the people who think they're quite something for pointing out Larry's mistake, even though it was already spotted on page one, the third comment after Larry's.

    That's me among many. Larry's mistake is a featured comment while the correction isn't. Red flag to a bull.

  • moikmellah (unregistered) in reply to Larry

    Louisiana's index is 0.5?

  • mobile (unregistered) in reply to Larry

    Fails for 'LA', among others.

Leave a comment on “Pick-a-State”

Log In or post as a guest

Replying to comment #:

« Return to Article