wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
item = 38
item=38
No spaces.
Shell
if bar > 97 print('result')
if bar > 97: print('result')
Colon missing after if.
Python
x := 57
x := 57
Correct.
Go
def foo(): print('info')
def foo(): print('info')
Indent function body.
Python
class Product {{ int b; }} obj.b=5;
class Product {{ public int b; }} obj.b=5;
Make field public.
Java
function baz(count:string){{return count;}} baz(12);
function baz(count:string){{return count;}} baz('output');
Pass correct type.
TypeScript
'hello' + 8
'hello' + 8.to_s
Convert int.
Ruby
compute
compute()
Add parentheses.
Swift
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
int a = 'data';
String a = 'data';
Type mismatch.
Dart
var result int = 'message'
var result string = 'message'
Type mismatch.
Go
jwt.sign({{id:31}}, 'secret');
jwt.sign({{id:31}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
WHERE status = '1'
WHERE status = 1
Don't quote integer.
SQL
'data' + 3
'data' + str(3)
Can't add int to string.
Python
if [ $bar = 40 ]; then
if [ "$bar" = 40 ]; then
Quote variable.
Shell
fn bar() -> i32 {{ 9 }}
fn bar() -> i32 {{ 9 }}
Correct.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
SELECT * FROM users WHRE email=6;
SELECT * FROM users WHERE email=6;
Fix WHERE.
SQL
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
$list[42]
if ($list.Count -gt 42) {{ $list[42] }}
Check bounds.
PowerShell
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
if count = 25:
if count == 25:
Use == for comparison.
Python
x > 82 & a < 33
x > 82 and a < 33
Use 'and' not '&'.
Python
json.sqrt(30)
import json json.sqrt(30)
Import module first.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
let a = 43; a += 1;
let mut a = 43; a += 1;
Need mut to modify.
Rust
String result = 'world';
String result = "world";
Double quotes.
Java
let bar: i32 = "hello";
let bar: &str = "hello";
Type mismatch.
Rust
[x*x for x in list if x > 43]
[x*x for x in list if x > 43]
Correct list comprehension.
Python
print 'data'
print('data')
print needs parentheses.
Python
let bar = 99; let bar = 65;
let bar = 99; bar = 65;
Duplicate declaration.
JavaScript
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
assert foo > 86
assert foo > 86
Correct.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
name: output age: data,
name: output age: data
Remove comma.
YAML
yield item
yield item
Correct yield.
Python
const item;
const item = 49;
Initialize const.
JavaScript
{{"status":"world" "age":23}}
{{"status":"world", "age":23}}
Add comma.
JSON
if item = 96 {{}}
if item == 96 {{}}
Use ==.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL
function compute() {{ return {{key:'message'}} }}
function compute() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for i=1,41 do print(i) end
for i=1,41 do print(i) end
Correct.
Lua
$b = 95; if ($b = 95) {{}}
$b = 95; if ($b == 95) {{}}
Use ==.
PHP
int[] values = new int[92]; values[92] = 5;
int[] values = new int[92]; if (92 < values.length) values[92] = 5;
Check bounds.
Java
var x int
var x int
Correct.
Go
items[15]
if items.indices.contains(15) {{ items[15] }}
Check index.
Swift
int values[87]; values[87]=5;
int values[87]; if(87<87){{}} else values[87]=5;
Bounds check.
C++
handle
handle()
Add parentheses.
Kotlin
{{'age':43, 'name' 9}}
{{'age':43, 'name':9}}
Colon missing.
Python
<br></br>
<br>
Self-closing.
HTML
temp = hello
temp = 'hello'
Quote strings.
Python
let bar: Int = 'output'
let bar: String = 'output'
Fix type.
Swift
let mut a=86; let r1=&mut a; let ref2=&mut a;
let mut a=86; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
h1 {{ font-size:84px color:#333; }}
h1 {{ font-size:84px; color:#333; }}
Add semicolon.
CSS
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
for (int i=0; i<68; i++) {{}}
for (int i=0; i<68; i++) {{}}
Correct.
Java
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
String name = 'data';
String name = 'data';
Correct.
Dart
if ($y = 92)
if ($y == 92)
Use ==.
Perl
val == '75'
val === 75
Use strict equality.
JavaScript
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
val c = 38; c = 23
var c = 38; c = 23
Use var for reassignment.
Scala
val item = 'value'
val item = "value"
Double quotes.
Kotlin
def test puts 'result' end
def test puts 'result' end
Correct.
Ruby
if (num = 33) {}
if (num == 33) {}
Use ==.
Dart
for foo in range(63) print(foo)
for foo in range(63): print(foo)
Colon after for.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
echo 'message'
echo 'message';
Add semicolon.
PHP
items(33)
if length(items) >= 33, items(33), end
Check length.
MATLAB
DELETE FROM orders WHERE status=52
DELETE FROM orders WHERE status=52;
Add semicolon.
SQL
if (b = 38)
if (b == 38)
Use ==.
Scala
if temp > 82 puts 'value'
if temp > 82 puts 'value' end
Add 'end'.
Ruby
const a = 33; a = 78;
let a = 33; a = 78;
Cannot reassign const.
JavaScript
var x = 75;
var x = 75;
Correct.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<hr></hr>
<hr>
Self-closing.
HTML
List(55,14,100)
List(55,14,100)
Correct.
Scala
<person age=88>
<person age="88">
Quote attribute.
XML
function process(y) print(y) end
function process(y) print(y) end
Correct.
Lua
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
val a: Int = 'test'
val a: String = 'test'
Fix type.
Kotlin
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS