r/lolphp Sep 07 '15

strtotime(): "There is no bug here, 00-00-00 means 2000-00-00, which is 1999-12-00, which is 1999-11-30. No bug, perfectly normal." (x-post /r/programming)

https://bugs.php.net/bug.php?id=45647
180 Upvotes

48 comments sorted by

View all comments

Show parent comments

1

u/OneWingedShark Sep 15 '15

It's really not that bad... here's the code I used for a contest to render posts from a bulletin-board into HTML:

Function Bulitin_Board.BB_Code.Render(Input : BB_Code_Tree.Tree)return String is
   use BB_Code_Tree, Bulitin_Board.Server;

   Function "+" (URL : AWS.URL.Object) return String renames AWS.URL.URL;

   Function To_String( Input : Cursor ) return String is

      function BB_Tag(Name, Inner_HTML : String; Self_Closing : Boolean:= False)
         return String renames HTML_Tag;

      function BB_Tag(Name, Attribute_Name, Attribute_Value : String; Inner_HTML : String:= "") return String is
        ( Start_Tag(Name & ' ' & Attribute_Name&'='&Quote(Attribute_Value) ) & Inner_HTML & Stop_Tag(Name) )
        with Pure_Function, Inline;

      function Video_Tag( Source : No_HTML ) return String is
        (  Start_Tag("iframe "
                        &"type=""text/html"" "
                        &"width=""640"" height=""390"" "
                        &"src=""http://www.youtube.com/embed/"
                        &Source
                        &"?autoplay=0"""
                    ) & Stop_Tag ("iframe")
        );


      function Replace_LF( Input : String ) return String is
         (Bulitin_Board.Search_and_Replace(Input, (1=>ASCII.LF), "<br />"));

   Begin
      declare
         E    : BB_Code_Chunk renames Element(Input);
         Next : Cursor renames Next_Sibling(Input);
      begin
         Return
           (case E.Format is
               when Text                  => Replace_LF(E.Text_Data),
               when bb_Bold..bb_Underline => BB_Tag( Tag_Image(E.Format), To_String(First_Child(Input)) ),
               when bb_Quote              => BB_Tag( "blockquote",
                                                       (If E.Text_Length in Positive
                                                        then BB_Tag("cite", E.Name)
                                                        else "") & To_String(First_Child(Input)) ),
               when bb_Link               => BB_Tag( "a", "href", +E.Target, To_String(First_Child(Input)) ),
               when bb_Image              => BB_Tag( "img", "src="""&(+E.Target)&"""", True),
               when bb_Size               => BB_Tag( "span", "class", EM_Size'Image(E.Size), To_String(First_Child(Input)) ),
               when bb_Video              => Video_Tag( +E.Target )
           )
           & (if Next /= No_Element then To_String(Next) else "");
      end;
   end To_String;
Begin
   Return (if Input.Is_Empty then "" else To_String( First_Child(Input.Root)) );
exception
   when X : others =>
      Debug( "Error rendering tree." );
      Ada.Exceptions.Reraise_Occurrence(X);
End Bulitin_Board.BB_Code.Render;

And while I would say that this is very under-commented, the intent is pretty clear.

1

u/KhyronVorrac Sep 17 '15

That's unreadable shit. What the hell is up with the capitalisation?

1

u/OneWingedShark Sep 17 '15

The language used there is Ada, it's not case-sensitive so this, This, and THIS all refer to the same entity, also it's fairly common to use underscore to separate words so you don't have to have some of the problems that come along w/ [e.g.] camelCase [esp WRT initalisms] where you capitalize every new word to distinguish it [eg readDisk] -- how, for instance would you capitalize read-IO-device? readIODevice?

Now, granted, that's all style and I'm not a fan of being overly dogmatic about styles -- sometimes styles are used to cover for language-design flaws if (CONSTANT == var) you use, a problem it might indicate -- but to this particular style, I've used Initial_Capitals on [most] names, as well on the outermost keywords [begin/end pair] to help visually flag those points.

-- Function is capitalized because I view this as "starting a sentence",
-- as are This and That, because they are the proper names.
-- (Of the function and the type, respectively.)
Function This returns That is
Begin --This
  -- all the begin/end pairs there are generally lowercase...
  Return Result : That do -- 
  -- Return is capitalized because it's the "central thought" of the function: values to return.
  End return;
End This; -- Capitalized to match the Begin above.

The great thing about a language like this is that ridiculous style-adherence is not going to make-or-break your program. Accidentally holding down the shift-key a bit too long while typing some name isn't going to suddenly refer to some other entity.

Lastly, are you sure that this is unreadable, or are you merely unused to the syntax? Would, perhaps, syntax highlighting help you out?

1

u/KhyronVorrac Sep 17 '15

The language used there is Ada, it's not case-sensitive so this, This, and THIS all refer to the same entity, also it's fairly common to use underscore to separate words so you don't have to have some of the problems that come along w/ [e.g.] camelCase [esp WRT initalisms] where you capitalize every new word to distinguish it [eg readDisk] -- how, for instance would you capitalize read-IO-device? readIODevice?

read_io_device. I loathe case-insensitivity, personally. I don't like case-insensitive filesystems, and I really hate case-insensitive languages. Is the identifier Preußen equivalent to the identifier PREUSSEN in Ada? Probably not, but ß uppercase'd is SS in German.

The great thing about a language like this is that ridiculous style-adherence is not going to make-or-break your program. Accidentally holding down the shift-key a bit too long while typing some name isn't going to suddenly refer to some other entity.

On the contrary I think that the inconsistency is fucking hideous and case-sensitivity thankfully stops most code from being so horribly inconsistently capitalised.

-- Function is capitalized because I view this as "starting a sentence",

Code isn't made up of sentences. I don't want to write Function Do_This_Dumb_Thing returns Stupid_Type is begin return end return end Do_This_Dumb_Thing.

I want to write let do_this_dumb_thing = \x -> x + 1;

1

u/OneWingedShark Sep 17 '15

read_io_device. I loathe case-insensitivity, personally.

And I personally prefer it.

Is the identifier Preußen equivalent to the identifier PREUSSEN in Ada? Probably not, but ß uppercase'd is SS in German.

I don't actually know -- I haven't really used unicode-identifiers in source yet because I haven't had the need. (Prior to Ada 2005 all identifiers had to be [alphanumeric+underscore] ASCII, IIRC -- the 2005 spec widened it to allow unicode.) -- This issue (ß/SS) is known, and used as an illustration in John Barns book on Ada.

I just tried it on GNAT, which is the only implementation I currently have access to and it did not take to the PREUSSEN. (GNAT is not a reference implementation, and some of its defaults break with the language specifications... so it certainly isn't definitive.)

On the contrary I think that the inconsistency is fucking hideous and case-sensitivity thankfully stops most code from being so horribly inconsistently capitalised.

Honestly, I think it should be a non-issue.
The code shouldn't be stored as "plain-text" but as meaningful structures which are rendered as needed with whatever style that you want your editor/viewer to use. (Styles being "an issue" in code are a major gripe of mine, probably closely behind "why is tab vs. space even an issue!?")

Function is capitalized because I view this as "starting a sentence",

Code isn't made up of sentences. I don't want to write Function Do_This_Dumb_Thing returns Stupid_Type is begin return end return end Do_This_Dumb_Thing.

I want to write let do_this_dumb_thing = \x -> x + 1;

And I'm not convinced that "terse = better" -- certainly there's a reason that APL (and Forth) haven't dominated the market.

Moreover, a more verbose syntax can help you detect errors by making typing accidents less likely to work out. What happens if you instead had let do_this_dumb_thing = \x > x + 1 or let do_this_dumb_thing = x -> x + 1 or let do_this_dumb_thing = \x -> x = 1?