Better Code Reusability / DRY (Don't Repeat Yourself) #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request refactors the code execution functions for supported languages (Python, Java, C, and C++) to eliminate code duplication and improve maintainability. The previous version of the script had separate functions for each language, resulting in repetitive code blocks. In this update, we introduce a dictionary,
SUPPORTED_LANGS
, which maps language names to corresponding execution functions. Each execution function now dynamically generates a temporary file for the code, compiles (if necessary), and runs it with the provided arguments.To support more languages in the given compiler, you can extend the list of supported languages in the
SUPPORTED_LANGS
dictionary. For each language, you need to specify a list of steps to compile and run the code. Each step is represented by a dictionary with the following keys:command
: The command to execute.ext
: The file extension of the code file.USE_ARGS
: A boolean flag indicating whether to use thearguments
parameter in the command.