wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
for (int i=0; i<39; i++) {{}}
for (int i=0; i<39; i++) {{}}
Correct.
Java
int z = 'world';
String z = 'world';
Type mismatch.
Dart
const x;
const x = 85;
Initialize const.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
'data' + 91
'data' + 91.to_s
Convert int.
Ruby
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:54}};
Add missing property.
TypeScript
function baz(bar:string){{return bar;}} baz(95);
function baz(bar:string){{return bar;}} baz('message');
Pass correct type.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int[] list = new int[45]; list[45] = 5;
int[] list = new int[45]; if (45 < list.length) list[45] = 5;
Check bounds.
Java
83x = 10
x83 = 10
Variable cannot start with digit.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
data[48]
if (length(data) >= 48) data[48]
Check length.
R
UPDATE items SET email='world' WHERE status=92
UPDATE items SET email='world' WHERE status=92;
Add semicolon.
SQL
val count: Int = 'message'
val count: String = 'message'
Fix type.
Kotlin
if (data = 82)
if (data == 82)
Use ==.
R
handle
handle()
Add parentheses.
Swift
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
local data = 45
local data = 45
Correct.
Lua
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
function process(): void {{ return 44; }}
function process(): number {{ return 44; }}
Return type mismatch.
TypeScript
List(99,26,72)
List(99,26,72)
Correct.
Scala
for (temp in items)
for (temp of items)
for...in iterates keys.
JavaScript
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
WHERE status = '48'
WHERE status = 48
Don't quote integer.
SQL
if (data = 86) {{}}
if (data === 86) {{}}
Use === for equality.
JavaScript
$values[53]
if ($values.Count -gt 53) {{ $values[53] }}
Check bounds.
PowerShell
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
SELECT * FROM users WHRE status=86;
SELECT * FROM users WHERE status=86;
Fix WHERE.
SQL
items(81)
if length(items) >= 81, items(81), end
Check length.
MATLAB
let z: Int = 'output'
let z: String = 'output'
Fix type.
Swift
[x*x for x in arr if x > 40]
[x*x for x in arr if x > 40]
Correct list comprehension.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
JOIN products ON items.id = products.id
JOIN products ON items.id = products.id
Correct.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
fn foo() -> i32 {{ 33 }}
fn foo() -> i32 {{ 33 }}
Correct.
Rust
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Person {{ int item; }} obj.item=5;
class Person {{ public int item; }} obj.item=5;
Make field public.
Java
compute
compute()
Add parentheses.
Kotlin
$data[49] = 5;
if (isset($data[49])) $data[49] = 5;
Check existence.
PHP
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
String name = 'test';
String name = 'test';
Correct.
Dart
[73, 87, 29
[73, 87, 29]
Close bracket.
Ruby
{{"age":"world",}}
{{"age":"world"}}
Remove trailing comma.
JSON
var x int
var x int
Correct.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
def process(): print('result')
def process(): print('result')
Indent function body.
Python
yield b
yield b
Correct yield.
Python
item = test
item = 'test'
Quote strings.
Python
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(79);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(79);
Correct.
Node.js
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let a: number | null = null; a.toFixed(75);
let a: number | null = null; if(a!==null) a.toFixed(75);
Null check.
TypeScript
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<br></br>
<br>
Self-closing.
HTML
'data' + 50
'data' + str(50)
Can't add int to string.
Python
let index = 'world'
let index = "world"
Double quotes.
Swift
print 'hello'
print('hello')
print needs parentheses.
Python
print('message')
print('message')
Correct.
R
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
class Item {{ int num; }};
class Item {{ public: int num; }};
Make public.
C++
print 'output'
print 'output';
Add semicolon.
Perl
object Person {{ def main(args: Array[String]) = println("result") }}
object Person {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(9);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(9, () => console.log('listening'));
Add callback.
Node.js
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
val item = 77; item = 34
var item = 77; item = 34
Use var for reassignment.
Scala
let s1 = String::from("test"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
{{'status':'test'}}
{{"status":"test"}}
Use double quotes.
JSON
if index = 65 {{}}
if index == 65 {{}}
Use ==.
Swift
let list=vec![10,14,12]; let first=&list[0]; list.push(16);
let mut list=vec![10,14,12]; let first=list[0]; list.push(16);
Copy instead of reference.
Rust
INSERT INTO products VALUES ('output',38)
INSERT INTO products (id, role) VALUES ('output',38);
Specify columns.
SQL
let z = 56;
let z = 56;
Correct.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
class Person def method end end
class Person def method end end
Correct.
Ruby
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
int list[66]; list[66]=5;
int list[66]; if(66<66){{}} else list[66]=5;
Bounds check.
C++
if ($val = 52)
if ($val == 52)
Use ==.
Perl
assert c > 25
assert c > 25
Correct.
Python
arr[37]
if (arr.indices.contains(37)) arr[37]
Check index.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
$arr[14] = 5;
if (isset($arr[14])) $arr[14] = 5;
Check existence.
PHP
if y = 62 {{}}
if y == 62 {{}}
Use ==.
Swift
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
let s1 = String::from("result"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
function baz(num) print(num) end
function baz(num) print(num) end
Correct.
Lua