One of the things that the beginners learn is that coding is important, and that code is an important artifact. Which makes it difficult to convince them why giving away code is not dangerous. The philosophy of open source is usually met with raised eyebrows and skepticism in classrooms, especially if they have come to read how Bill Gates and Steve Jobs built companies and made money.
So here is yet another analogy, to explain why giving away the code only helps.
Imagine you run a transport service, ferrying passengers to destinations they want. A part of your job is to follow maps, find out new routes and build your knowledge about them so that you can take your passengers to the right destination. Now, if someone asks you for directions for going from one place to another, would you hesitate? In fact you would only be helping that person out by giving out the directions. Someone else comes too for them, and so you just make them available to everyone. Would that be a problem? It will hardly be, since your job is to enable your passengers to reach their destination, which is more than just directions. They might have a time-limit, they might want some intermediate hops or they might even have some weird baggage to be carried. You can help the passenger plan their travel, and even help them decide whether they want to travel by air, water or road. You try your best to provide a safe and convenient travel for your passengers within their constraints and that is what you get paid for.
Did you go out of your way to maintain those directions? No, you anyway had to do that for your business. You just told others what you how a certain route worked out.
There are other businesses, like the ones that sell maps or your competitors which might use directions given by you for themselves. But that should hardly matter, because directions is just one ingredient of the entire solution you offer. On the other hand, you giving out directions can only help you. It will create goodwill about you and also prove your dedication towards maintaining a record of your directions. Others who have to come to know of a better route might inform you about it or update the directions in your record. Or they might inform you about temporary impediments in the route. All this is going to help you in your own business.
There is also a possibility that you might lose passengers because some of they might choose to drive by using directions you gave. But that is hardly a loss. First, even if you do not provide the directions, it is easy for them to get it from someone else, like their friends or just go out and buy the map. Secondly, they are not your target audience since they are not looking for the solution you offer. This just turns into another benefit that you are helping even those who are not your customers. In fact you are helping all those who are looking for directions. Are directions important for your business? Sure. But you still benefited by opening them to others.
Code is not any different. Code sure is important, but just part of what you offer, a solution. Every individual and business has different needs and constraints, where you might end up using a lot of common code, but the solution is different. By giving away your code you can only benefit, not harm yourself. You get all the credibility, goodwill and even get back a lot of code back from the community. Do you still think that giving away your code is dangerous for your business?