Refactoring without tests should be fine
Matthias Noback Blog
by Matthias Noback
1y ago
Refactoring without tests should be fine. Why is it not? When could it be safe? From the cover of "Refactoring" by Martin Fowler: Refactoring is a controlled technique for improving the design of an existing code base. Its essence is applying a series of small behavior-preserving transformations, each of which "too small to be worth doing". However the cumulative effect of each of these transformations is quite significant. Although the word "refactoring" is used by programmers in many different ways (often it just means "changing" the code), in this case I'm thinking of those small behavior ..read more
Visit website
Good design means it's easy-to-change
Matthias Noback Blog
by Matthias Noback
1y ago
Software development seems to be about change: the business changes and we need to reflect those changes, so the requirements or specifications change, frameworks and libraries change, so we have to change our integrations with them, etc. Changing the code base accordingly is often quite painful, because we made it resistant to change in many ways. Code that resists change I find that not every developer notices the "pain level" of a change. As an example, I consider it very painful if I can't rename a class, or change its namespace. One reason could be that some classes aren't auto-loaded wit ..read more
Visit website
Is it a DTO or a Value Object?
Matthias Noback Blog
by Matthias Noback
1y ago
A common misunderstanding in my workshops (well, whose fault is it then? ;)), is about the distinction between a DTO and a value object. And so I've been looking for a way to categorize these objects without mistake. What's a DTO and how do you recognize it? A DTO is an object that holds primitive data (strings, booleans, floats, nulls, arrays of these things). It defines the schema of this data by explicitly declaring the names of the fields and their types. It can only guarantee that all the data is there, simply by relying on the strictness of the programming language: if a constructor has ..read more
Visit website
A step-debugger for the PHP AST
Matthias Noback Blog
by Matthias Noback
1y ago
When you're learning to write custom rules for PHPStan or Rector, you'll have to learn more about the PHP programming language as well. To be more precise, about the way the interpreter parses PHP code. The result of parsing PHP code is a tree of nodes which represents the structure of the code, e.g. you'll have a Class definition node, a Method definition node, and within those method Statement nodes, and so on. Each node can be checked for errors (with PHPStan), or automatically refactored in some way (with Rector). The tree of nodes is called Abstract Syntax Tree, and a successful PHPStan o ..read more
Visit website
What's a simple solution?
Matthias Noback Blog
by Matthias Noback
1y ago
"As I'm becoming a more experienced programmer, I tend to prefer simple solutions." Or something similar. As is the case with many programming-related quotes, this is somewhat of a blanket statement because who doesn't prefer simple solutions? To make it a powerful statement again, you'd have to explain what a simple solution is, and how you distinguish it from not-so-simple solutions. So the million-dollar question is "What is a simple solution?", and I'll answer it now. Just kidding. But I do have some ideas about this. There are several aspects of simplicity we'd have to consider. For insta ..read more
Visit website
When to use a trait?
Matthias Noback Blog
by Matthias Noback
1y ago
When to use a trait? Never. Well, a trait could be considered to have a few benefits: Benefits If you want to reuse some code between multiple classes, using a trait is an alternative for extending the class. In that case the trait may be the better option because it doesn't become part of the type hierarchy, i.e. a class that uses a trait isn't "an instance of that trait". A trait can save you some manual copy/paste-ing by offering compile-time copy/paste-ing instead. Downsides On the other hand, there are several problems with traits. For instance: When a trait adds one or more public met ..read more
Visit website
Effective immutability with PHPStan
Matthias Noback Blog
by Matthias Noback
1y ago
This article is about a topic that didn't make the cut for my latest book, Recipes for Decoupling. It still contains some useful ideas I think, so here it is anyway! DateTimeImmutable is mutable I don't know where I first heard it, but PHP's DateTimeImmutable is not immutable: <?php $dt = new DateTimeImmutable('now'); echo $dt->getTimestamp() . "\n"; $dt->__construct('tomorrow'); echo $dt->getTimestamp() . "\n"; The result: 1656927919 1656972000 Indeed, DateTimeImmutable is not really immutable because its internal state can be modified after instantiation. After calling __ ..read more
Visit website
New book: Recipes for Decoupling
Matthias Noback Blog
by Matthias Noback
1y ago
My new book Recipes for Decoupling is 100% complete and available now! And now some other news related to this book. A little background information My new book is based on two things: 20 years of experience with (mostly framework) coupling issues in legacy code, and the hypothesis that PHPStan, the automated static analysis tool for PHP, can help us keep our code decoupled. Decoupling often means we want to use a dependency, but don't want to couple our code too tightly to it. The process of decoupling often involves some kind of rule, like "don't use Container::get()", but we don't want to f ..read more
Visit website
DDD entities and ORM entities
Matthias Noback Blog
by Matthias Noback
2y ago
I was tweeting something about having separate "DDD" and "ORM" entities in a project in a project, and that I don't understand this. There were some great comments and questions, thanks a lot for that! To be honest, I understand more about it now. In this article I'll try to provide some more information about this. I'm glad many developers want to use input from the book "Domain-Driven Design" by Eric Evans to improve their domain model. I recommend reading this book and getting your information from the source, because unfortunately the internet, tweets, e-books, including my own books, aren ..read more
Visit website
Too much magic?
Matthias Noback Blog
by Matthias Noback
2y ago
Years ago my co-worker Maurits introduced me to the term "magic" in programming. He also provided the valuable dichotomy of convention and configuration (or in fact, he'd choose configuration over convention...). I think this distinction could be very helpful in psychological research, figuring out why some people prefer framework X over framework Y. One requires the developer to spell out everything they want in elaborate configuration files, the other relies on convention: placing certain files with certain names and certain methods in certain places will make everything work "magically". An ..read more
Visit website

Follow Matthias Noback Blog on FeedSpot

Continue with Google
Continue with Apple
OR