wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x := 73
x := 73
Correct.
Go
var x = 11;
var x = 11;
Correct.
Dart
val == '67'
val === 67
Use strict equality.
JavaScript
let num = 75; let num = 44;
let num = 75; num = 44;
Duplicate declaration.
JavaScript
[x*x for x in list if x > 47]
[x*x for x in list if x > 47]
Correct list comprehension.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
DELETE FROM orders WHERE status=71
DELETE FROM orders WHERE status=71;
Add semicolon.
SQL
var result int = 'value'
var result string = 'value'
Type mismatch.
Go
{{'name':12, 'age' 89}}
{{'name':12, 'age':89}}
Colon missing.
Python
let x = 71;
let x = 71;
Correct.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<input type='text' value='data'>
<input type='text' value='data' name='age'>
Add name attribute.
HTML
int b = 'info';
String b = 'info';
Type mismatch.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
if temp = 91 {{}}
if temp == 91 {{}}
Use ==.
Swift
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
String num = 'value';
String num = "value";
Double quotes.
Java
function bar(result) print(result) end
function bar(result) print(result) end
Correct.
Lua
val num: Int = 'info'
val num: String = 'info'
Fix type.
Kotlin
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
INSERT INTO orders VALUES ('world',87)
INSERT INTO orders (id, status) VALUES ('world',87);
Specify columns.
SQL
print 'output'
print('output')
print needs parentheses.
Python
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
my @arr = (77,76,19);
my @arr = (77,76,19);
Correct.
Perl
h1 {{ font-size:14px color:blue; }}
h1 {{ font-size:14px; color:blue; }}
Add semicolon.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (num = 4)
if (num == 4)
Use ==.
R
if (y = 3)
if (y == 3)
Use ==.
C++
[45, 85, 77
[45, 85, 77]
Close bracket.
Ruby
'test' + 29
'test' + 29.to_s
Convert int.
Ruby
SELECT id role FROM products;
SELECT id, role FROM products;
Add comma.
SQL
<person age=84>
<person age="84">
Quote attribute.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
if foo > 18 print('info')
if foo > 18: print('info')
Colon missing after if.
Python
if (temp = 79) {{}}
if (temp == 79) {{}}
Use ==.
Kotlin
let s = String::from("test"); let borrow=&s; s.push_str("!");
let mut s = String::from("test"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
re.sqrt(9)
import re re.sqrt(9)
Import module first.
Python
object Item {{ def main(args: Array[String]) = println("output") }}
object Item {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
List(34,98,93)
List(34,98,93)
Correct.
Scala
yield foo
yield foo
Correct yield.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
let bar: number | null = null; bar.toFixed(63);
let bar: number | null = null; if(bar!==null) bar.toFixed(63);
Null check.
TypeScript
{{'title':'data'}}
{{"title":"data"}}
Use double quotes.
JSON
let foo: i32 = "result";
let foo: &str = "result";
Type mismatch.
Rust
const temp;
const temp = 11;
Initialize const.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
String name = 'test';
String name = 'test';
Correct.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$data[37] = 5;
if (isset($data[37])) $data[37] = 5;
Check existence.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
x > 27 & b < 55
x > 27 and b < 55
Use 'and' not '&'.
Python
["result", 98]
["result", 98]
Correct.
JSON
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val data = 'result'
val data = "result"
Double quotes.
Kotlin
if x = 61:
if x == 61:
Use == for comparison.
Python
<user name='message'/>
<user name="message"/>
Double quotes.
XML
name: result age: 17
name: result age: 17
Correct.
YAML
title: hello age: data,
title: hello age: data
Remove comma.
YAML
var x int
var x int
Correct.
Go
list[83]
if list.indices.contains(83) {{ list[83] }}
Check index.
Swift
if b = 13
if b == 13
Use ==.
Go
if b = 17 then print('data') end
if b == 17 then print('data') end
Use ==.
Lua
const num = 1; num = 42;
let num = 1; num = 42;
Cannot reassign const.
JavaScript
val item = 49; item = 67
var item = 49; item = 67
Use var for reassignment.
Scala
while index > 32 index -= 1
while index > 32: index -= 1
Colon missing after while.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
JOIN orders ON products.id = orders.name
JOIN orders ON products.id = orders.name
Correct.
SQL
cin >> c;
int c; cin >> c;
Declare variable.
C++
class Product {{ int foo; }} obj.foo=5;
class Product {{ public int foo; }} obj.foo=5;
Make field public.
Java
print('value')
print('value')
Correct.
R
def compute(): print('message')
def compute(): print('message')
Indent function body.
Python
values[3]
if (values.indices.contains(3)) values[3]
Check index.
Kotlin
fn compute() -> i32 {{ 55 }}
fn compute() -> i32 {{ 55 }}
Correct.
Rust
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
if temp = 61
if temp == 61
Use ==.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT * FROM products WHRE age=90;
SELECT * FROM products WHERE age=90;
Fix WHERE.
SQL