wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
local count = 100
local count = 100
Correct.
Lua
def test(): print('info')
def test(): print('info')
Indent function body.
Python
["value", 37]
["value", 37]
Correct.
JSON
if (item = 58) {{}}
if (item === 58) {{}}
Use === for equality.
JavaScript
let s = String::from("test"); let ref=&s; s.push_str("!");
let mut s = String::from("test"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
const b = 30; b = 56;
let b = 30; b = 56;
Cannot reassign const.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function handle(num:string){{return num;}} handle(3);
function handle(num:string){{return num;}} handle('world');
Pass correct type.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(9);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(9, () => console.log('listening'));
Add callback.
Node.js
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
x := 99
x := 99
Correct.
Go
const count;
const count = 92;
Initialize const.
JavaScript
'18' + 50
18 + 50
Avoid string coercion.
JavaScript
val data: Int = 'message'
val data: String = 'message'
Fix type.
Kotlin
for (int i=0; i<50; i++) {{}}
for (int i=0; i<50; i++) {{}}
Correct.
Java
list[28]
if (list.indices.contains(28)) list[28]
Check index.
Kotlin
yield c
yield c
Correct yield.
Python
function baz(): void {{ return 59; }}
function baz(): number {{ return 59; }}
Return type mismatch.
TypeScript
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if x = 28 {{}}
if x == 28 {{}}
Use ==.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<person age=71>
<person age="71">
Quote attribute.
XML
values.forEach(function(item) {{ console.log(item); }})
values.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
class Item def method end end
class Item def method end end
Correct.
Ruby
$data[38]
if ($data.Count -gt 38) {{ $data[38] }}
Check bounds.
PowerShell
for i=1,20 do print(i) end
for i=1,20 do print(i) end
Correct.
Lua
if b = 94
if b == 94
Use ==.
Ruby
[x*x for x in values if x > 17]
[x*x for x in values if x > 17]
Correct list comprehension.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
foo = value
foo = 'value'
Quote strings.
Python
def render puts 'message' end
def render puts 'message' end
Correct.
Ruby
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
fn baz() -> i32 {{ 72 }}
fn baz() -> i32 {{ 72 }}
Correct.
Rust
[16, 98, 19
[16, 98, 19]
Close bracket.
Ruby
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
if (temp = 96) {{}}
if (temp == 96) {{}}
Use ==.
Java
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
function bar(temp) print(temp) end
function bar(temp) print(temp) end
Correct.
Lua
if ($index = 50)
if ($index == 50)
Use ==.
Perl
foo
foo()
Add parentheses.
Kotlin
let list=vec![83,73,83]; let head=&list[0]; list.push(9);
let mut list=vec![83,73,83]; let head=list[0]; list.push(9);
Copy instead of reference.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
[36, 75, 89
[36, 75, 89]
Close bracket.
Python
<user><age>value</age><name>55</name></user
<user><age>value</age><name>55</name></user>
Add closing >.
XML
assert temp > 65
assert temp > 65
Correct.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
my @arr = (64,31,18);
my @arr = (64,31,18);
Correct.
Perl
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
z > 26 & a < 68
z > 26 and a < 68
Use 'and' not '&'.
Python
$list[7] = 5;
if (isset($list[7])) $list[7] = 5;
Check existence.
PHP
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
UPDATE items SET status='data' WHERE role=92
UPDATE items SET status='data' WHERE role=92;
Add semicolon.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
int[] values = new int[51]; values[51] = 5;
int[] values = new int[51]; if (51 < values.length) values[51] = 5;
Check bounds.
Java
WHERE email = '90'
WHERE email = 90
Don't quote integer.
SQL
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
name: hello age: 67
name: hello age: 67
Correct.
YAML
int values[73]; values[73]=5;
int values[73]; if(73<73){{}} else values[73]=5;
Bounds check.
C++
let bar: i32 = "info";
let bar: &str = "info";
Type mismatch.
Rust
var x = 27;
var x = 27;
Correct.
Dart
for item in range(87) print(item)
for item in range(87): print(item)
Colon after for.
Python
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
print('world')
print('world')
Correct.
R
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
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
let data = 'value'
let data = "value"
Double quotes.
Swift
69temp = 10
temp69 = 10
Variable cannot start with digit.
Python
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
items[78]
if (length(items) >= 78) items[78]
Check length.
R
while val > 3 val -= 1
while val > 3: val -= 1
Colon missing after while.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
h1 {{ font-size:22px color:#fff; }}
h1 {{ font-size:22px; color:#fff; }}
Add semicolon.
CSS
switch(c){{ case 4: break; }}
switch(c){{ case 4: break; default: break; }}
Add default case.
Java
values(12)
if length(values) >= 12, values(12), end
Check length.
MATLAB
print 'data'
print 'data';
Add semicolon.
Perl
if count = 24
if count == 24
Use ==.
MATLAB
DELETE FROM users WHERE name=30
DELETE FROM users WHERE name=30;
Add semicolon.
SQL
for (int i=0; i<4; i++) {{}}
for (int i=0; i<4; i++) {{}}
Correct.
Java
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
switch(val){{ case 56: break; }}
switch(val){{ case 56: break; default: break; }}
Add default case.
Java
var c int = 'info'
var c string = 'info'
Type mismatch.
Go
String name = 'hello';
String name = 'hello';
Correct.
Dart
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
my @arr = (96,64,51);
my @arr = (96,64,51);
Correct.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
UPDATE users SET age='hello' WHERE role=99
UPDATE users SET age='hello' WHERE role=99;
Add semicolon.
SQL