برچسب: Have

  • Methods should have a coherent level of abstraction | Code4IT

    Methods should have a coherent level of abstraction | Code4IT


    Just a second! 🫷
    If you are here, it means that you are a software developer.
    So, you know that storage, networking, and domain management have a cost .

    If you want to support this blog, please ensure that you have disabled the adblocker for this site.
    I configured Google AdSense to show as few ADS as possible – I don’t want to bother you with lots of ads, but I still need to add some to pay for the resources for my site.

    Thank you for your understanding.
    Davide

    Mixed levels of abstraction make the code harder to understand.

    At the first sight, the reader should be able to understand what the code does without worrying about the details of the operations.

    Take this code snippet as an example:

    public void PrintPriceWithDiscountForProduct(string productId)
    {
        var product = sqlRepository.FindProduct(productId);
        var withDiscount = product.Price * 0.9;
        Console.WriteLine("The final price is " + withDiscount);
    }
    

    We are mixing multiple levels of operations. In the same method, we are

    • integrating with an external service
    • performing algebraic operations
    • concatenating strings
    • printing using .NET Console class

    Some operations have a high level of abstraction (call an external service, I don’t care how) while others are very low-level (calculate the price discount using the formula ProductPrice*0.9).

    Here the readers lose focus on the overall meaning of the method because they’re distracted by the actual implementation.

    When I’m talking about abstraction, I mean how high-level an operation is: the more we stay away from bit-to-bit and mathematical operations, the more our code is abstract.

    Cleaner code should let the reader understand what’s going on without the need of understanding the details: if they’re interested in the details, they can just read the internals of the methods.

    We can improve the previous method by splitting it into smaller methods:

    public void PrintPriceWithDiscountForProduct(string productId)
    {
        var product = GetProduct(productId);
        var withDiscount = CalculateDiscountedPrice(product);
        PrintPrice(withDiscount);
    }
    
    private Product GetProduct(string productId)
    {
        return sqlRepository.FindProduct(productId);
    }
    
    private double CalculateDiscountedPrice(Product product)
    {
        return product.Price * 0.9;
    }
    
    private void PrintPrice(double price)
    {
        Console.WriteLine("The final price is " + price);
    }
    

    Here you can see the different levels of abstraction: the operations within PrintPriceWithDiscountForProduct have a coherent level of abstraction: they just tell you what the steps performed in this method are; all the methods describe an operation at a high level, without expressing the internal operations.

    Yes, now the code is much longer. But we have gained some interesting advantages:

    • readers can focus on the “what” before getting to the “how”;
    • we have more reusable code (we can reuse GetProduct, CalculateDiscountedPrice, and PrintPrice in other methods);
    • if an exception is thrown, we can easily understand where it happened, because we have more information on the stack trace.

    You can read more about the latest point here:

    🔗 Clean code tip: small functions bring smarter exceptions | Code4IT

    This article first appeared on Code4IT 🐧

    Happy coding!

    🐧



    Source link

  • 6 Automotive Technologies That Have Hit the Scene Recently


    Automotive technology has come a long way since the first concept car was built in the 1700s. New innovations have been exploding onto the scene at a rapid pace since then. Cars are becoming more capable of assisting drivers in all aspects of their driving experiences as well. These are some of the technologies that have hit the scene recently.

    1. Adaptive Cruise Control

    Adaptive cruise control came about over the past few years and is an excellent upgrade to standard cruise control. Adaptive cruise control has a feature that enables the vehicle to slow down swiftly and speed up according to a pre-determined following distance. This technology has done wonders to protect drivers from getting into accidents. Millions of people sustain injuries on the highway yearly, and every little attempt to make the roadways safer is a huge plus.

    2. Lane Departure Warning

    Lane departure warning is a god-send for exhausted drivers worldwide. It also helps people who have to take long trips. The feature alerts the driver with a loud sound, light, or vibration when the vehicle swerves in the lane. The driver then regains alertness and corrects the issue.

    3. Lane-Keeping Assistance

    Lane-keeping assistance usually works with the lane departure warning system. It goes the extra mile and helps the driver get back into the lane from which he or she strayed. You might be interested in this feature if you have long rides to work or travel a lot by yourself. It can help you avoid having to deal with a lawsuit, too. The statute of limitations for driving incidents in Texas in two years. Thus, you might have to worry for two whole years if you get into an accident in the state. Having these features can help you avoid all such incidents.

    4. Automatic Emergency Braking

    Automatic Emergency Braking is exactly what it sounds like. The vehicle has a set of sensors that can pick up objects and people in the way. If the system senses a near accident, the braking system will stop the vehicle. It’s like mechanical assistance for emergencies and can be a real lifesaver if anything happens. It can be useful if someone ever lacks the reaction time to stop the vehicle quickly enough.

    5. Cameras

    More vehicles are being crafted with cameras that give a view of the entire road as well as the vehicle’s surroundings. These cameras cut down on accidents and leave lots of evidence for theft and vandalism incidents. Even the police are starting to use cruiser vehicles with cameras. In 2000, only 11% of police used cars with cameras. That figure has since blown up to a whopping 72%. If the police force uses them, that should be a cue for you to consider purchasing a car with the feature.

    6. Autonomy

    Some cars are now capable of driving on their own. The feature still requires drivers to stay alert and keep their hands near the wheels. However, the most intricate of the newer vehicles have an autonomy feature that can help when a driver wants to relax. This option is available mostly in all-electric high-end vehicles.

    You can add it to your package for additional pay, which might add up to several thousand dollars. However, you’ll be one of the first people to try out this exciting new feature. Consider inquiring about it the next time you want to purchase a vehicle.

    This list is not at all exhaustive. Many more features exist in cars today. It’s up to you to find the best fit for you and your family. Ask your sales rep to explain your vehicle’s features and benefits.



    Source link

  • Online Signature Tools Now Have Neat Icons

    Online Signature Tools Now Have Neat Icons


    Last month, we added neat icons to Online JSON Tools, and today we have also added neat icons to Online Signature Tools. The new icons make it easier to find and use your favorite tools.

    What Are Online Signature Tools?

    Online Signature Tools, also known as Digital Signature Tools, are browser-based apps that help you edit and enhance your handwritten signature for digital use. They let you do things like remove the background, change the color, resize, rotate, and improve the quality of your scanned signature image. These tools are super useful for making your signature look clean and professional when signing PDFs, Word docs, or other digital documents.​

    What Are Online Signature Tool Synonyms?

    • E-signature tools
    • Digital signature makers
    • Online signing apps
    • Electronic signing software
    • Signature creator tools
    • Web signature generators
    • Digital signing tools
    • E-sign apps
    • Signature editor tools
    • Online signature generators
    • Digital signature software

    Who Created Online Signature Tools?

    Online Signature Tools were built by me and my team at Browserling. We wanted to create something simple and easy for people to use right in their browsers – no downloads, no installs, no complicated stuff. While we work on a bunch of handy online tools, we also do cross-browser testing to make sure everything works great no matter what browser you’re using. Our goal is to help regular users and developers save time and get things done without any tech headaches.

    Who Uses Online Signature Tools?

    Online Signature Tools and Browserling are used by everyone, including regular Internet users, freelancers, small business owners, and even Fortune 100 companies. They’re handy for signing documents, contracts, or forms quickly without printing or scanning. Everyday users use them for signing agreements or apartment leases, while professionals use them for signing NDAs and big contracts.

    Buy a subscription now at onlinePNGtools.com/pricing and use the coupon code SIGNLING for 30% off! 🤑



    Source link

  • Online Stamp Tools Now Have Neat Icons

    Online Stamp Tools Now Have Neat Icons


    Last month, we added neat icons to Online Icon Tools, and today we have also added neat icons to Online Stamp Tools (such as stamp background remover, stamp color changer, and stamp resizer) . The new icons make it easier to find and use your favorite tools.

    What Are Online Stamp Tools?

    Tools for editing stamps. Buy a subscription for full access.

    Who Created Online Stamp Tools?

    Team Browserling created Online Stamp Tools. Buy a subscription if you love us.

    Who Uses Online Stamp Tools?

    Everyone uses Online Stamp Tools. Buy a subscription to join the family.

    Buy a subscription now at onlinePNGtools.com/pricing and use the coupon code STAMPLING for 30% off! 🤑



    Source link

  • Online Icon Tools Now Have Neat Icons

    Online Icon Tools Now Have Neat Icons


    Last month, we added neat icons to Online Logo Tools, and today we have also added neat icons to Online Icon Tools. The new icons make it easier to find and use your favorite tools.

    What Are Online Icon Tools?

    Tools for editing icons. Buy a subscription for full access.

    Who Created Online Icon Tools?

    Team Browserling created Online Icon Tools. Buy a subscription if you love us.

    Who Uses Online Icon Tools?

    Everyone uses Online Icon Tools. Buy a subscription to join the family.

    Buy a subscription now at onlinePNGtools.com/pricing and use the coupon code ICONLING for 30% off! 🤑



    Source link