Time Not Well-Spent

Here it is, Whiskey-Exemption Thursday, and my weight is on-target so I can even have beer. The purpose of Thursday is to devote an evening to pushing the writing forward, and hang the consequences.

What have I been writing this fine evening? I’ve been trying to come up with the least-objectionable way to emulate Swift’s extensions to Protocols in php. The answer: there is no way.

Begin geek

Coding with php is coding with flint knives and bearskins; the power of php is in its wham-bam-thank-you-ma’am ability to do a quick task and then to go away.

Bless the movers behind php, they’re trying to evolve their language to catch up with the way people are using it these days. If they had known Drupal was coming along, they might not have been so quick-and-dirty before. Drupal might be slightly less awful as a result.

There are design patterns enabled by Swift that I get a little misty contemplating. Being able to add extensions (with executable code!) to protocols is enormously powerful. Having experienced that, I wanted to do the same thing in php, creating a trait “taggable” and having classes that used it automatically injected with the implementation. Injected, not inherited. Ain’t gonna happen.

End geek

At least now I’m writing prose about writing the code rather than writing the code itself. Progress, I guess.


4 thoughts on “Time Not Well-Spent

  1. One bourbon, one scotch, and one beer can make that time better spent ;).
    What you describe at least sounds more engaging than trying to find decoupling capacitors these days. That’s OK, it’ll get better once the trade barriers are raised. Not.


  2. I understand PHP, with more to learn. But want to move to another language. Swift, Python, or….just go straight to whiskey?

    • You really can’t go wrong with the whiskey option. The others depend on what you’re planning to build.

      For simple Web sites, php is still a good choice and always will be. If you want to get fancier, you’ll be using Javascript a lot on the client side and writing your server with Node (which is a javascript-based server) means at least you’re only using one language.

      When I tell people I like to write software in Swift, they assume I’m writing code for iOS/watchOS/tvOS/yourMomOS. But I’m actually not; I’m writing sweet hot data services running on Linux. I have access to slightly-more-advanced tools for that purpose than you do, (or maybe I should say “slightly-more-experimental”), but if you are writing server software, you could start with Kitura (from IBM) or Vapor and enjoy all the power of Swift. I’ve met a couple of the people at IBM working on Kitura and they are really smart mo-fo’s.

      BUT – Swift as a language is a hard-ass. It is designed from the ground up to prevent common, costly mistakes. It took me a bit to grok the “optional” concept, but when I did, I loved it. Swift has come as close as we ever have to “if it compiles, you probably got it right.” That’s all cool, but it’s a major adjustment coming from php or JavaScript.

  3. To be fair to php, after some work I’ve found that traits, despite being a cut-and-paste shorthand, are reasonably useful for injecting capabilities into classes. Ham-fisted but effective all the same.

    Nothing like extending a Swift Protocol, but it’ll get you down the road a way.

Leave a Reply

Your email address will not be published. Required fields are marked *