My first look at an inherited project



  • So I'm about to start a project in my spare time for charity; literally for starving children in Africa.

    Anyway, about ten actual seconds in, I see this:

    $nrs_lookup = array(  1 => "01",  2 => "02",  3 => "03",  4 => "04",  5 => "05",  6 => "06",  7 => "07",  8 => "08",  9 => "09", 10 => "10",
                         11 => "11", 12 => "12", 13 => "13", 14 => "14", 15 => "15", 16 => "16", 17 => "17", 18 => "18", 19 => "19", 20 => "20",
                         21 => "21", 22 => "22", 23 => "23", 24 => "24", 25 => "25", 26 => "26", 27 => "27", 28 => "28", 29 => "29", 30 => "30",
                         31 => "31", 32 => "32", 33 => "33", 34 => "34", 35 => "35", 36 => "26", 37 => "37", 38 => "38", 39 => "39", 40 => "40" );
    

    disgunbegud.gif


  • Winner of the 2016 Presidential Election

    is this PHP?
    Because if it was then even if I ignore the obvious WTF (and the str_pad-Function) I would still not understand why the keys are numerated! It does that on it's own! 😃
    Oh Wait, it would start at 0... wich begs the question (not really) why the 0 is left out!

    Filed Under: PHP can't be TRWTF! There are still devs that program like that IN PHP! They are TWOTWRWTF



  • @Kuro said:

    wich begs the question (not really) why the 0 is left out!

    To save memory space, obviously. Duh.



  • Yeah, this is PHP. Of course, I'm actually not very nice for posting this here because a friend of a friend did this for free for them, in 2008. Now I'm doing it for free, but the difference is I'm a PHP professional.

    Having spent a few more minutes perusing the code, I've decided to scrap the whole thing and do a new site from scratch. The project is hosted on a server of the "el cheapo" persuasion; thankfully though it's a 5.3 box so I can use Composer and a decent framework for it.



  • Worse, it isn't even correct for the values it handles. 36 => "26".


  • BINNED

    PHP: Enabling "programmers" who should be doing something else for 20 years.



  • Thanks for catching that!



  • @toon said:

    difference is I'm a PHP professional.

    No offence, but a what, you say?

    Filed under: Just because you're a whore doesn't mean you're a good fuck



  • @Kuro said:

    Oh Wait, it would start at 0... wich begs the question (not really) why the 0 is left out!

    Billy Corgan is not involved in this project.



  • @toon said:

    I've decided to scrap the whole thing and do a new site from scratch.

    Make certain that you'll observe SOLID.


  • Discourse touched me in a no-no place

    @Nagesh said:

    Make certain that you'll observe SOLID.

    I think that that could mean something else in relation to PHP…

    Filed under: no link, no embedded image, no sirreee!



  • PHP is a fairly terrible language, yes, but just like a certain John-Cleese-turned-into-a-newt, it got better. Yes, they're still dealing with some of the stupid decisions of yesteryear and even Rasmus accepts the mistakes that were made. 5.3 deprecated, and 5.4 removed, a number of the old stupid feature.

    But one thing you can't take away from PHP is the relative ubiquity of it. Show me another language that is as present 'everywhere'. Getting PHP hosting really isn't difficult, but getting good PHP hosting is as difficult as getting good PHP applications.

    One thing that intrigues me, for all the "PHP is TRWTF" comments, how come there aren't so many PHP TDWTF entries? We see more in other languages than we do of PHP.


  • Discourse touched me in a no-no place

    @Arantor said:

    How come there aren't so many PHP TDWTF entries?

    Probably the PHP is busy triggering flashbacks… but here's one.

    We've got a web application that we maintain1 which is a catalogue of web services. It's OK, but no perfect piece of software. (Discourse is better as a web application.) It's all written in Ruby-on-Rails with the data stored in MySQL and Solr2. As part of its tasks, it allows registered users to submit a new service by uploading the WSDL description of that service3.

    The WSDL parser is in PHP.

    It's a disaster. It craps out on about 20% of all inputs, and we completely lack the expertise to maintain it. The code was inherited from a project years ago that we weren't even involved in. (We also lack the effort to replace it.)

    The contortions to fit an old PHP application into a RoR are worse, as it can't go on the same VM because of (reasonable) paranoia. As such, the PHP part sits in a weird firewall situation where sometimes a network admin “optimises” things and stops things from working entirely (either by preventing the WSDL documents from reaching the parser, or by walling off the rest of the webapp from it).

    It's not the only awful PHP app that we have (the most awful is the SPARQL query engine implemented in PHP!) but the others at least don't affect anyone outside the team in practice.


    1 I emphasise that I did not write one line of this thing.
    2 That we have both of these data stores and they get out of synch with each other and the searching people do is disjoint between them… that's one of my big gripes with it all. But that's not this WTF…
    3 The thing that's on my longer-term TODO list is taking a leaf out of the Stack Overflow and LinkedIn playbooks and adding mechanisms to encourage users to provide enhanced metadata for their service descriptions. Right now, description curation is a massive problem because Users Don't.



  • That's a pretty nasty one, I sympathise with you. 😦

    I have seen enough PHP WTFs over the years but as the years go by, it's less and less PHP being TRWTF and simply PEBKAC on the part of the programmer.



  • Like the finite simple groups, all the PHP WTFs have been classified. PHP is the monster.



  • And like any good piece of vitriol, there is another to counter it. PHP certainly isn't perfect but it's getting better. It's certainly not the monster it used to be.



  • I'm a quarter through it, and your article is pretty WTF so far.



  • I didn't write it... ;) Just putting it out there as an equally well written counter to the originally linked article.

    PHP certainly isn't perfect. And a lot of its crap is historical - which is being phased out of the language, while limiting the damage of backwards compatibility breaks.



  • Sorry, I didn't mean to imply your authorship.

    But it's not as good. It doesn't cover even 25% of the original article. And it defends a lot of indefensible constructs. A good 25% of the defense is "he doesn't understand loosely typed languages" -- which is BS, since the author was promoting Python and Ruby over PHP for the same tasks.



  • shrug So much of it comes back to how PHP was designed to be as low-barrier-to-entry as possible, for good and bad, and it's paying for its mistakes, and has done over and over and over.

    I like how, for example, the article's author complains about the use as CGI except that on shared hosting (where most PHP really happens), there are limits to what you can do about that, and on any real system you'll be stacking it behind nginx with PHP-FPM anyway (which is a built in feature to run a pool of interpreters)

    Then there's the point about how the whole PHP 'accelerators' market existed. Sure, it did. Still does if you want to handle encrypted scripts, too. Zend Guard and ionCube being the typical examples. But guess what? Precompiling scripts and running the compiled version is a core feature now.

    Then we have the claim about how there's only one php.ini file. Again, that's not entirely the case and other options are available, especially important on shared hosting which is where PHP's real market is and pretty much always will be.

    Then it talks about using insulating apps from each other and with different versions of PHP? HostGator et al don't seem to have a problem with any of this...

    So yes, PHP has a lot of flaws. But so many of them are because of poor developer practice. And when you can get cheap hosting for any arbitrary Python or Ruby app, in the couple of dollars a month bracket, lemme know.



  • be glad that it's not what I'm dealing with:



  • You have my condolences.



  • @Arantor said:

    You have my condolences.

    Thanks. It's getting a lot better.



  • digitalocean.com. 5$ a month for a basic virtual machine. 10$ for something that can run Discourse. Features one-click installers for the "common" stacks.

    I'll be using them to deploy a Haskell app, hopefully in two weeks. Of course, I'll report any WTFs I find.



  • @Captain said:

    I'll report any WTFs I find.

    @Captain said:
    Haskell app

    [insert obligatory "found it" because you mentioned what language you used]



  • @toon said:

    Having spent a few more minutes perusing the code, I've decided to scrap the whole thing and do a new site from scratch.

    @toon said:
    Thanks for catching that!

    So you are planning to reuse that lookup table? ;-)


  • Discourse touched me in a no-no place

    @Arantor said:

    Show me another language that is as present 'everywhere'.

    It seems to be the VB of yesteryear...


  • BINNED

    Excel Macro's of the days of yor. Or Access "applications" made by a user.



  • I'm still mystified how you would use Haskell for a website.



  • @dhromed said:

    I'm still mystified how you would use Haskell for a website.

    There is a web page for almost anything.



  • fuck


  • Discourse touched me in a no-no place

    @dhromed said:

    I'm still mystified how why you would use Haskell for a website.

    FTFY


  • BINNED

    I've used Haskell for writing internal tools in the past, and it's worked well for me. Generally, by the time I fix all of the type errors the compiler bitches about, I end up with a program that just works. The one problem I had with Haskell is that it's not a mature language, and the developers are OK with making breaking changes in libraries.

    That said, I'm looking at Yesod for a personal project.

    Yesod is a full-featured web framework. It takes a modular approach to development, so many parts of the framework such as Hamlet and Persistent are available as standalone packages. However, put together, Yesod provides you with solutions for templating, routing, persistence, sessions, JSON, authentication/authorization, and more. Yesod's major guiding principle is type safety: if your application compiles, it works.


  • BINNED

    @Arantor said:

    PHP was designed to be as low-barrier-to-entry as possible

    As I alluded to earlier, this is not a good thing. When you make things easier for marginal developers, poor developer practices are the inevitable result.



  • Oh, I'm certainly not complaining about that. I have to deal with that small detail most days. But the language has recognised this is the case and is doing something about it. It's growing up as a language, though it'll never be the standard that the people here generally expect because of backwards compatibility concerns.



  • @Arantor said:

    HP was designed to be as low-barrier-to-entry as possible

    It wasn't.

    Or they accidentally forgot to add protection and help for new users.



  • @antiquarian said:

    As I alluded to earlier, this is not a good thing.

    It is a good thing, but PHP wasn't designed for novice users. It wasn't designed for advanced users either. It wasn't designed.


  • Considered Harmful

    @Arantor said:

    P was designed to be as low-barrier-to-entry as possible

    Well, it's not NP... or is it?



  • NPHP

     


  • BINNED

    @dhromed said:

    It is a good thing

    Or they accidentally forgot to add protection and help for new users

    Designing a programming language to be novice-friendly is only a bad thing if it's the only (or even primary) design goal. Novices who are encouraged to just code without learning anything (cough VB cough) tend to remain novices as a result and write WTFs. What we want is for novices to become competent and seasoned developers. Python encourages this. Haskell requires it (or your programs won't compile).



  • @antiquarian said:

    What we want is for novices to become competent and seasoned developers.

    What we want is for novices to understand that they're novices and can't sell their programming services to an employer. We don't want them to not code, we don't want them to stop, and we don't want to make it really hard to start.

    Haskell is the vim of languages, so let's not go there.

    Making your stack difficult to set up and your language obtuse and hard to use is unfortunately much easier than fostering a proper culture.

    I liken it to art: you're arguing that pencils are too easy to use and the influx of shit artists is too great. But by and large, people who are bad know they're bad, and don't try to sell their shit. The primary difference being that it's really easy to see whether art is very good. It's very hard to determine if a program or code is very good.


  • BINNED

    @dhromed said:

    I liken it to art: you're arguing that pencils are too easy to use and the influx of shit artists is too great. But by and large, people who are bad know they're bad, and don't try to sell their shit. The primary difference being that it's really easy to see whether art is very good. It's very hard to determine if a program or code is very good.

    I think we're talking past each other so let's try something else. Instead of pencils, consider the projector. Artists working from a picture will use a projector to project the picture they are working from onto the canvas to make drawing/painting easier. That's fine if you already know how to draw. It's not so good if you don't and you're using it because you don't know how to draw.

    Haskell is the vim of languages, so let's not go there.

    I really meant to use Python more than Haskell as an example of what to do. They do have the proper culture though I'm not sure how they did it. Haskell is definitely not for everyone, though I'll close with an anecdote and a quote, both from IRC via Haskell Weekly News:

    Ferdirand: I was TA for a C++ programming course aimed at 1st year physics once.
    Some girl asked for help "i wrote pseudo-code but I cannot translate it to C++".
    Her pseudo-code was valid haskell. I cried.

    cmccann: C++ is dual to Haskell in a sense: it's much too hard for the average programmer
    to use safely, but they do anyway with disastrous results; whereas Haskell isn't actually
    that difficult to use but people don't even try


  • ♿ (Parody)

    @dhromed said:

    I liken it to art: you're arguing that pencils are too easy to use and the influx of shit artists is too great. But by and large, people who are bad know they're bad, and don't try to sell their shit.

    That's true. But for some reason, they're still able to get government grants to produce their (sometimes literally) shit. This analogy is really terrible. Past masters (as viewed now) were often ignored or thought to be not very good.

    @dhromed said:

    It's very hard to determine if a program or code is very good.

    There are different ways to measure, but the main problem with this, which is actually similar to art, is that a lot of it is subjective. You can apply statistics to usability data, but that doesn't mean that some people will struggle greatly with it.


  • ♿ (Parody)

    @antiquarian said:

    Haskell isn't actually that difficult to use but people don't even try

    I've been meaning to learn a functional language forever, but haven't found the time. Functional paradigms often creep into my OO / procedural code.



  • @antiquarian said:

    Instead of pencils, consider the projector. Artists working from a picture will use a projector to project the picture they are working from onto the canvas to make drawing/painting easier. That's fine if you already know how to draw. It's not so good if you don't and you're using it because you don't know how to draw.

    Your projector analogy makes no sense to me. I thought you were trying to decrease the extent to which you thought we're talking past each other!

    @antiquarian said:

    an anecdote and a quote

    Meh. They're fun quotes, but I can tear those down in a number of ways i.e. explain why I don't think they mean anything, but that wouldn't be productive and I don't feel like it.



  • @boomzilla said:

    they're still able to get government grants to produce their (sometimes literally) shit.

    Yeah, I'm reminded of some cringingly bad art sold for $3000, but sadly I don't remember the link.

    @boomzilla said:

    a lot of it is subjective. You can apply statistics to usability data, but that doesn't mean that some people will struggle greatly with it.

    Yeah, but by the time you're in the subjective bit, you're already at the good enough level.

    The girl who draws this works at a game studio:

    (http://len-yan.tumblr.com/post/88484533457/quick-random-doodle-probably-half-an-hour)

    You can subjectively argue whether you like it or not, but clearly we're already firmly in the Quality Art region.

    This is the kind of quality you need for work in that area (well, a little less would do fine as well). If you make shit art, you're not going to get a job there. The problem isn't the shit, the problem is that the shit isn't recognized and the shitshitters have jobs and get money for their shit.



  • Man, oneboxing is kinda fucked here.



  • @boomzilla said:

    I've been meaning to learn a functional language forever, but haven't found the time. Functional paradigms often creep into my OO / procedural code.

    I once tried to write a C++ library that would let you write LISP-Style C++. The code looked really nice, but the C++ compiler hated me and optimized away some weird nested class constructor calls or whatever it was I had concocted.

    Something like [code]int five = Inc(Inc(Inc(Inc(1))));[/code] never returned 5. In the end I gave up.


  • BINNED

    @dhromed said:

    antiquarian said:
    Instead of pencils, consider the projector. Artists working from a picture will use a projector to project the picture they are working from onto the canvas to make drawing/painting easier. That's fine if you already know how to draw. It's not so good if you don't and you're using it because you don't know how to draw.

    Your projector analogy makes no sense to me. I thought you were trying to decrease the extent to which you thought we're talking past each other!

    I'll elaborate. If you don't know how to draw, you can project a photo onto a larger piece of paper, trace over what you see, and you'll have a decent drawing. However, your drawing will at best be only as good as the photo you used and will be subject to the limits of your camera. For example, if you're working from a picture of a large building, the lines will be off due to the optics of the camera. Also, you won't be able to draw something that's right in front of you because that takes a different set of skills that aren't developed by tracing over a projection. On the other hand, if you take an art class, they'll start by having you draw something that's right in front of you and you will learn those skills.

    So how does this relate to software development? Consider the old VB6 development environment. Paula Bean could drag and drop some items from the GUI, put in some code in function stubs created by the GUI, and have a working application. Writing maintainable code in a larger-scale project on the other hand, requires skills that Paula wouldn't have been able to acquire just by working in Visual Studio. Had she started using Python instead, the culture would have guided her in learning those skills.



  • @antiquarian said:

    Had she started using Python instead, the culture would have guided her in learning those skills.

    "use Python" == "art class"?

    You'll have to elaborate a bit further.
    I would like to do you one better:
    @antiquarian said:

    Had she started using Python instead

    ...she would have had no application because she might have given up, regardless of her programming capabilities.

    At least, that's my Haskell story. Looked like a fun, compact language, but pretty high barrier to entry-- and that's not just the language, that's everything around it.


Log in to reply