That would depend on who you ask.
There are two main classifications of reasoning.
The first are the four freedoms, and generally regarded as what is required at minimum for a program to be considered free and to give the user the essential freedom to control the program on their device.
https://www.gnu.org/philosophy/free-sw.en.html
A program is free software if the program's users have the four essential freedoms:
- The freedom to run the program as you wish, for any purpose (freedom 0).
- The freedom to study how the program works, and change it so it does your computing as you wish (freedom 1). Access to the source code is a precondition for this.
- The freedom to redistribute copies so you can help your neighbor (freedom 2).
- The freedom to distribute copies of your modified versions to others (freedom 3). By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.
The other is open source, broadly speaking is somewhat similar to the free software definition but less specific about user freedom and more about the code being open.
https://opensource.org/osd
Free Redistribution
The license shall not restrict any party from selling or giving away the software as a component of an aggregate software distribution containing programs from several different sources. The license shall not require a royalty or other fee for such sale.
Source Code
The program must include source code, and must allow distribution in source code as well as compiled form. Where some form of a product is not distributed with source code, there must be a well-publicized means of obtaining the source code for no more than a reasonable reproduction cost, preferably downloading via the Internet without charge. The source code must be the preferred form in which a programmer would modify the program. Deliberately obfuscated source code is not allowed. Intermediate forms such as the output of a preprocessor or translator are not allowed.
Derived Works
The license must allow modifications and derived works, and must allow them to be distributed under the same terms as the license of the original software.
Integrity of The Author's Source Code
The license may restrict source-code from being distributed in modified form only if the license allows the distribution of "patch files" with the source code for the purpose of modifying the program at build time. The license must explicitly permit distribution of software built from modified source code. The license may require derived works to carry a different name or version number from the original software.
No Discrimination Against Persons or Groups
The license must not discriminate against any person or group of persons.
No Discrimination Against Fields of Endeavor
The license must not restrict anyone from making use of the program in a specific field of endeavor. For example, it may not restrict the program from being used in a business, or from being used for genetic research.
Distribution of License
The rights attached to the program must apply to all to whom the program is redistributed without the need for execution of an additional license by those parties.
License Must Not Be Specific to a Product
The rights attached to the program must not depend on the program's being part of a particular software distribution. If the program is extracted from that distribution and used or distributed within the terms of the program's license, all parties to whom the program is redistributed should have the same rights as those that are granted in conjunction with the original software distribution.
License Must Not Restrict Other Software
The license must not place restrictions on other software that is distributed along with the licensed software. For example, the license must not insist that all other programs distributed on the same medium must be open-source software.
License Must Be Technology-Neutral
No provision of the license may be predicated on any individual technology or style of interface.
The thing here (I think) is that your mindset isn't focused on the correct thing. You are thinking in a similar fashion of 'how can I make the most money out of people and remove any competition' leading to the conclusion that you cant let people see your code because then people could run it without paying you and the competition could use your code.
But the mind set is completely wrong.
Humans by their very nature are social and sharing, at least within their communities. and by that nature, your always going to get people "sharing" or "pirating" your software, becuase people want people to have things even if they dont have the monetary means to do so. And some people are just greedy.
The same is true for open code. Except the infrastructure around open code and open works allows for the share and share alike mentality.
People might take your code, but in doing so, you also get their code (unless you use a license that allows them to not contribute back). It encourages sharing and contribution, do it right and you can have people translate your program in many languages, QA and test your code, bug report and submit patches on systems you've never had.
Open source encouraged correctly can provide you with vast resources for minimal cost because the cost is that you share with the community what the community is sharing with you.
Can you just straight up make an open source program then sell it as a product? Probably not, traditional methods don't necessarily work, but traditional methods aren't necessarily good. Even Microsoft cant sell Windows these days as is evident with the change of direction with Windows 10.
So what other methods are there? It depends on the type of software.
Red Hat sells services and support. In doing so they hire many developers and consultants to work on open source products from the kernel, to GNOME, systemd, and a bunch of other things.
Discourse (this forum software) sells instances of the forum with and without support, with the ability to have features developed for paying customers that in turn become open source.
Blender sells books, movies, training, among other things, and I imaging may have paid develops from other companies.
Some people work as developers for companies and through those companies publish open code, through various means of showing the benefits of doing so, having a "20%" type of work environment for working on other projects of their choice, to the company simply having a stance on encouraging open code.
I do agree with the fact though that a lot of end users are just stingy people who have never paid for or gave money to a developer not contributed in any way. You'' always get people like that, but I wish we had a nice unifying effort to better encourage contribution either monetary or through contribution of skills.