This project provides a tool to analyze source code and calculate Halstead metrics. Halstead metrics are a set of software metrics introduced by Maurice Halstead to measure the complexity of a program.
- Supports multiple programming languages including C#, Java, JavaScript, Python, and Ruby.
- Calculates various Halstead metrics such as:
- Number of distinct operators (N1)
- Number of distinct operands (N2)
- Total number of operators (n1)
- Total number of operands (n2)
- Program vocabulary (N)
- Program length (n)
- Calculated program length (Np)
- Calculated program volume (V)
- Calculated program difficulty (D)
- Calculated program effort (E)
- Calculated program time (T)
- Calculated program bugs (B)
To use the tool, run the main.go file with the -filepath flag pointing to the source code file you want to analyze. For example:
go run main.go -filepath path/to/sourcecode.extHere is an example of how to use the tool to analyze a Python file:
go run main.go -filepath Dataset/PalindromeChecker.py- Go 1.23.2 or higher
- Clone the repository:
git clone https://github.com/itsfuad/halstead.git
- Navigate to the project directory:
cd halstead-metrics - Run the tool:
go run main.go -filepath path/to/sourcecode.ext
This project is licensed under the GNU GENERAL PUBLIC LICENSE. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
- Maurice Halstead for introducing the Halstead metrics.
- The open-source community for providing various tools and libraries.