Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Programming The Internet

Developer Hacks Together Object-Oriented HTML (github.com) 184

An anonymous reader writes: Ever since I started coding, I have always loved object-oriented design patterns. I built an HTML preprocessor that adds inheritance, polymorphism, and public methods to this venerable language. It offers more freedom than a templating engine and has a wider variety of use cases. Pull requests appreciated!
This discussion has been archived. No new comments can be posted.

Developer Hacks Together Object-Oriented HTML

Comments Filter:
  • Spare us. (Score:5, Insightful)

    by HornWumpus ( 783565 ) on Sunday April 30, 2017 @03:36PM (#54330123)

    Another genius, building his own framework, just what the world needs.

    • Re: (Score:2, Insightful)

      by jellomizer ( 103300 )

      Object oriented is very overblown methodology. It has its advantages but overall it just gets in the way, because it takes the effort away from logic and workflow and more towards design. So you often end up with a well designed product that doesn't do what it needs to do.

      • Re:Spare us. (Score:5, Insightful)

        by Dutch Gun ( 899105 ) on Sunday April 30, 2017 @04:09PM (#54330261)

        You know, I disagree vehemently with those who proclaim OO an abject failure. But I'm always a bit bemused with people who feel the need to build OO into everything, whether it needs it or not. The trick, of course, is to use it as it makes sense.

        One of the problems with OO is that poorly designed programs can be much worse to grok the logic and flow of than poorly designed procedural programs, mostly because of how scattered the logic can be throughout an object hierarchy.

        A much more modern* trend is to avoid deep class hierarchies whenever practical, preferring instead to try to use smaller, more reusable objects that are only responsible for a single task, and use composition of objects. This allows you to more easily test each individual component and assure correctness of behavior, and then build on that behavior. These days, a lot of my classes are very shallow, either a single class, or perhaps derived from an interface class to hide implementation details when necessary.

        Class hierarchies still have their place on occasion. There are still cases when you must manage a number of types of related-but-different objects with a lot of common properties. But if you keep this paradigm to a minimum, you'll be a lot happier with OOP, and keep your code more manageable.

        * If you consider the last 15 years or so "modern"

        • Re:Spare us. (Score:4, Interesting)

          by ls671 ( 1122017 ) on Sunday April 30, 2017 @05:00PM (#54330447) Homepage

          Nice post! Most of my utility classes are stateless and contain only static methods. A lot of common logic is in there instead of being in the instantiated class. Inheritance here and there were it makes sense.

          Yet, I still see OO heads around who think; the more it inherits, the more it is OO. The ultimate case is those projects where all classes inherit from an often called "RootObject" that contains all utility methods for the project hence effectively making all utility methods global methods.

          • Yet, I still see OO heads around who think; the more it inherits, the more it is OO.

            You can thank Grady Booch for this. (The other early 90s "gurus" can share some of the blame, but Booch is the worst offender.)

            Compare Alan Kay, who coined the term "object-oriented":

            OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them.

            with Grady Booch, who has some very expensive CASE tools [wikipedia.org] to sell you:

            Object-oriented programming is a method of implementation in which programs are organized as cooperative collections of objects, each of which represents an instance of some class, and whose classes are all members of a hierarchy of classes united via inheritance relationships.

            There are three important parts to this definition: object-oriented programming (1) uses objects, not algorithms, as its fundamental logical building blocks (the “part of” hierarchy [...]); (2) each object is an instance of some class; and (3) classes are related to one another via inheritance relationships (the "is a" hierarchy [...]). A program may appear to be object-oriented, but if any of these elements is missing, it is not an object-oriented program. Specifically, programming without inheritance is distinctly not object-oriented; we call it programming with abstract data types.

            Now to be fair to Booch, he was working at a time when it was believed that analysis was the really hard part of software development. You have to remember that this was a boom era when old paper-based businesses were computerising their processes. There was a

            • by ls671 ( 1122017 )

              Nice, thanks!

            • by ls671 ( 1122017 )

              Also, an easy way to know what you are getting into when you come to help on a project is plug the source code into something like Enterprise Architect and see a graphical representation of the classes, along with the relations.

              I don't use such tools extensively but the graphical snapshot is amazing if only for that.

        • OO isn't a failure. But it isn't often the best tool for the job.

        • You know, I disagree vehemently with those who proclaim OO an abject failure.

          I don't think OO is an abject failure, I think it's more like driving your aircraft carrier down to the mini-market for a candy bar.

          98% of the OO projects I've seen use OO only because someone told someone told someone that they should use OO...and usually for a variety of nebulous reasons that either never made sense in the first place or or because they were just enamored with OO and wanted to strut their OO shit for all to see.

          Nearly all of those projects would have been better off using traditional line

        • by Tablizer ( 95088 )

          OOP and functional programming, and probably other paradigms/methodologies have something in common: there's a right place and way to use them and wrong places and ways. They are helpful in the right place, but can make Yuuuge messes in the wrong place.

          The "art" of programming is often using the right tool for the job: hammers are not "bad", but don't use them to drive in screws. Always remember not to make things hard on future maintainers who may not know about or share your grand code design philosophies

      • It was overblown, but I think it's settling down now. There is a trend towards non-Simula object models (e.g. prototypes), pure (or as pure as possible) functional programming, the actor model, generative programming (e.g. "Modern C++") and so on.

      • By definition a well designed product does what it needs to do. The problem isn't OOP or any other methodology. It is the fact that the industry has been flooded by morons like you that can actually make that statement without realizing how phenomenally stupid it is to say.
      • Object oriented is very overblown methodology. It has its advantages but overall it just gets in the way, because it takes the effort away from logic and workflow and more towards design. So you often end up with a well designed product that doesn't do what it needs to do.

        Exactly.

        Form over Function writ large.

      • Object oriented is very overblown methodology.

        Unless you use CLOS, which very few people do.

      • The problem OO has is that we have forgotten the mindset of the designers.

        Much of the early work in computer languages was born out of the study of human language with formal grammars. I never fully appreciated OO until I started trying to do simple language generation, and OO actually seemed like the perfect model for dealing with verb conjugation groups and irregular verbs. All the examples for beginners about "mammals have four legs", "dogs are mammals", "Fido is a dog" are a bit trivial and aren't actu

      • Just out of curiosity what kind of development do you do and what languages do you use.

        I prefer c++ over c but most of the stuff built on java is probably the worst example of object oriented programing.

           

    • Re: (Score:2, Insightful)

      by Anonymous Coward

      Your response is about as short-sighted as possible. I'm sure you would prefer to have been spared all of the other many geniuses that have tinkered and built across the many generations. Sure, many of those creations have been left on the scrapheap of time, but the remaining ones facilitate and amplify our abilities.

      Go move into a cave in the deep wilderness where you can spare yourself.

    • You are soo right. He should have written it in JavaScript instead

      • by Wuhao ( 471511 )

        The true test of any language is whether it can be self-descriptive, so obviously it should have been written in itself. Also, it doesn't make use of any of the modern breakthroughs in semantic design theory, like functional re-isms, kwanzaa clauses or multilevel reflexisms. You know what? I'll just implement my own and show everyone how it ought to work.

      • Got you covered! [github.com]

    • I particularly like how he is apparently under the impression that HTML is a programming language, since that's the only way object orientation could be desirable or even make sense.

      • by ls671 ( 1122017 )

        Just to be fair, here is the first sentence on the GitHub page (README.md):

        HTML isn't a programming language as such, it's actually a markup language...

      • by gfxguy ( 98788 )
        I disagree. If there's one area that OO blows other types of programming out of the water it's user interfaces. After cursory reading, I don't know that this is a great implementation and, honestly, mostly you're using some server side script to generate the HTML (and that script, IMO, is better suited to OO as I believe most interfaces and XML like structures are better suited to OO). I'd rather be using python on the back-end anyway. However, if you were writing complicated static pages (I don't know
  • by Anonymous Coward on Sunday April 30, 2017 @03:37PM (#54330131)

    It's really, really CLASSLESS to post stories about your own projects. That said, it's a preprocessor, that's all. Not seeing how this is different from say, PHP?

    • I hope not. I'm still polishing my Python script for scraping Slashdot comment history. When I publish it on GitHub, I'll be submitting it to Slashdot. Anonymously, of course.
    • Not seeing how this is different from say, PHP?

      Maybe this won't suck. :-)

  • by Anonymous Coward on Sunday April 30, 2017 @03:43PM (#54330145)

    This repo hasn't had a commit in 2 years, why is this interesting now?

  • by __aaclcg7560 ( 824291 ) on Sunday April 30, 2017 @03:44PM (#54330147)
    I use the Pelican [getpelican.com] static website generator for my static websites. I got Python [python.org] to massage the data and Jinja2 [pocoo.org] for the template engine. I see no need to us OOP on the backend. If I did, Python can do OOP.
  • by Anonymous Coward

    It says:

    Latest commit d79333a on Jul 22, 2015 @Michaelkielstra Michaelkielstra Commented.

    That's 2 years ago, so I wouldn't call this news. Also, it's just a template engine, so it isn't new either.

  • by johanw ( 1001493 ) on Sunday April 30, 2017 @03:48PM (#54330173)

    that describes the structure of a document. It is not a graphical design language, as most webdesigners think, or a programming language as most webdevelopers think. It is as much of either as LaTeX.

  • venerable language (Score:4, Interesting)

    by phantomfive ( 622387 ) on Sunday April 30, 2017 @03:50PM (#54330179) Journal
    I'm suspicious of anyone who calls HTML 'venerable.' They should call it, "notorious" or "infamous," maybe, "expectorant." Marc Andreesen points out [zerobugsan...faster.net] there are just problems with it, and I can't see OOP fixing things.

    So, I looked at this guy's project, and it's better than I expected. The major problem it solves is: "how do you avoid repeating yourself, while still keeping things flexible?" The common approach right now is to either throw it into a CSS library (like Bootstrap) or write Javascript to produce the HTML. The latter idea there sounds like a joke but it's not.

    In comparison, this lets you break things into components (like React does), but without any cost to the front end. Overall a good approach, but likely to get lost in the noise of a thousand other web frameworks.
    • by Cederic ( 9623 )

      I'm suspicious of anyone who calls HTML 'venerable.' They should call it, "notorious" or "infamous," maybe, "expectorant." Marc Andreesen points out there are just problems with it, and I can't see OOP fixing things.

      Hate it all you like, you have to admit that it's been a success by pretty much any measure. Tim got the basics pretty sound.

      • you have to admit that it's been a success by pretty much any measure

        It wins in exactly one measure: popularity. It's a huge pain to get things on the page where you want them.

        • by Dog-Cow ( 21281 )

          It's a huge pain to get things on the page where you want them.

          You're literally using it wrong.

    • I took a look at it and to me it appears to be a similar idea to the functionality of XSLT. Also a mandatory XKCD reference. [xkcd.com]

    • I'm suspicious of anyone who calls HTML 'venerable.' They should call it, "notorious" or "infamous," maybe, "expectorant." Marc Andreesen points out [zerobugsan...faster.net] there are just problems with it, and I can't see OOP fixing things.

      So, I looked at this guy's project, and it's better than I expected. The major problem it solves is: "how do you avoid repeating yourself, while still keeping things flexible?" The common approach right now is to either throw it into a CSS library (like Bootstrap) or write Javascript to produce the HTML. The latter idea there sounds like a joke but it's not.

      In comparison, this lets you break things into components (like React does), but without any cost to the front end. Overall a good approach, but likely to get lost in the noise of a thousand other web frameworks.

      I'm suspicious of anyone who calls HTML a "LANGUAGE", let alone "venerable".

      Despite the "L" in the acronym, HTML is NOT a computer Language. It lacks several of the criteria. Must I list them for a Slashdot audience?

      • Must I list them for a Slashdot audience? If you've been here long enough to remember a time when the answer to that question would have been "no", you've been here long enough to know the answer is "yes".

        • Ugh... HTML quote fail... Whatever, you know which part of that you wrote and which part was written by me...
          • Ugh... HTML quote fail... Whatever, you know which part of that you wrote and which part was written by me...

            I fingered it out, LOL!

            And actually, I was busy when I posted that, so decided to use the snarky comment to hide the fact that I was too lazy to find a reference to "What is necessary for something to be called a computer language?"

            Hey, "Snarky" without citation works for all the damn ACs; so why can't I use it once in awhile? ;-)

            • Besides, Stack Overflow agrees with me that HTML, despite the "L", is NOT a Programming Language (pretty much for the reasons I was thinking).

              http://stackoverflow.com/quest... [stackoverflow.com]

              • I'm not sure I'd use "Stack Overflow agrees with me" as a supporting argument. I mean, in this case you're not wrong, but... Just be careful with it :)
                • I'm not sure I'd use "Stack Overflow agrees with me" as a supporting argument. I mean, in this case you're not wrong, but... Just be careful with it :)

                  They seem to be fairly level-headed for an internet forum. Sure, every forum has flamewars and trolls; but in my experience, they don't seem to be that bad...

                  Maybe I've just been lucky, eh?

                  Oh, and another reason I continue to use capitalization instead of HTML "font tags" for stuff, especially italicizing, is that, when I am home on my iPad, iOS insists on changing the "i" to "I" in that tag, and I can never remember if that tag is case-sensitive or not. My HTML knowledge is very weak; so don't flame me if

                  • For starters... ugh... HTML editing on iOS... not without a hardware keyboard!!! As for WebKit on iOS 9, it's up to the developers of a given site to decide what they want to support and make it work; I do find it ironic that MacRumors has issues on that particular platform, though.

                    One commonly missed detail about web development is that web developers must write a single codebase that works everywhere. We don't get to fork our code for Windows, Mac, Linux, iOS, Android, and BlackBerry. We don't get to pr
  • I don't see any OO (Score:4, Interesting)

    by Half-pint HAL ( 718102 ) on Sunday April 30, 2017 @04:09PM (#54330257)

    The Github page doesn't give any examples that look like OO to me, which is A) not surprising, because what the hell would an OO markup language look like and B) very surprising, given that the whole DOM is OO from the ground up in modern rendering engines.

    Anyway, on a tangent...

    I see no real call for OO in web rendering, but the one thing I think is missing from HTML is the ability to parameterise things like column widths etc. Why cant I call column 1's width "x" and ask the renderer to make column 2's width "3x"? Or use these parameters across tables, so that the columns in table 1, table 2 and table 3 are all the same size?

    I know this can be done with CSS, but in order to do that, I need to choose a particular size -- I can say "I don't care about the actual size, but these 3 things should all be as big as each other."

    • by darkain ( 749283 )

      column sizing with X, and then X*3 or whatever for the next is actually possible now with flex-box. Instead of setting actual sizes, you can just set ratios (example, width:10px on first, width:30px on the next), and set the columns to flex-grow:1. This will grow them out proportionally to fill up their parent container width, instead of staying the fixed input value. Essentially it works like old HTML table formatting, but with quite a bit more granularity, and each row can optionally be different proporti

  • We already have enough features.

  • Java? KILL IT! (Score:1, Insightful)

    by Anonymous Coward

    Made in Java? Born dead, hahahaha!

  • Spare us, there are various JS packages that allow you to attach objects and methods to HTML tags.

  • as in, pull my finger?
  • "I built an HTML preprocessor that adds inheritance, polymorphism, and public methods to this venerable language"

    HTML isn't a programing language. It's markup language, and it doesn't need you polluting it with bullshit like this.

  • XSLT still seems like the better choice to me, as it's geared towards taking actual machine readable data (XML) and transforming it into HTML. With your system you would have to already be outputting your data as HTML for it to be further transformed into the final markup.

  • Didn't they get the message, that you now use javascript to create

    asdf

    by writing html("p").html("b").content("asdf"), so that the website takes longer to render and doesn't work with browsers which disabled javascript?

  • Comment removed based on user account deletion

Life in the state of nature is solitary, poor, nasty, brutish, and short. - Thomas Hobbes, Leviathan

Working...