Learning Driven Developmentpodcast· Aug 9, 2024· 17:11
There's so much you can learn from just building things, from getting out there and just creating something. In fact, that's why I call this series Learning Driven Development because I think the best way to learn is actually by doing, by building that thing you want to build, by learning that tool that you need to learn in order to build that thing that you want to build. And on this episode, we're going to be reading five lessons I learned from building my own Laravel package by Ash Allen.
So what do you need to learn in order to build something or what do you need to build in order to learn something? Welcome to the Learning Driven Development Podcast. I'm Josh Seery and here's where I get the incredible opportunity to read, learn and share with you articles, blogs, documentation, stories or other forms of written content that exists in the tech space. This is five lessons I learned from building my own Laravel package by Ash Allen.
You can find Ash on GitHub at Ash Allen. That's Ash-JC-Allen on GitHub. Freelance Laravel developer from Preston, UK. And then on Twitter slash X at Ash Allen Design. That's at Ash Allen Design. So here is five lessons I learned from building my own Laravel package. And Ash has been incredibly gracious for the purpose of this episode.
He has two books, Battle Ready Laravel and Consuming APIs in Laravel. You can find them in the show notes or the video description. But he is giving five discount codes that I have ready to give away to anyone who is listening to this podcast or watching this video. If you are on the podcast, head over to YouTube. That's YouTube Josh Siri. And in the comments, say keep creating.
and I will enter you to win a free copy of both of these books, Battle Ready Laravel and Consuming APIs in Laravel. I have five discount codes to give away, so comment, like, subscribe, and let's get into reading this. Five lessons I learned from building my own Laravel package. This was written by Ash on the 26th of May, 2021. Introduction. During my Christmas holidays at the
end of 2019, I spent a bit of my free time building a Laravel package called Laravel Exchange Rates. The package is pretty simple and is just a wrapper for the Exchange Rates API.io API with some caching features added for performance. At the time of writing this post, the package has around 43,000 downloads and has started getting around 4,000 downloads per month. It's not that big in comparison to some other projects, but I'd like to think that I did
something right for it to be getting that many downloads. My main reason for building it was just so that I could experiment with packages. As part of using Laravel on a daily basis, I'd gotten used to using lots of packages, but I felt like the best way for me to properly understand how we use packages in Laravel was to build one myself. By doing that, I would be able to get an insight into every step of the process to try and improve my skills as a developer. The entire development process was fun and taught me a lot. Here are the main things that I learned from building a Laravel
exchange rates and then I pass on to other developers. One, learn to take criticism. When I first started building the package, I had only been working as a Laravel developer for around a year and a half. So even though I had picked up the fundamentals of the framework, there was still a lot I didn't know in comparison to now. Because of this, I was already expecting to get criticism from more experienced developers. After I'd built an initial version of the package, I posted a link to the GitHub repository on Reddit, on the Laravel subreddit, asking for
opinions and feedback. Overall, the feedback was useful and most people made some really valid points about some of the code that could be improved. I took their feedback on board and updated the parts that they mentioned. However, I did get some feedback that came across as criticism. As an example, one comment was just a link to an existing exchange rates package. I wasn't too sure what to make of this, but I took it as meaning, what's the point in using yours? There's already another one that exists. As someone who was just starting out in web
development and was quite excited to get a bit of feedback from the development community, this was a bit demotivating because it made me think to myself, what's the point in me actually doing it if someone else has already made it? Obviously, looking back now though, that probably wasn't the case and the commenter might not have meant it like that. The important part is that if someone shuns your work or criticizes it, don't let it get you down too much. If it's possible, try and find out why they criticized your work. It can be good to sometimes take a step back and
listen to other developers feedback to help you improve. But also bear in mind, you don't know if the person you're taking feedback from is a top-notch developer or someone who only started writing hello world last week. So it's really important to remember that the criticism won't always be valid. Top tip, listen to the constructive criticism and use the feedback to improve your code, but don't dwell on negative comments. Number two, learn to look at code from someone else's
perspective. When I was building the package, I found it really useful to try and look at the package from another developer's perspective. I tried to imagine how I would want to use the package if someone else had built it. So my main focus was to keep the method names readable and reduce the amount of parameters that needed to be passed to the methods. Sometimes when you're working on your own side projects, especially ones that you're just building as a learning exercise, it can be easy to let standards slip. You might add a quick hack here and there to get something
working instead of spending a little bit more time to do something properly. I wanted to try and avoid doing that with the package because I knew that it would be a surefire way to put other developers off wanting to use it. As developers, we don't use packages purely for saving time. We also use them to make our life easier. It's such a great feeling when you install a new package into your project and it just works without having to mess around to get it working. So I aim to provide that same feeling with this package.
I wanted it to be installed and ready to go within a few lines of code without needing any complicated setup. Top tip, if you can, ask another developer you know to give your package a try and see if they run into any difficulties or have suggestions for improvements. Number three, learn the importance of tests. As any developer should know, tests are crucial for any type of development, whether it be a full-blown system or just a small package.
Thankfully, I knew that early on in the process and made tests a priority. When I'm looking at including a new package into my project, one of the main things that I look at are if there are any tests. They provide some form of proof that the code does what it says it should do, assuming that the tests are written properly, but that's for a whole other article. Without any tests written, how are we supposed to have the confidence that the code works? These tests then come in handy if you start to get other developers who want to contribute to the package later down the line.
By using something like GitHub Actions, Travis CI, or CircleCI, you can trigger your tests to run whenever a pull request is made to the package's repository. This is extremely useful for letting yourself and the other developer know if the new changes break any existing functionality. After all, one thing that you want to ensure is stability. If projects that use your package start running into issues with the new code, it will likely get frustrating for them and they may even remove your package
and look for an alternative. Top tip, make sure that you write tests to give yourself and other developers peace of mind that your code works. Number four, don't be scared to start again. Near the beginning of this article, I said that I posted on Reddit about the exchange rates package, but that wasn't 100% the truth. I actually posted about an earlier version of the package that I'd called Coinverter. Converter was supposed to be the same as Laravel exchange rates, except for me it was going to use the adapter pattern and support multiple APIs
rather than just exchange rates API. The idea behind it was that a developer could just update their .env file to use a different exchange rates driver and change the API keys to switch between services without needing to update any of their code. I spent quite a bit of time reading into the adapter pattern and I was quite excited to be working on the package. But then I slowly started to realize that I'd bitten off more than I could chew and I wasn't experienced enough to do something like this properly. Sure, I got it to a working stage,
but I just never felt like it was done quite right. So I decided to do what I mentioned earlier and I looked at it from another developer's perspective. One of my main goals from the start of the package development was to try and make the package simple to set up and intuitive to use with a limited barrier to entry. As a result of this, I stepped back from the idea of using the adapter pattern. For the sake of simplicity, I chose to use just one service.
My reasoning behind using the ExchangeRatesAPI.io API was that it was free, really easy to use, and it didn't require any API keys or accounts to use at the time of building it. I feel like by starting again and rebuilding the package, I managed to strip away a lot of unnecessary code that was just going to be adding unneeded complexity. The end result was a much simpler package that was easier to maintain, test, and use. Top tip, don't be worried about deleting your code and starting again.
The fact that you know to start again shows that you're learning and can spot your mistakes to improve next time. Number five, understand the importance of standards and documentation. As part of any development, standards and documentation are an absolute must. By following a set standard, in my case at the time PSR-2, you can make sure that your code is in a format that is understandable by other developers.
By using a standard that's well known, you can also make it easier for other developers to contribute to your code because they'll be able to structure their code to be in the same style as yours. The documentation is also really important because it's the only thing really that's telling developers how to install your package and use it. Before I started to write my documentation, I searched around and looked at other popular packages to see how theirs were laid out.
After doing this, I wrote my documentation and provided clear steps on the project prerequisites, installation, usage, license, and how to contribute. Whenever I look at new packages, I read the documentation before deciding whether to install them. I check out things like, does this package solve the problem that I've got? Does it look easy to use? Are there examples of it being used? All of these questions form my opinion on whether to install the package. If the documentation isn't very good, it might be a hint that the overall package quality might not be very good either.
This isn't always the case though. Top tip, make the package as easy as possible to install and use by writing thorough documentation with code examples. In conclusion, to recap, I'd say whenever you're writing a new package, listen to the constructive criticism and use the feedback to improve your code, but don't dwell on negative comments. If you can, ask other developers you know to give your package a try and see if they run into any difficulties or have suggestions for improvements. Make the package as easy as possible to install
and use by writing thorough documentation with code examples. Also make sure that you write tests to give yourself and other developers peace of mind that your code works. Don't be worried about deleting your code and starting again. The fact that you know to start again shows that you're learning and you can spot your mistakes to improve next time. But most of all, make sure that you're enjoying it and having fun while you're doing it. Like I said at the start of this video, I've always been under the mindset of the opinion,
I should say that it is best to learn something by actually completing the thing that you want to build. Usually if you go about wanting to, oh, how am I going to learn how to build a package? The best way to do that isn't to necessarily watch a course or read a tutorial and see how is everyone else doing this? And then I'll learn how to create it. That's a good step throughout the process. But usually you don't start building a package that way.
You start by creating the package and then figuring out, okay, what am I going to do here? And then the learning comes. When I say, and I call this series learning driven development, I basically mean that as you learn, as you get up to the task that you need to complete, in this case, building a package like Ash did, as you come across that particular instance, that particular challenge, now you have something actual to learn.
Ash was building with, you know, different API sets and was going to say, okay, I'm going to convert all these different APIs, but then learned that was probably more that he could choose. So then it's learning, which is the best way to do this, whether it's starting from scratch, whether it's finding a particular package that you know, that you trust, and how do they accomplish this pattern? I see this a lot when you're building anything, building a product or
I do it with building tutorials, with building demos for tutorials. I take a look. Okay. How has someone else used this particular section? Am I showing this the right way that I would want someone else to show it? I think that leads really nicely into the whole deleting everything and starting again. You know what happens the second time you build something? Not only do you build it faster, but you tend to not make the same mistakes. If you're learning,
You tend to not make the same mistakes that you did the first time around. Take a look at any modern package or even just like open source project. There are people that have probably built that from the ground up three or four times. The package I love in Laravel Livewire was rebuilt probably multiple times before every single release because that's just something Caleb Porzio, the creator, does for fun.
I usually if I don't like how a video is going there's sometimes where I've created and recorded an hour-long video about particular demo or like building you know a particular project within a video and I don't like how certain parts flowed when I pressed stop recording so I just deleted the video and started again but you know what happens that second time I start recording or
third time or fourth time, depending on how many times delete it and start again, things flow more smoothly in how I talk and how I type and how I research the small bugs that still come up. It doesn't, it doesn't mean I do it flawlessly. There's still edits that have to be made. There's still things that I need to redo in the video when I finally get my thoughts out onto the screen, into the camera, but it's in a way that I feel comfortable with because it feels
familiar. A lot of the times when you're learning, simply redoing it, repetition, even if you're learning from scratch in this way, shape, or form of building a Laravel package, or maybe you're creating a product or something like that. Most of the times, the second time you do it, people's second businesses, for example, are always better because you have that repetition put in. You have the idea of, I made this mistake the first time. It's fresh in my mind. I'm not
going to make it again. So anyways, before I wrap this up, I really enjoyed what Ash said here. But if you go on to the YouTube video in the comments, type keep creating two words, doesn't matter how you put it, but you'll be entered to win one of the five discount codes that I have that's 100%
discount off for Battle Ready Laravel as well as Consuming APIs and Laravel. Those two books by Ash, who has been gracious to be able to give those for the purpose of this show. But thank you so much for listening. Thank you for watching. And one of the things that I think that you should always keep in mind when you have this idea that you have that I'm like, hey, I want to learn something. And now I need to find these different pieces and collect all these different pieces so
that I can learn this so that it comes to fruition in the end, start by saying, I'm going to figure out what this next step is. And then the next step is, and it might not be you're learning this all in one, but I guarantee you the second time you do it, the third time you do it. And the fourth time you do it now, people are going to be starting to look at your project, your package, your app, your insert name here, for an example, where before you were looking at others, I've done it
myself with creators, with tutorial people, with educators, with builders, with designers, with developers. Every single time I do it, I do the thing, I get better at it. And every single time I do the thing, usually because I'm better at it, the thing is usually better too. So keep building, keep iterating, keep creating.
you