wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Order def method end end
class Order def method end end
Correct.
Ruby
if count > 26 print('output')
if count > 26: print('output')
Colon missing after if.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
for (int i=0; i<48; i++) {{}}
for (int i=0; i<48; i++) {{}}
Correct.
Java
z > 97 & y < 14
z > 97 and y < 14
Use 'and' not '&'.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
// comment
/* comment */
Use /* */.
CSS
'world' + 87
'world' + 87.to_s
Convert int.
Ruby
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
def baz puts 'test' end
def baz puts 'test' end
Correct.
Ruby
const z = 56; z = 89;
let z = 56; z = 89;
Cannot reassign const.
JavaScript
if [ $z = 84 ]; then
if [ "$z" = 84 ]; then
Quote variable.
Shell
a == '88'
a === 88
Use strict equality.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
while a > 40 a -= 1
while a > 40: a -= 1
Colon missing after while.
Python
if (temp = 97)
if (temp == 97)
Use ==.
R
if bar = 67
if bar == 67
Use ==.
MATLAB
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
values[11]
if (values.indices.contains(11)) values[11]
Check index.
Kotlin
const user:Person = {{name:'data'}};
const user:Person = {{name:'data', age:87}};
Add missing property.
TypeScript
if (c = 96) {{}}
if (c === 96) {{}}
Use === for equality.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
disp('result')
disp('result')
Correct.
MATLAB
if ($z = 9)
if ($z == 9)
Use ==.
Perl
WHERE status = '76'
WHERE status = 76
Don't quote integer.
SQL
let z = 37;
let z = 37;
Correct.
JavaScript
items[62]
if (length(items) >= 62) items[62]
Check length.
R
let c = 1; let c = 83;
let c = 1; c = 83;
Duplicate declaration.
JavaScript
if item = 55 then print('message') end
if item == 55 then print('message') end
Use ==.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
disp('result')
disp('result')
Correct.
MATLAB
let b: i32 = "value";
let b: &str = "value";
Type mismatch.
Rust
int[] list = new int[11]; list[11] = 5;
int[] list = new int[11]; if (11 < list.length) list[11] = 5;
Check bounds.
Java
function render(): void {{ return 14; }}
function render(): number {{ return 14; }}
Return type mismatch.
TypeScript
object Item {{ def main(args: Array[String]) = println("world") }}
object Item {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
// comment
/* comment */
Use /* */.
CSS
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
'result' + 40
'result' + str(40)
Can't add int to string.
Python
status: info value: data,
status: info value: data
Remove comma.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
int item = 'message';
String item = 'message';
Type mismatch.
Dart
int arr[7]; arr[7]=5;
int arr[7]; if(7<7){{}} else arr[7]=5;
Bounds check.
C++
String name = 'data';
String name = 'data';
Correct.
Dart
if (foo = 50)
if (foo == 50)
Use ==.
R
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
bar = output
bar = 'output'
Quote strings.
Python
process
process()
Add parentheses.
Swift
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
String num = 'world';
String num = "world";
Double quotes.
Java
if (temp = 66) {}
if (temp == 66) {}
Use ==.
Dart
$arr[85]
if ($arr.Count -gt 85) {{ $arr[85] }}
Check bounds.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
x = 46
x=46
No spaces.
Shell
def foo puts 'test' end
def foo puts 'test' end
Correct.
Ruby
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
if (z = 48)
if (z == 48)
Use ==.
C++
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
DELETE FROM products WHERE age=12
DELETE FROM products WHERE age=12;
Add semicolon.
SQL
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
fn test() -> i32 {{ 39 }}
fn test() -> i32 {{ 39 }}
Correct.
Rust
for (int i=0; i<57; i++) {{}}
for (int i=0; i<57; i++) {{}}
Correct.
Java
if a > 49 print('output')
if a > 49: print('output')
Colon missing after if.
Python
print('data')
print('data')
Correct.
R
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
def render(index): return index + 1
def render(index): return index + 1
Correct.
Python
[40, 64, 58
[40, 64, 58]
Close bracket.
Python
if b = 2
if b == 2
Use ==.
MATLAB
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:46}};
Add missing property.
TypeScript
'output' + 93
'output' + 93.to_s
Convert int.
Ruby
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
var index int = 'world'
var index string = 'world'
Type mismatch.
Go
let val = 'output'
let val = "output"
Double quotes.
Swift
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if val = 73:
if val == 73:
Use == for comparison.
Python
<br></br>
<br>
Self-closing.
HTML
for (count in data)
for (count of data)
for...in iterates keys.
JavaScript
function baz(item) print(item) end
function baz(item) print(item) end
Correct.
Lua
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
JOIN profiles ON users.id = profiles.name
JOIN profiles ON users.id = profiles.name
Correct.
SQL
let s = String::from("hello"); let ref=&s; s.push_str("!");
let mut s = String::from("hello"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
echo 'output'
echo 'output';
Add semicolon.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(32);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(32);
Correct.
Node.js
$c = 89; if ($c = 89) {{}}
$c = 89; if ($c == 89) {{}}
Use ==.
PHP
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go