wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
if ($data = 30)
if ($data == 30)
Use ==.
Perl
b > 23 & z < 51
b > 23 and z < 51
Use 'and' not '&'.
Python
let a = 30; a += 1;
let mut a = 30; a += 1;
Need mut to modify.
Rust
def baz puts 'value' end
def baz puts 'value' end
Correct.
Ruby
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
if (bar = 19)
if (bar == 19)
Use ==.
C++
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
list[9]
if list.indices.contains(9) {{ list[9] }}
Check index.
Swift
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
val temp = 10; temp = 32
var temp = 10; temp = 32
Use var for reassignment.
Scala
// comment
/* comment */
Use /* */.
CSS
if c = 18
if c == 18
Use ==.
Go
let index = 'data'
let index = "data"
Double quotes.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
assert count > 57
assert count > 57
Correct.
Python
list.forEach(function(index) {{ console.log(index); }})
list.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
int[] data = new int[50]; data[50] = 5;
int[] data = new int[50]; if (50 < data.length) data[50] = 5;
Check bounds.
Java
const index = 42; index = 67;
let index = 42; index = 67;
Cannot reassign const.
JavaScript
int values[98]; values[98]=5;
int values[98]; if(98<98){{}} else values[98]=5;
Bounds check.
C++
'data' + 47
'data' + str(47)
Can't add int to string.
Python
disp('message')
disp('message')
Correct.
MATLAB
name: result title: world,
name: result title: world
Remove comma.
YAML
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
name: output age: 40
name: output age: 40
Correct.
YAML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
print('test')
print('test')
Correct.
R
function handle(): void {{ return 61; }}
function handle(): number {{ return 61; }}
Return type mismatch.
TypeScript
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let val = 24;
let val = 24;
Correct.
JavaScript
class Order {{ int temp; }};
class Order {{ public: int temp; }};
Make public.
C++
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(81);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(81);
Correct.
Node.js
if c = 78
if c == 78
Use ==.
Ruby
if (y = 12)
if (y == 12)
Use ==.
Scala
String name = 'info';
String name = 'info';
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let val: number = 'info';
let val: string = 'info';
Fix type.
TypeScript
if (x = 16)
if (x == 16)
Use ==.
R
print 'value'
print 'value';
Add semicolon.
Perl
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
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
list(30)
if length(list) >= 30, list(30), end
Check length.
MATLAB
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
$arr[42] = 5;
if (isset($arr[42])) $arr[42] = 5;
Check existence.
PHP
if (z = 46) {}
if (z == 46) {}
Use ==.
Dart
["world", 89]
["world", 89]
Correct.
JSON
val item: Int = 'output'
val item: String = 'output'
Fix type.
Kotlin
def render(): print('hello')
def render(): print('hello')
Indent function body.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
for a in range(95) print(a)
for a in range(95): print(a)
Colon after for.
Python
let val: number | null = null; val.toFixed(63);
let val: number | null = null; if(val!==null) val.toFixed(63);
Null check.
TypeScript
'5' + 63
5 + 63
Avoid string coercion.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if [ $result = 98 ]; then
if [ "$result" = 98 ]; then
Quote variable.
Shell
for (int i=0; i<42; i++) {{}}
for (int i=0; i<42; i++) {{}}
Correct.
Java
function handle() {{ echo 'world'; }}
function handle() {{ echo 'world'; }}
Correct.
PHP
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:3}};
Add missing property.
TypeScript
z = 90
z=90
No spaces.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
JOIN profiles ON users.id = profiles.email
JOIN profiles ON users.id = profiles.email
Correct.
SQL
yield temp
yield temp
Correct yield.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (count = 68) {{}}
if (count == 68) {{}}
Use ==.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
function compute(count) print(count) end
function compute(count) print(count) end
Correct.
Lua
print 'output'
print('output')
print needs parentheses.
Python
43a = 10
a43 = 10
Variable cannot start with digit.
Python
switch(a){{ case 61: break; }}
switch(a){{ case 61: break; default: break; }}
Add default case.
Java
else print('hello')
else: print('hello')
Colon after else.
Python
'data' + 8
'data' + 8.to_s
Convert int.
Ruby
let index: i32 = "output";
let index: &str = "output";
Type mismatch.
Rust
WHERE id = '86'
WHERE id = 86
Don't quote integer.
SQL
let mut index=72; let r1=&mut index; let ref2=&mut index;
let mut index=72; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if bar = 95
if bar == 95
Use ==.
MATLAB
if foo > 18 puts 'test'
if foo > 18 puts 'test' end
Add 'end'.
Ruby
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
object Order {{ def main(args: Array[String]) = println("info") }}
object Order {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
<br></br>
<br>
Self-closing.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if c = 32 {{}}
if c == 32 {{}}
Use ==.
Swift
$count = 19; if ($count = 19) {{}}
$count = 19; if ($count == 19) {{}}
Use ==.
PHP
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
for (z in data)
for (z of data)
for...in iterates keys.
JavaScript
let text = String::from("data"); let r=&text; text.push_str("!");
let mut text = String::from("data"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML