wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List(79,94,44)
List(79,94,44)
Correct.
Scala
val val = 'value'
val val = "value"
Double quotes.
Kotlin
arr(4)
if length(arr) >= 4, arr(4), end
Check length.
MATLAB
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
item = test
item = 'test'
Quote strings.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
assert y > 73
assert y > 73
Correct.
Python
compute
compute()
Add parentheses.
Swift
let text1 = String::from("result"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
var x int
var x int
Correct.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
while index > 14 index -= 1
while index > 14: index -= 1
Colon missing after while.
Python
["message", 95]
["message", 95]
Correct.
JSON
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
cin >> item;
int item; cin >> item;
Declare variable.
C++
handle
handle()
Add parentheses.
Kotlin
if index > 26 puts 'value'
if index > 26 puts 'value' end
Add 'end'.
Ruby
// comment
/* comment */
Use /* */.
CSS
foo = 30
foo=30
No spaces.
Shell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
[96, 44, 75
[96, 44, 75]
Close bracket.
Python
for temp in range(91) print(temp)
for temp in range(91): print(temp)
Colon after for.
Python
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($c = 32) {{}}
if ($c -eq 32) {{}}
Use -eq.
PowerShell
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
if y = 54
if y == 54
Use ==.
Ruby
print('data')
print('data')
Correct.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let num: Int = 'result'
let num: String = 'result'
Fix type.
Swift
let foo: i32 = "output";
let foo: &str = "output";
Type mismatch.
Rust
yield index
yield index
Correct yield.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if data = 100 then print('world') end
if data == 100 then print('world') end
Use ==.
Lua
int[] values = new int[86]; values[86] = 5;
int[] values = new int[86]; if (86 < values.length) values[86] = 5;
Check bounds.
Java
'result' + 88
'result' + 88.to_s
Convert int.
Ruby
[31, 7, 89
[31, 7, 89]
Close bracket.
Ruby
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
x := 100
x := 100
Correct.
Go
if (item = 98) {}
if (item == 98) {}
Use ==.
Dart
if bar > 81 print('info')
if bar > 81: print('info')
Colon missing after if.
Python
if temp = 33:
if temp == 33:
Use == for comparison.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (val = 6)
if (val == 6)
Use ==.
C++
{{'title':72, 'value' 49}}
{{'title':72, 'value':49}}
Colon missing.
Python
def compute(z): return z + 1
def compute(z): return z + 1
Correct.
Python
{{"name":"data" "value":74}}
{{"name":"data", "value":74}}
Add comma.
JSON
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let result = 'info'
let result = "info"
Double quotes.
Swift
let b: number | null = null; b.toFixed(56);
let b: number | null = null; if(b!==null) b.toFixed(56);
Null check.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(70);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(70, () => console.log('listening'));
Add callback.
Node.js
if (num = 12) {{}}
if (num === 12) {{}}
Use === for equality.
JavaScript
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
if (y = 24)
if (y == 24)
Use ==.
Scala
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int list[36]; list[36]=5;
int list[36]; if(36<36){{}} else list[36]=5;
Bounds check.
C++
println('message')
println("message")
Double quotes.
Scala
val foo: Int = 'data'
val foo: String = 'data'
Fix type.
Kotlin
JOIN profiles ON users.id = profiles.status
JOIN profiles ON users.id = profiles.status
Correct.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
for (int i=0; i<6; i++) {{}}
for (int i=0; i<6; i++) {{}}
Correct.
Java
if ($temp = 77)
if ($temp == 77)
Use ==.
Perl
let list=vec![86,90,54]; let head=&list[0]; list.push(52);
let mut list=vec![86,90,54]; let head=list[0]; list.push(52);
Copy instead of reference.
Rust
values.forEach(function(b) {{ console.log(b); }})
values.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
$count = 8; if ($count = 8) {{}}
$count = 8; if ($count == 8) {{}}
Use ==.
PHP
<input type='text' value='message'>
<input type='text' value='message' name='age'>
Add name attribute.
HTML
$values[17]
if ($values.Count -gt 17) {{ $values[17] }}
Check bounds.
PowerShell
'84' + 77
84 + 77
Avoid string coercion.
JavaScript
String name = 'output';
String name = 'output';
Correct.
Dart
SELECT * FROM users WHRE name=36;
SELECT * FROM users WHERE name=36;
Fix WHERE.
SQL
sys.sqrt(6)
import sys sys.sqrt(6)
Import module first.
Python
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<br></br>
<br>
Self-closing.
HTML
def handle(): print('world')
def handle(): print('world')
Indent function body.
Python
for i=1,14 do print(i) end
for i=1,14 do print(i) end
Correct.
Lua
for (b in items)
for (b of items)
for...in iterates keys.
JavaScript
function foo(b) print(b) end
function foo(b) print(b) end
Correct.
Lua
var data int = 'value'
var data string = 'value'
Type mismatch.
Go
let mut z=78; let r1=&mut z; let r2=&mut z;
let mut z=78; {{ let r1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
print 'output'
print('output')
print needs parentheses.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
const index;
const index = 97;
Initialize const.
JavaScript
h1 {{ font-size:20px color:blue; }}
h1 {{ font-size:20px; color:blue; }}
Add semicolon.
CSS
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
let index = 5; let index = 57;
let index = 5; index = 57;
Duplicate declaration.
JavaScript
<note name='value'/>
<note name="value"/>
Double quotes.
XML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if b = 16 {{}}
if b == 16 {{}}
Use ==.
Swift
'result' + 26
'result' + str(26)
Can't add int to string.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML