We are in front end team and build our product based on ReactJS. My boss told me that she could not figure out how to execute iterate by map or forEach. She insists on writing iterate by for-loop.
Well, for me, there also once was a time, when I did not quite understand [].map() and [].forEach(). They looked strange to me, and when I received a script to review, which was full of those expressions, I needed a lot of time and had the person explain the code to me. I just could not cope with it. Since then, I expanded my experience and trained those expressions, so they come natural, now.
I think, your boss has the very same problem. She might be unfamiliar with the look of it and her brain just cannot make sense of it. Maybe, she doesn't even understand the advantages, yet.
So, from my experience, what you should do is prepare a presentation. Compare (by 1-on-1 example) a for-loop to those iteration-methods. Explain, why they are better for the product (e.g. better performance?) and why they are a good fit for your code architecture (e.g. keep complexity-level low). At this point, you could throw a comparison of a full source with and without iteration-methods at her and show her how they improve overview. Then, try to add a compromise at the end. It is hard for your boss to read and understand everything at once, so you might want to introduce new methods gradually in code she has to work with a lot. For example, you might decide to start with forEach() and reduce()and implement the others using loops. After a while, when you think your boss got the grip on them, add the next ones, like map() and filter() .
You should send that presentation to your boss or show it to her in a 1-on-1 session and ask her for her opinion. Tell her that this presentation is the reason why you wrote the code that particular way. Offer her to introduce her and the team to "advanced" and "new" JS functionalities and FP principles, which improve the overall code quality and lead to a better product with less time spent reading code bulk.
I guess, I was missing such a private course :D . So, try to always offer help and advice. But keep in mind: If your boss says, that even then she does not want you to use those methods, you will have to listen to her. She is your boss after all, it is her decision what to do with your brains, and you are hired to get the job done, not to have an argument about some features.
forEach is good, but for loops perform better for most things. I have had this debate with other engineers on my team and I always come back to this example:
jsperf.com/jquery-each-vs-each-vs-for-loop/3
I would prove it out, especially if performance is a big concern for your project. For readability reasons, and because I enjoy the library, I prefer to use the each function from lodash .
Sandeep Panda
co-founder, Hashnode
You should evaluate both of the options and do the following:
Ask your boss why she thinks Solution A is a better option as compared to Solution B (your solution). Try to have a productive discussion and dig deeper into her perspective. If you find out certain limitations in her solution, you should put it forward.
You should note that both you and your boss have the intention of doing good to the product. However, different people have different perspectives and communication plays a key role here. If you communicate with your boss clearly and prove that your solution is better, I think she will understand.
However, if the discussions aren't fruitful and you are indecisive - maybe the whole team can meet and take each other's opinion? In the end, your company has built a team to solve the technical problems. So, it may be a good idea to involve other developers from the team in the discussion and have a general chat.