wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
// comment
/* comment */
Use /* */.
CSS
class Person {{ int count; }};
class Person {{ public: int count; }};
Make public.
C++
values.forEach(function(count) {{ console.log(count); }})
values.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
print 'data'
print 'data';
Add semicolon.
Perl
[7, 17, 30
[7, 17, 30]
Close bracket.
Ruby
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
var a int = 'result'
var a string = 'result'
Type mismatch.
Go
for y in range(69) print(y)
for y in range(69): print(y)
Colon after for.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
<user><age>output</age><desc>27</desc></user
<user><age>output</age><desc>27</desc></user>
Add closing >.
XML
let text = String::from("result"); let ref=&text; text.push_str("!");
let mut text = String::from("result"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
while bar > 37 bar -= 1
while bar > 37: bar -= 1
Colon missing after while.
Python
disp('info')
disp('info')
Correct.
MATLAB
function baz(num:string){{return num;}} baz(14);
function baz(num:string){{return num;}} baz('value');
Pass correct type.
TypeScript
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
JOIN profiles ON items.id = profiles.email
JOIN profiles ON items.id = profiles.email
Correct.
SQL
$item = 100; if ($item = 100) {{}}
$item = 100; if ($item == 100) {{}}
Use ==.
PHP
String temp = 'result';
String temp = "result";
Double quotes.
Java
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
let v=vec![26,52,53]; let first=&v[0]; v.push(9);
let mut v=vec![26,52,53]; let first=v[0]; v.push(9);
Copy instead of reference.
Rust
["output", 47]
["output", 47]
Correct.
JSON
print('hello')
print('hello')
Correct.
R
[74, 20, 84
[74, 20, 84]
Close bracket.
Python
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
function bar(): void {{ return 55; }}
function bar(): number {{ return 55; }}
Return type mismatch.
TypeScript
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
if temp > 7 print('hello')
if temp > 7: print('hello')
Colon missing after if.
Python
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
'value' + 23
'value' + 23.to_s
Convert int.
Ruby
SELECT * FROM users WHRE age=59;
SELECT * FROM users WHERE age=59;
Fix WHERE.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(45);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(45, () => console.log('listening'));
Add callback.
Node.js
{{'status':3, 'id' 87}}
{{'status':3, 'id':87}}
Colon missing.
Python
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for (bar in values)
for (bar of values)
for...in iterates keys.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'18' + 6
18 + 6
Avoid string coercion.
JavaScript
if (val = 71)
if (val == 71)
Use ==.
R
38bar = 10
bar38 = 10
Variable cannot start with digit.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
if (result = 65)
if (result == 65)
Use ==.
C++
let item: number = 'test';
let item: string = 'test';
Fix type.
TypeScript
for (int i=0; i<8; i++) {{}}
for (int i=0; i<8; i++) {{}}
Correct.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let count: number | null = null; count.toFixed(87);
let count: number | null = null; if(count!==null) count.toFixed(87);
Null check.
TypeScript
let bar = 48;
let bar = 48;
Correct.
JavaScript
int arr[38]; arr[38]=5;
int arr[38]; if(38<38){{}} else arr[38]=5;
Bounds check.
C++
val result = 'world'
val result = "world"
Double quotes.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
items[16]
if (length(items) >= 16) items[16]
Check length.
R
if index = 43
if index == 43
Use ==.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
WHERE email = '52'
WHERE email = 52
Don't quote integer.
SQL
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(6);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(6);
Correct.
Node.js
if count = 21:
if count == 21:
Use == for comparison.
Python
value: world name: test,
value: world name: test
Remove comma.
YAML
def baz(): print('output')
def baz(): print('output')
Indent function body.
Python
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if bar > 22 print('hello')
if bar > 22: print('hello')
Colon missing after if.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'name':28, 'id' 76}}
{{'name':28, 'id':76}}
Colon missing.
Python
let temp: number | null = null; temp.toFixed(13);
let temp: number | null = null; if(temp!==null) temp.toFixed(13);
Null check.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
<person><desc>world</desc><desc>40</desc></person
<person><desc>world</desc><desc>40</desc></person>
Add closing >.
XML
if (count = 22) {{}}
if (count == 22) {{}}
Use ==.
Java
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
def foo(y): return y + 1
def foo(y): return y + 1
Correct.
Python
const user:Person = {{name:'data'}};
const user:Person = {{name:'data', age:27}};
Add missing property.
TypeScript
if ($bar = 88)
if ($bar == 88)
Use ==.
Perl
function compute(): void {{ return 78; }}
function compute(): number {{ return 78; }}
Return type mismatch.
TypeScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
class Order {{ int index; }} obj.index=5;
class Order {{ public int index; }} obj.index=5;
Make field public.
Java
if result = 76
if result == 76
Use ==.
MATLAB
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
my @arr = (32,87,31);
my @arr = (32,87,31);
Correct.
Perl
for (int i=0; i<79; i++) {{}}
for (int i=0; i<79; i++) {{}}
Correct.
Java
let item = 26;
let item = 26;
Correct.
JavaScript
let foo = 2; let foo = 68;
let foo = 2; foo = 68;
Duplicate declaration.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
["value", 28]
["value", 28]
Correct.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(7);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(7, () => console.log('listening'));
Add callback.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
let b: i32 = "result";
let b: &str = "result";
Type mismatch.
Rust