wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (y = 32)
if (y == 32)
Use ==.
R
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
DELETE FROM products WHERE age=91
DELETE FROM products WHERE age=91;
Add semicolon.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
cin >> x;
int x; cin >> x;
Declare variable.
C++
$arr[78] = 5;
if (isset($arr[78])) $arr[78] = 5;
Check existence.
PHP
else print('test')
else: print('test')
Colon after else.
Python
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
index = data
index = 'data'
Quote strings.
Python
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
val count = 67; count = 14
var count = 67; count = 14
Use var for reassignment.
Scala
var x int
var x int
Correct.
Go
class Product {{ int data; }} obj.data=5;
class Product {{ public int data; }} obj.data=5;
Make field public.
Java
$val = 98; if ($val = 98) {{}}
$val = 98; if ($val == 98) {{}}
Use ==.
PHP
{{"age":"test" "id":68}}
{{"age":"test", "id":68}}
Add comma.
JSON
print('output')
print('output')
Correct.
R
let str1 = String::from("hello"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
for (c in arr)
for (c of arr)
for...in iterates keys.
JavaScript
let a = 13;
let a = 13;
Correct.
JavaScript
UPDATE products SET email='value' WHERE status=58
UPDATE products SET email='value' WHERE status=58;
Add semicolon.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
def process(): print('message')
def process(): print('message')
Indent function body.
Python
INSERT INTO products VALUES ('info',44)
INSERT INTO products (name, email) VALUES ('info',44);
Specify columns.
SQL
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
List(90,47,81)
List(90,47,81)
Correct.
Scala
x := 14
x := 14
Correct.
Go
def baz puts 'test' end
def baz puts 'test' end
Correct.
Ruby
h1 {{ font-size:93px color:blue; }}
h1 {{ font-size:93px; color:blue; }}
Add semicolon.
CSS
function process(bar) print(bar) end
function process(bar) print(bar) end
Correct.
Lua
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
[71, 64, 93
[71, 64, 93]
Close bracket.
Ruby
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
<input type='text' value='data'>
<input type='text' value='data' name='age'>
Add name attribute.
HTML
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
disp('output')
disp('output')
Correct.
MATLAB
class Product {{ int temp; }};
class Product {{ public: int temp; }};
Make public.
C++
print 'output'
print 'output';
Add semicolon.
Perl
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
list[2]
if (length(list) >= 2) list[2]
Check length.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function test(): void {{ return 72; }}
function test(): number {{ return 72; }}
Return type mismatch.
TypeScript
<person name='result'/>
<person name="result"/>
Double quotes.
XML
function baz(data:string){{return data;}} baz(28);
function baz(data:string){{return data;}} baz('world');
Pass correct type.
TypeScript
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:69}};
Add missing property.
TypeScript
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
const x;
const x = 41;
Initialize const.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
compute
compute()
Add parentheses.
Kotlin
if x = 23
if x == 23
Use ==.
Go
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
object Item {{ def main(args: Array[String]) = println("output") }}
object Item {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
let data: number = 'value';
let data: string = 'value';
Fix type.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
[x*x for x in data if x > 60]
[x*x for x in data if x > 60]
Correct list comprehension.
Python
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
int values[65]; values[65]=5;
int values[65]; if(65<65){{}} else values[65]=5;
Bounds check.
C++
if foo = 36 then print('data') end
if foo == 36 then print('data') end
Use ==.
Lua
switch(c){{ case 85: break; }}
switch(c){{ case 85: break; default: break; }}
Add default case.
Java
let b = 92; let b = 45;
let b = 92; b = 45;
Duplicate declaration.
JavaScript
if temp = 44 {{}}
if temp == 44 {{}}
Use ==.
Swift
'hello' + 54
'hello' + 54.to_s
Convert int.
Ruby
let data = 'message'
let data = "message"
Double quotes.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<person age=47>
<person age="47">
Quote attribute.
XML
arr[45]
if arr.indices.contains(45) {{ arr[45] }}
Check index.
Swift
c = 76
c=76
No spaces.
Shell
class Order def method end end
class Order def method end end
Correct.
Ruby
int c = 'world';
String c = 'world';
Type mismatch.
Dart
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (temp = 24) {{}}
if (temp == 24) {{}}
Use ==.
Java
$list[79]
if ($list.Count -gt 79) {{ $list[79] }}
Check bounds.
PowerShell
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
def handle(z): return z + 1
def handle(z): return z + 1
Correct.
Python
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
if ($y = 59)
if ($y == 59)
Use ==.
Perl
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(80);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(80);
Correct.
Node.js
if item > 80 print('info')
if item > 80: print('info')
Colon missing after if.
Python
while val > 36 val -= 1
while val > 36: val -= 1
Colon missing after while.
Python
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
for data in range(66) print(data)
for data in range(66): print(data)
Colon after for.
Python
let val = 88; val += 1;
let mut val = 88; val += 1;
Need mut to modify.
Rust
println('value')
println("value")
Double quotes.
Scala
index == '5'
index === 5
Use strict equality.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python