برچسب: Dont

  • Don’t use too many method arguments | Code4IT

    Don’t use too many method arguments | 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

    Many times, we tend to add too many parameters to a function. But that’s not the best idea: on the contrary, when a function requires too many arguments, grouping them into coherent objects helps writing simpler code.

    Why? How can we do it? What are the main issues with having too many params? Have a look at the following snippet:

    void SendPackage(
        string name,
        string lastname,
        string city,
        string country,
        string packageId
        ) { }
    

    If you need to use another field about the address or the person, you will need to add a new parameter and update all the existing methods to match the new function signature.

    What if we added a State argument? Is this part of the address (state = “Italy”) or something related to the package (state = Damaged)?

    Storing this field in the correct object helps understanding its meaning.

    void SendPackage(Person person, string packageId) { }
    
    class Person {
        public string Name { get; set; }
        public string LastName { get; set; }
        public Address Address {get; set;}
    }
    
    class Address {
        public string City { get; set; }
        public string Country { get; set; }
    }
    

    Another reason to avoid using lots of parameters? To avoid merge conflicts.

    Say that two devs, Alice and Bob, are working on some functionalities that impact the SendPackage method. Alice, on her branch, adds a new param, bool withPriority. In the meanwhile, Bob, on his branch, adds bool applyDiscount. Then, both Alice and Bob merge together their branches on the main one. What’s the result? Of course, a conflict: the method now has two boolean parameters, and the order by which they are added to the final result may cause some troubles. Even more, because every call to the SendPackage method has now one (or two) new params, whose value depends on the context. So, after the merge, the value that Bob defined for the applyDiscount parameter might be used instead of the one added by Alice.

    Conclusion

    To recap, why do we need to reduce the number of parameters?

    • to give context and meaning to those parameters
    • to avoid errors for positional parameters
    • to avoid merge conflicts

    👉 Let’s discuss it on Twitter or on the comment section below!

    🐧





    Source link

  • Full Stack Engineers Don’t Exist! | Stephen Walsh


    Photo by Paul Bill on Unsplash

    There I said it, you might think this is a controversial or unpopular opinion but if you hear me out maybe you’ll agree with me, maybe not, but that’s what makes life worth living. I’ve believed this for a long time now, but it’s time to put a little more thought and time to flesh it out.

    As for the term Developer or Engineer, yes technically they have different scopes but they mostly cover the same disciplines and principles, so I’ll use them interchangeably from here on out.

    To say something doesn’t exist, I should probably first define what people think it is. So Looking across the internet to

    A full-stack developer is a developer or engineer who can build both the front end and the back end of a website. The front end (the parts of a website a user sees and interacts with) and the back end (the behind-the-scenes data storage and processing) require different skill sets. Since full-stack…



    Source link