6 ms·
Show HN: PHP API Bindings for Open Brewery DB
Howdy! I'm a recent PHP convert after a decade of laughing at PHP memes on r/programmerhumor, and wanted to dive a bit deeper into the language by building something practical with it. I also love beer and decided to combine the two by building a PHP library for the Open Brewery DB API (https://openbrewerydb.org/ https://openbrewerydb.org/). Hope someone finds it useful!
- nrichardson 3y agoCheck OpenBreweryClient.php for comment rot, e.g. references to Blizzard and ‘game’ APIs.
- hipadev23 3y ago[flagged]
- edmundsauto 3y agoThis line of comments is toxic but so close to being constructive that I have to comment. You had an opportunity to help a php newb get better. Your comment even did the work to present the ways to improve the code. It’s all undercut by the tone, however, which really sounds like you’re just shitting on OP. It would have been easier to just call out ways OP can improve than to shit on their work. Why take the extra effort to be mean?
- hipadev23 3y ago[flagged]
- edmundsauto 3y agoThe overall tone is dismissive. If I were new to php and read this, my only takeaway would be “this is awful you are not cut out to program why even bother.” The last line is also mean - you don’t need to diminish the scope for someone’s first project. Was the purpose of your comment to help this person improve? Or to show your superiority? It came across as the latter but was so close to being really awesome if the negativity werent present.
- pvg 3y agoIt’s a dismissive put down with a side of chatGPT swipery. You can’t comment on other people’s work like that, especially in a show HN. Criticism has to be constructive rather than tropey. Take a look at https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html and https://news.ycombinator.com/showhn.html https://news.ycombinator.com/showhn.html
- joeymckenzie 3y agoThank you for the feedback! I'm still fairly new to PHP, coming from the .NET/TypeScript world. Unfortunately, it wasn't ChatGPT generated and I'm well aware there's still a lot to learn. I'm always looking for ways to improve, so if you'd like to create a few issues, I'd be more than happy to address them and get the chance to dig deeper into PHP.
- edmundsauto 3y agoYou have a great attitude and if you can take the constructive criticism and ignore the rest, you will have a fast growth curve. Nice work and thanks for being courageous enough to post imperfect code. I’ve used php since 2004 and wouldn’t be this brave.
- joeymckenzie 3y agoThank you, I really appreciate it! It can definitely be daunting putting something out into the wild for people to see, but I've found the constructive criticism (in most cases) that comes with the territory can only help improve whatever it is I'm working. Gotta take it all in stride.
- hobs 3y agoNot being a php-er, it sounds like a good linter/editor support would probably get you a long way - I like using the Jetbrains stuff and they usually have a useful page like https://www.jetbrains.com/help/phpstorm/php-code-quality-tools.html https://www.jetbrains.com/help/phpstorm/php-code-quality-too... which walks you through the things that people would nitpick you about.
- joeymckenzie 3y agoAbsolutely agree, on the todo list. Only using PHPStan/Pint at the moment, though I've looked a bit into the other tools as well and definitely want to get them involved soon to help me as a I go. I've been a loyal JetBrains guy for almost a decade, and I gotta say... PHPStorm is up there with IntelliJ competing for best IDE. I use Rider daily at work, so any chance I get to use familiar tooling in another language feels like it helps level out the learning curve a bit.
- joeymckenzie 3y agoThanks for pointing that out. Definitely some leftover copy/pasta from another learning library I was writing for PHP. Updated!
- mgkimsal 3y agoWelcome to PHP! :) Glad to have you join the community!
- euoia 3y agoI run and pub and brewery in the east of England that was established in 1991. We have lots of breweries around here and none of them seem to be on openbrewerydb. I have joined the Discord and will see if I can contribute some info.
- askonomm 3y agoHeck yeah, more PHP things here please!
- baggachipz 3y agoThis looks great! Is there an open database of beers/ratings similar to Untappd? Bar/brewery owners I know hate Untappd because of the exorbitant fees they charge.
- joeymckenzie 3y agoNone that I'm personally aware of, Open Brewery DB seems to be most complete dataset of breweries I've found out in the wild so far though just for breweries.
- munk-a 3y agoI work extensively in PHP, am rather fond of it, and have built out quite a lot of tooling in the language. The reputation it has from the early 00s is quite mismatched against its current capabilities and I'm glad to see more people picking it up. The API you've put together is modern and follows a lot of the best practices so thanks for your hard work!
- pphysch 3y agoI don't think it's capabilities were ever in doubt -- it had early adoption because it had capabilities that other languages didn't have/express well, not because it was a particularly nice language to work with. The OPs code is quite readable and I wouldn't mind maintaining it (vastly better than the real-world legacy PHP code I have to maintain), but my main takeaway is "this is like Python with Java syntax" (interestingly the opposite of Kotlin, i.e. Java with Python syntax).
- joeymckenzie 3y agoAppreciate the feedback! I'll be the first to admit I have a tendency to C#/Java-ify code in languages that I attempt to learn (could definitely argue it's a bad habit) due to nearly a decade of working with them. Any advice you might have to make things a bit more idiomatic to modern PHP? Always looking to improve the code however I can.
- munk-a 3y agoIt's my opinion (but one I strongly hold) that good maintainable code is modularized and clean - with strict types and a heavy emphasis on clean contracts between different components (since in an organization/large open source project many people will be contributing in parallel). It relies heavily on common patterns and styling for easy recognition and tries to do things in the least sneaky way possible. If you're aiming for this state of a codebase you'll lean heavily towards Object/Modular oriented styles which strongly resemble Java/C++ etc - even languages that express them in dramatically different manners (like OCaML) end up looking really familiar when built in a sustainable manner. There is a common visual expectation we have around code that promotes readability[1] and we'll form code in most languages to match that common visual expression. This is actually one reason I decidedly dislike python - since it's visual expression is encoded into the syntax evaluation of the language itself. Anyways the TL;DR is that, IMO, clean maintainable code looks like clean maintainable code and the language only minorly impacts this appearance. 1. That isn't to say this is necessarily the best visual expression - it could just have been chosen early on and then just ingrained in us all.
- slt2021 3y agomodern PHP has become indistinguishable from Java, which begs a question: why PHP, when Python is less verbose, if you want less verbosity and scripting. and Java is same verbosity + has more mature (and arguably more performant) runtime + benefits of statically compiled language and rich library ecosystem? what is selling point of PHP, that python and java don't fit into ?? (lets not even mention javascript/node with its runtime)
- endofreach 3y agoI can think of many reasons, but for starters (obviously focused on web dev): - pythons dependency management is insane. For PHP Composer seems a bit aged, but compared to all others i've had to work with in the last decade, it's still the best to work with - the PSRs are pretty good & make the whole language seem like a good big framework - php can actually be very fast nowadays - decent type system (if you're unlike me any don't hate working with annotations, you'll be even happier) - since php8 (especially 8.1 and 8.2) there were a lot of major new things (property promotion, named parameters) On the contrary: - php.ini must die. It's not causing much issues for me anymore, but it just doesn't feel right. I don't know why, but no matter how much i work in other languages, even if i really enjoy them (eg. go), nothing when starting from scratch for web server stuff, i always end up going with PHP. Whenever it's "just web" on the serverside, nothing beats php. Especially when you ignore the bad stuff and look at really well designed modern projects based on php8. I just think it might be time to fork php8, start with a new name & get rid of all the old, dirty stuff that's still there for some weird & non-realistic backward compatibility. If anyone is up for that task, i am happy to help & finance parts of that.
- aaviator42 3y agoI agree with a lot of your comment, but what's wrong according to you with php.ini? I've always found it a really handy way to customise the behaviour of my php installs and apps, and I've actually learnt a fair bit from just reading through the comments and following the links it contains.
- 3y ago
- languagehacker 3y agoI'm not sure that this is the right use of the term "binding". Maybe more of an SDK?
- joeymckenzie 3y agoProbably. I tend to use both interchangeably, though probably incorrectly. I think either could describe the use case here, in the sense the library is binding to the API for Open Brewery DB. SDK could fit the bill here, and that's ultimately the hope if I get it to a place where it would be the "official" way to use the API via PHP.
- 0x6c6f6c 3y agoHey OP I don't think I've seen this mentioned yet, but one important thing to consider is the collection of PSRs (PHP Standard Recommendations), several of which are around HTTP clients. This is an important component to decoupling packages from specific underlying implementations like Guzzle. You can even use the auto-discovery package to have whichever conforming HTTP client is installed (like Guzzle for example) be utilized, or allow via dependency injection an existing HTTP client to be passed in. This would be a great enhancement since the PHP community has done a great job with these shared standards, it is a common expectation across packages to utilize them.
- joeymckenzie 3y agoThis is an excellent idea. I assume you're referring specifically to [PSR-18](https://www.php-fig.org/psr/psr-18/ https://www.php-fig.org/psr/psr-18/)? I wasn't aware of those PSRs around the HTTP client implementations, just digging into them now. I've got my Saturday morning reading covered!
- theluketowers 3y agoI'm curious, what made you decide to use final classes and private properties in your Client class? I'd recommend taking a look at https://ocramius.github.io/blog/when-to-declare-classes-final/ https://ocramius.github.io/blog/when-to-declare-classes-fina... if you haven't seen it before.