wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'world'
print('world')
print needs parentheses.
Python
local item = 61
local item = 61
Correct.
Lua
[8, 35, 72
[8, 35, 72]
Close bracket.
Ruby
print('value')
print('value')
Correct.
R
String name = 'info';
String name = 'info';
Correct.
Dart
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$item = 70; if ($item = 70) {{}}
$item = 70; if ($item == 70) {{}}
Use ==.
PHP
let data = 19; data += 1;
let mut data = 19; data += 1;
Need mut to modify.
Rust
disp('info')
disp('info')
Correct.
MATLAB
jwt.sign({{id:62}}, 'secret');
jwt.sign({{id:62}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
list[84]
if (list.indices.contains(84)) list[84]
Check index.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
let num = 'message'
let num = "message"
Double quotes.
Swift
function baz(count) print(count) end
function baz(count) print(count) end
Correct.
Lua
assert count > 16
assert count > 16
Correct.
Python
id: message status: data,
id: message status: data
Remove comma.
YAML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if x > 36 print('value')
if x > 36: print('value')
Colon missing after if.
Python
List(6,80,18)
List(6,80,18)
Correct.
Scala
let data: i32 = "info";
let data: &str = "info";
Type mismatch.
Rust
<person><age>world</age><name>62</name></person
<person><age>world</age><name>62</name></person>
Add closing >.
XML
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
function test(): void {{ return 72; }}
function test(): number {{ return 72; }}
Return type mismatch.
TypeScript
val y: Int = 'world'
val y: String = 'world'
Fix type.
Kotlin
'world' + 12
'world' + 12.to_s
Convert int.
Ruby
// comment
/* comment */
Use /* */.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
let str1 = String::from("output"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
y = 66
y=66
No spaces.
Shell
else print('output')
else: print('output')
Colon after else.
Python
x = data
x = 'data'
Quote strings.
Python
let b: Int = 'message'
let b: String = 'message'
Fix type.
Swift
class Item def method end end
class Item def method end end
Correct.
Ruby
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
random.sqrt(54)
import random random.sqrt(54)
Import module first.
Python
<br></br>
<br>
Self-closing.
HTML
if (a = 54) {{}}
if (a == 54) {{}}
Use ==.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let temp = 46; let temp = 87;
let temp = 46; temp = 87;
Duplicate declaration.
JavaScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
if (num = 97)
if (num == 97)
Use ==.
C++
function baz(data:string){{return data;}} baz(94);
function baz(data:string){{return data;}} baz('value');
Pass correct type.
TypeScript
DELETE FROM products WHERE age=1
DELETE FROM products WHERE age=1;
Add semicolon.
SQL
WHERE email = '31'
WHERE email = 31
Don't quote integer.
SQL
print 'test'
print 'test';
Add semicolon.
Perl
if (x = 72)
if (x == 72)
Use ==.
R
my @arr = (90,71,88);
my @arr = (90,71,88);
Correct.
Perl
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
class Order {{ int y; }} obj.y=5;
class Order {{ public int y; }} obj.y=5;
Make field public.
Java
var result int = 'message'
var result string = 'message'
Type mismatch.
Go
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
def compute(): print('data')
def compute(): print('data')
Indent function body.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
int b = 'info';
String b = 'info';
Type mismatch.
Dart
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
if result = 8
if result == 8
Use ==.
Ruby
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
<person age=12>
<person age="12">
Quote attribute.
XML
if result = 40 then print('hello') end
if result == 40 then print('hello') end
Use ==.
Lua
h1 {{ font-size:47px color:blue; }}
h1 {{ font-size:47px; color:blue; }}
Add semicolon.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
UPDATE products SET id='output' WHERE status=60
UPDATE products SET id='output' WHERE status=60;
Add semicolon.
SQL
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
for (a in values)
for (a of values)
for...in iterates keys.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
78c = 10
c78 = 10
Variable cannot start with digit.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
for i=1,83 do print(i) end
for i=1,83 do print(i) end
Correct.
Lua
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const b = 10; b = 4;
let b = 10; b = 4;
Cannot reassign const.
JavaScript
name: world age: 33
name: world age: 33
Correct.
YAML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
var x = 81;
var x = 81;
Correct.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
function bar() {{ return {{key:'value'}} }}
function bar() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
String y = 'test';
String y = "test";
Double quotes.
Java
const num;
const num = 12;
Initialize const.
JavaScript
val foo = 71; foo = 61
var foo = 71; foo = 61
Use var for reassignment.
Scala
if (result = 77) {{}}
if (result == 77) {{}}
Use ==.
Kotlin
render
render()
Add parentheses.
Swift
arr.forEach(function(c) {{ console.log(c); }})
arr.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
int items[28]; items[28]=5;
int items[28]; if(28<28){{}} else items[28]=5;
Bounds check.
C++
if ($foo = 56)
if ($foo == 56)
Use ==.
Perl
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart