wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
58foo = 10
foo58 = 10
Variable cannot start with digit.
Python
function compute() {{ return {{key:'value'}} }}
function compute() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
val z = 'world'
val z = "world"
Double quotes.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int[] items = new int[62]; items[62] = 5;
int[] items = new int[62]; if (62 < items.length) items[62] = 5;
Check bounds.
Java
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
while temp > 50 temp -= 1
while temp > 50: temp -= 1
Colon missing after while.
Python
def process(temp): return temp + 1
def process(temp): return temp + 1
Correct.
Python
if [ $b = 13 ]; then
if [ "$b" = 13 ]; then
Quote variable.
Shell
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
cin >> val;
int val; cin >> val;
Declare variable.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
items[94]
if (items.indices.contains(94)) items[94]
Check index.
Kotlin
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
let text1 = String::from("value"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
class Product {{ int temp; }};
class Product {{ public: int temp; }};
Make public.
C++
let index: number | null = null; index.toFixed(75);
let index: number | null = null; if(index!==null) index.toFixed(75);
Null check.
TypeScript
if (val = 85)
if (val == 85)
Use ==.
Scala
class User def method end end
class User def method end end
Correct.
Ruby
jwt.sign({{id:2}}, 'secret');
jwt.sign({{id:2}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
UPDATE products SET email='output' WHERE status=15
UPDATE products SET email='output' WHERE status=15;
Add semicolon.
SQL
echo 'result'
echo 'result';
Add semicolon.
PHP
local y = 89
local y = 89
Correct.
Lua
if (val = 46) {}
if (val == 46) {}
Use ==.
Dart
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
function test(): void {{ return 26; }}
function test(): number {{ return 26; }}
Return type mismatch.
TypeScript
if (y = 13) {{}}
if (y == 13) {{}}
Use ==.
Java
cin >> count;
int count; cin >> count;
Declare variable.
C++
fn process() -> i32 {{ 32 }}
fn process() -> i32 {{ 32 }}
Correct.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(64);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(64, () => console.log('listening'));
Add callback.
Node.js
String y = 'info';
String y = "info";
Double quotes.
Java
List(8,26,44)
List(8,26,44)
Correct.
Scala
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
let count = 29; let count = 76;
let count = 29; count = 76;
Duplicate declaration.
JavaScript
let item: Int = 'hello'
let item: String = 'hello'
Fix type.
Swift
print 'output'
print 'output';
Add semicolon.
Perl
if data = 95 {{}}
if data == 95 {{}}
Use ==.
Swift
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let bar: i32 = "world";
let bar: &str = "world";
Type mismatch.
Rust
{{'age':51, 'status' 12}}
{{'age':51, 'status':12}}
Colon missing.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
if ($index = 17) {{}}
if ($index -eq 17) {{}}
Use -eq.
PowerShell
[64, 36, 11
[64, 36, 11]
Close bracket.
Python
<person age=13>
<person age="13">
Quote attribute.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
[49, 21, 79
[49, 21, 79]
Close bracket.
Ruby
list.forEach(function(x) {{ console.log(x); }})
list.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
function test(temp:string){{return temp;}} test(99);
function test(temp:string){{return temp;}} test('world');
Pass correct type.
TypeScript
$values[29] = 5;
if (isset($values[29])) $values[29] = 5;
Check existence.
PHP
[x*x for x in arr if x > 7]
[x*x for x in arr if x > 7]
Correct list comprehension.
Python
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
for i=1,86 do print(i) end
for i=1,86 do print(i) end
Correct.
Lua
if ($val = 84)
if ($val == 84)
Use ==.
Perl
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
let y = 52; y += 1;
let mut y = 52; y += 1;
Need mut to modify.
Rust
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<note name='output'/>
<note name="output"/>
Double quotes.
XML
x > 91 & y < 70
x > 91 and y < 70
Use 'and' not '&'.
Python
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
if count = 29
if count == 29
Use ==.
MATLAB
if temp = 95
if temp == 95
Use ==.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
var x = 85;
var x = 85;
Correct.
Dart
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if (data = 54)
if (data == 54)
Use ==.
R
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
x := 100
x := 100
Correct.
Go
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
let vec=vec![70,53,28]; let head=&vec[0]; vec.push(16);
let mut vec=vec![70,53,28]; let head=vec[0]; vec.push(16);
Copy instead of reference.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
int list[86]; list[86]=5;
int list[86]; if(86<86){{}} else list[86]=5;
Bounds check.
C++
// comment
/* comment */
Use /* */.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
'output' + 61
'output' + str(61)
Can't add int to string.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
SELECT * FROM orders WHRE name=3;
SELECT * FROM orders WHERE name=3;
Fix WHERE.
SQL
disp('test')
disp('test')
Correct.
MATLAB
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
values[55]
if (length(values) >= 55) values[55]
Check length.
R
<user><desc>result</desc><name>84</name></user
<user><desc>result</desc><name>84</name></user>
Add closing >.
XML
<br></br>
<br>
Self-closing.
HTML
function test(data) print(data) end
function test(data) print(data) end
Correct.
Lua
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
foo == '38'
foo === 38
Use strict equality.
JavaScript
items(14)
if length(items) >= 14, items(14), end
Check length.
MATLAB
age: hello id: world,
age: hello id: world
Remove comma.
YAML
$item = 23; if ($item = 23) {{}}
$item = 23; if ($item == 23) {{}}
Use ==.
PHP
switch(z){{ case 61: break; }}
switch(z){{ case 61: break; default: break; }}
Add default case.
Java