A program should do one thing and do it well




















What if one time we needed to query a small list of computers rather than a bunch of computers from the directory? Either change would involve coding changes, probably resulting in many different versions of our tool lying around.

Instead, we might have designed the following:. Suddenly, everything becomes more flexible. That middle function could now work with any source of computer names: the directory, a text file, or whatever. Its data could be sent to any other command to produce output.

What about the onscreen table we want right now? So a function that retrieves computer names from a configuration management database is an input tool. Restart-Computer accepts computer names. Windows PowerShell already comes with a number of input tools.

To us, this further emphasizes the fact that the task of getting computer names is a standalone capability, rather than being part of another tool. Instead, it accepts that information via a parameter of some kind—that parameter being fed by manually entered data, by another command, and so on. For Java, just look at the source code of any open source component that you already use. Not all are great, but many are.

To quote Clean Code , on the page 36, it says: So, another way to know that a function is doing more than "one thing" is if you can extract another function from it with a name that is not merely a restatement of its implementation. Peter Mortensen 1, 2 2 gold badges 12 12 silver badges 14 14 bronze badges. Dan Dan 2 2 bronze badges. But if you keep of extracting , the length of codes gets longer because of other methods, is still that an issue?

Not really, assuming your methods are well named and all belong to the class that they are in then it's fine. I'd rather have lots of little methods than several huge methods because it makes the code much easier to read - you have to keep less things in your mind when you're reading it.

BorisYankov But I query different tables. Having the login information in a single table is usually the best practice, and you having to query separate tables is possibly already a bad sign. If we assume it has been done correctly, it is totally OK and even encouraged to have these in two methods. In fact you can have more methods, one doing the data access, one doing some business logic etc.

Show 2 more comments. The Overflow Blog. Stack Gives Back Still works? Power management features and all? Course it will. All the drivers are allready installed. The files get loaded as needed. No registry no install needed. Granted it is assumed your hardware is actually supported. As for the ealier generic driver comment, the live cd holds the same drivers as anbinstall would. Or, let me tell you about the story how I got my printer working under Ubuntu.

Bad example. However in general, the apparent lack of proprietary drivers for Linux is mostly due to the Windows certification program. These devices are clearly meant for hackers to implement SDRs and not for your viewing pleasure. Write your own damn drivers if you want it. Also, you might wanna look into Formula One racing, or any high-performance racing, to get a glimpse of why exposing functional parts are a good thing. Slow code? With that said, there is always an initial high investment in programming that many neglect under the assumption that it is not a physical object.

However, if you expect your program to run on hardware, you need to ensure that it actually works on the target environment and adjust as best you can. This is a time and money investment that can slow down the production of a physical system if it requires that software. Also, remember that bloatware is a thing. Intel chips, as well as many other chips, are fast due to the use of RISC architecture which gets more done with less by getting rid of other instructions the took too much real estate on the chip to execute.

They had to balance it out by using more of the ones they had left, but the time boost they got was enough to make it worth doing so. Not because the languages were incapable, rather because these new languages were developed to steer away from the ideas of mathematical based functions. GUIs just changed our ability to interact with the system. Last I checked, Microsoft Office Suite is built like that as well many other software suites.

You have it a bit backwards. In order to gain simplicity, one must have full knowledge and access to hardware. Obsolescence and e-waste is due to chip sizes and integration. In a high speed crash, the whole chassis bends out of shape anyhow and rips out of its seams — in addition to turning the passengers into pulp.

It is. When first suggested, there were many who thought it insane to do so as it would mean the vehicle would damage easily instead of being rock solid all the way through. I mean, the whole notion of graceful failure is to let the worst happen but in a controlled manner that mitigates most of the risk involved.

But that was a misconception. That was the case in the 90s, when it let them push clock speeds ever upwards. Before Linux, most people experienced Unix as a user. And there were books for that userbase, detailing all those useful utilities. When Linux came along, it made users the system administrators, so the books spend a lot of time about the OS and installing it, leaving little space for the user.

That seems a good route. This kind of made me chuckle. I guess doing one thing and doing it well is why Linux programs can be a dependency quagmire. There are benefits to plunking it all together every time. You must not be using a deb-based system then…or have forgotten DLL hell in every other system as well.

MS now attempts to get around that by shipping the entire mess even with what should be modular little. Glad bits are cheap, eh? Having used all of the above, I find less trouble with Linux than I ever did with windows, both as a dev and as a user. I do like the use of symbolic links to make sure an app grabs the right shared library in linux, so you still only need at most one copy of each version, not one per application like windows setups.

Docker, virtualenv and Appimage being cases in point. To me at least it appears that no system has really solved the dependency problems completely, even if most linux distributions have more elegant partial solutions than Windows had. With disk storage becoming cheaper by the minute, solving this issue by just delivering every dependency with every application seems to be the way all systems are going.

Because the problem is not with the system, is with the libraries and the software that uses them. Extend yes, break no. It is part of idea of shared libraries from the beginning.

Then some programmer releases a not-well-tested, not-well-planned version of that library, and the OS takes the blame for the problem. Yup, agree. Dll hell or. Lots of moving parts in a system these days.

All bow down to that egotistical moron Poerttering and his lapdog RedHat! Roughly 6 years ago, Systemd came to life as the new, event-based init mechanism, designed to replicate the old serialized System V thingie. Today, it is the reality in most distributions, for better or worse. On modern systems some of the UNIX features are outdated, ex.

Or the everything is a file, is just not true. You have to handle the types at your own! UNIX is like a untyped scripting language, it was fun and easy in the 60ss, but nowadays are little outdated. As well as the undecipherable stupid names everything has. Search for:. For Developers As far as developers are concerned, many of us tend to subscribe to the single responsibility principle. Straight from Wikipedia: In object-oriented programming , the single responsibility principle states that every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class.

Dieter Rams is quoted as saying: Less, but better — because it concentrates on the essential aspects, and the products are not burdened with non-essentials. But how do you guys determine what constitutes doing one thing? For example: Are plugins like Easy Digital Downloads and WooCommerce considered plugins that do one thing that being commerce or do they provide too many features involved in the selling of digital goods? What about something like the WordPress Importer? Those are three things each of which compose a single operation — importing.



0コメント

  • 1000 / 1000