riswux / VisualNovel-1

0 stars 0 forks source link

Dead Code #1

Open riswux opened 1 year ago

riswux commented 1 year ago
Example 1

- MainActivity.kt ```kotlin /* fun saveScenarioList(context: Context, scenarioList: List, fileName: String) { val gson = Gson() val json = gson.toJson(scenarioList) val file = File(context.filesDir, fileName) file.writeText(json) } fun loadScenarioList(context: Context, fileName: String): List { val file = File(context.filesDir, fileName) val json = file.readText() val type = object : TypeToken>() {}.type return Gson().fromJson(json, type) }*/ ``` The commented-out code blocks` saveScenarioList()` and `loadScenarioList()` indicate the presence of dead code. Dead code is code that is no longer used or executed but remains in the codebase. For Further Usage Dead code adds unnecessary clutter to the codebase, making it harder to read and understand. It can confuse developers who are trying to comprehend the code and may lead to misconceptions about the code's functionality.

Example 2

- Scenario.kt ```kotlin data class Scenario( val text: String, val choice1: String, val choice2: String, val choice3: String, val nextPosition1: String, val nextPosition2: String, val nextPosition3: String ) fun main() { val scenarios = listOf( Scenario( "Hello! My name is Jack. And you?", "", "", "Accept", "", "", "startingPoint" ), Scenario( "Great, [username]! What are we going to do?", "Walking", "Hiking", "Go to the field", "walking", "hiking", "field" ), Scenario( "Maybe go home?", "", "Yes, and watch film", "Yes, and celebrate the halloween", "", "film", "halloween" ), // add more scenarios here... ) // Convert scenarios to JSON format val gson = Gson() val json = gson.toJson(scenarios) // Save JSON to file val file = File("scenarios.json") file.writeText(json) ``` The code block above is an example of smelly code because the activity is not implemented because the data has already been described in another activity so it's better to delete it so it doesn't cause confusion.

LidiaIvanova commented 1 year ago

The first example is incorrect comment, not dead code. 0,6