Is it appropriate to use terms "software bug" and/or just "bug" in formal report? What else could be used instead? Defect?
Terminology varies across the software industry; in some companies everybody is happy with "bug"; in other places you might be expected to use terms like "defect", "fault" or "issue". Sorry to not be able to give you a definite answer, but you'll need to ask around to find what's in general usage in your context.
One piece of advice which is useful though: whatever terminology you use, be consistent in distinguishing between the underlying problem in the software (fault/defect/bug/etc) and an event where something goes wrong when using the software: often the term "failure" is used for this. So for example you might have a single fault in the software, which causes multiple failures, one every time the software is used.
Defect is generally preferable, it covers deviations from the expected results of a system, although it usually excludes problems caused by human operators (e.g. if the user enters some bad data, and the program handles the exception appropriately, as per spec, it's not a defect).
Bug is more informal - I will sometimes say something is a bug but not in formal documents. I've found it's often used interchangeably with defect. As others have noted, it may be taken to mean something more specific (code/programming error) than defect.
Even more colloquial is gremlin - e.g. the report failed that one time due to a gremlin (generally this means no-one cares to work out what caused the failure, if the problem is not reproducible).
Failure is an even more general term which would include defects as well as operator error.
If it's a bug just use bug. However not all defects are bugs. A bug is behaviour which does not conform to the specification. A defect could be a missing but desirable feature. Software delivery or support contracts may have clauses concerning bugs (such as them being fixed for free) so be careful in using the term.
I think bug (or more formally, software bug) can be use in a formal context with no problem. It is the official and most correct term to describe an unexpected error that happens when a piece of software is executed.
A defect can be a bug, but it can be something else; for example an expected flaw in algorithm that makes the software perform much slower with some user's input.
"Coding error" or "Programming error" might be applicable - if you really want to specifically say it was something like a typo or an error in basic program design. "Defect" covers any kind of failure of the program to do what is desired of it.
There are several near-synonyms. These terms are not fully standardized across the software industry.
Defect is in my experience common in quality assurance (not just software quality assurance). In security, I often see flaw. For example, the Common Criteria for security evaluation use the word flaw, with a similar meaning (not 100% identical, of which more later). The relative number of on the Stack Exchange sites Software Quality Assurance and Security (an admittedly very noisy measurement) corroborate this perception that each domain prefers one of the terms: 259/32 in favor of defect on SQA, 897/44 in favor of flaw on Security.
anomaly: Any condition that deviates from expectation based on requirements specifications, design documents, user documents, standards, etc. or from someone’s perception or experience. Anomalies may be found during, but not limited to, reviewing, testing, analysis, compilation, or use of software products or applicable documentation.
defect: A flaw in a component or system that can cause the component or system to fail to perform its required function, e.g. an incorrect statement or data definition. A defect, if encountered during execution, may cause a failure of the component or system.
Bug, fault and problem refer to defect. Flaw is not formally defined.
This suggests a nuance between defect and flaw that I've seen elsewhere: a defect has an impact on the performance of the system and causes it to misbehave in a way that matters. A flaw can be a defect, but it is also possible for a flaw to have no known practical impact, for example a security vulnerability for which no exploit is known (which would automatically become a defect if an exploit is found).
I can't find an authoritative-reference for this, but I've often seen bug used in a more restrictive sense: a bug is a non-conformance to a detailed specification. If that detailed specification does not match high-level requirements, it is not a bug but it remains a defect. For example, if you forget a client requirement in the specification, it counts as a defect but that is classified as a feature request rather than a bug for internal tracking.
Issue is mostly used in the context of issue tracking and project management. Issue tracking generalizes bug tracking by at least uncontroversially including feature requests, as well as incident tracking which after investigation may lead to the conclusion that the incident was the result of misuse rather than of a bug, or that the incident was misreported.
The word bug was used by mechanics and electrical engineers well before software was a thing. It sometimes still has a hint of informality, though I'd hardly call it slang, especially in the computer world where it has been heavily used (e.g. 836/259 for bug vs. defect on SQA SE).
The word bug is mostly used for physical objects or software that has a behavior, and less so for specifications written in human or mathematical languages. When a specification is internally inconsistent, this is more often called a defect than a bug (for example, some standards bodies such as ISO and ANSI issue defect reports — others merely issue errata). When a specification does not correctly implement high-level requirements, this is a defect or a flaw.
Defect and flaw can also apply to development procedures and processes (for example, lack of quality control at some phase of the development). Bug is rarely used for that.
As a conclusion, I would recommend:
- defect in general;
- flaw if you are in a security field;
- bug if you are specifically discussing coding mistakes.