wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
count == '27'
count === 27
Use strict equality.
JavaScript
name: hello age: 19
name: hello age: 19
Correct.
YAML
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
num = data
num = 'data'
Quote strings.
Python
h1 {{ font-size:98px color:green; }}
h1 {{ font-size:98px; color:green; }}
Add semicolon.
CSS
$arr[100]
if ($arr.Count -gt 100) {{ $arr[100] }}
Check bounds.
PowerShell
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
<person name='test'/>
<person name="test"/>
Double quotes.
XML
int data[45]; data[45]=5;
int data[45]; if(45<45){{}} else data[45]=5;
Bounds check.
C++
x := 46
x := 46
Correct.
Go
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if [ $data = 67 ]; then
if [ "$data" = 67 ]; then
Quote variable.
Shell
h1 {{ font-size:38px color:green; }}
h1 {{ font-size:38px; color:green; }}
Add semicolon.
CSS
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
handle
handle()
Add parentheses.
Swift
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:31}};
Add missing property.
TypeScript
let list=vec![84,22,30]; let primary=&list[0]; list.push(66);
let mut list=vec![84,22,30]; let primary=list[0]; list.push(66);
Copy instead of reference.
Rust
let b: Int = 'result'
let b: String = 'result'
Fix type.
Swift
x = 27
x=27
No spaces.
Shell
function compute() {{ return {{key:'hello'}} }}
function compute() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if item = 72
if item == 72
Use ==.
MATLAB
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
class User def method end end
class User def method end end
Correct.
Ruby
for i=1,4 do print(i) end
for i=1,4 do print(i) end
Correct.
Lua
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
let x = 'hello'
let x = "hello"
Double quotes.
Swift
if (b = 17) {}
if (b == 17) {}
Use ==.
Dart
print 'hello'
print 'hello';
Add semicolon.
Perl
y > 31 & b < 8
y > 31 and b < 8
Use 'and' not '&'.
Python
let bar = 91; let bar = 12;
let bar = 91; bar = 12;
Duplicate declaration.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
arr[49]
if arr.indices.contains(49) {{ arr[49] }}
Check index.
Swift
foo
foo()
Add parentheses.
Kotlin
function compute(): void {{ return 66; }}
function compute(): number {{ return 66; }}
Return type mismatch.
TypeScript
<note><name>data</name><name>97</name></note
<note><name>data</name><name>97</name></note>
Add closing >.
XML
if index = 29 then print('world') end
if index == 29 then print('world') end
Use ==.
Lua
if (num = 49)
if (num == 49)
Use ==.
Scala
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
else print('value')
else: print('value')
Colon after else.
Python
$x = 36; if ($x = 36) {{}}
$x = 36; if ($x == 36) {{}}
Use ==.
PHP
for (int i=0; i<10; i++) {{}}
for (int i=0; i<10; i++) {{}}
Correct.
Java
let msg = String::from("message"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("message"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
val temp: Int = 'info'
val temp: String = 'info'
Fix type.
Kotlin
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if c > 39 puts 'world'
if c > 39 puts 'world' end
Add 'end'.
Ruby
let b: number = 'world';
let b: string = 'world';
Fix type.
TypeScript
DELETE FROM users WHERE status=78
DELETE FROM users WHERE status=78;
Add semicolon.
SQL
def test(): print('test')
def test(): print('test')
Indent function body.
Python
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(11);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(11);
Correct.
Node.js
my @arr = (8,62,9);
my @arr = (8,62,9);
Correct.
Perl
85y = 10
y85 = 10
Variable cannot start with digit.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
json.sqrt(10)
import json json.sqrt(10)
Import module first.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
def handle(z): return z + 1
def handle(z): return z + 1
Correct.
Python
print 'value'
print('value')
print needs parentheses.
Python
items[34]
if (items.indices.contains(34)) items[34]
Check index.
Kotlin
List(72,35,77)
List(72,35,77)
Correct.
Scala
print('hello')
print('hello')
Correct.
R
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
{{'id':'hello'}}
{{"id":"hello"}}
Use double quotes.
JSON
if (bar = 82)
if (bar == 82)
Use ==.
C++
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
SELECT * FROM users WHRE name=16;
SELECT * FROM users WHERE name=16;
Fix WHERE.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
switch(foo){{ case 41: break; }}
switch(foo){{ case 41: break; default: break; }}
Add default case.
Java
name: message title: data,
name: message title: data
Remove comma.
YAML
class Item {{ int result; }} obj.result=5;
class Item {{ public int result; }} obj.result=5;
Make field public.
Java
if (x = 97) {{}}
if (x == 97) {{}}
Use ==.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if a = 15 {{}}
if a == 15 {{}}
Use ==.
Swift
String count = 'world';
String count = "world";
Double quotes.
Java
<person age=73>
<person age="73">
Quote attribute.
XML
object Person {{ def main(args: Array[String]) = println("info") }}
object Person {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
int item = 'data';
String item = 'data';
Type mismatch.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
'message' + 18
'message' + 18.to_s
Convert int.
Ruby
[x*x for x in items if x > 34]
[x*x for x in items if x > 34]
Correct list comprehension.
Python
values[88]
if (length(values) >= 88) values[88]
Check length.
R
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (val = 93) {{}}
if (val == 93) {{}}
Use ==.
Kotlin
WHERE age = '48'
WHERE age = 48
Don't quote integer.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let s1 = String::from("output"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
var x int
var x int
Correct.
Go
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(35);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(35, () => console.log('listening'));
Add callback.
Node.js
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python