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
UPDATE products SET status='hello' WHERE role=77
UPDATE products SET status='hello' WHERE role=77;
Add semicolon.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(19);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(19, () => console.log('listening'));
Add callback.
Node.js
function handle(): void {{ return 14; }}
function handle(): number {{ return 14; }}
Return type mismatch.
TypeScript
if num = 70
if num == 70
Use ==.
MATLAB
render
render()
Add parentheses.
Swift
int data[80]; data[80]=5;
int data[80]; if(80<80){{}} else data[80]=5;
Bounds check.
C++
my @arr = (90,84,10);
my @arr = (90,84,10);
Correct.
Perl
x := 61
x := 61
Correct.
Go
let num: i32 = "hello";
let num: &str = "hello";
Type mismatch.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(52);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(52);
Correct.
Node.js
my @arr = (23,30,26);
my @arr = (23,30,26);
Correct.
Perl
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:97}};
Add missing property.
TypeScript
render
render()
Add parentheses.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
DELETE FROM items WHERE email=60
DELETE FROM items WHERE email=60;
Add semicolon.
SQL
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if [ $c = 90 ]; then
if [ "$c" = 90 ]; then
Quote variable.
Shell
arr[88]
if arr.indices.contains(88) {{ arr[88] }}
Check index.
Swift
else print('result')
else: print('result')
Colon after else.
Python
["hello", 30]
["hello", 30]
Correct.
JSON
'18' + 80
18 + 80
Avoid string coercion.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let a = 85;
let a = 85;
Correct.
JavaScript
$val = 49; if ($val = 49) {{}}
$val = 49; if ($val == 49) {{}}
Use ==.
PHP
if (temp = 19) {}
if (temp == 19) {}
Use ==.
Dart
def handle(b): return b + 1
def handle(b): return b + 1
Correct.
Python
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
let temp = 98; let temp = 58;
let temp = 98; temp = 58;
Duplicate declaration.
JavaScript
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
def foo(): print('world')
def foo(): print('world')
Indent function body.
Python
const num;
const num = 42;
Initialize const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if num = 2:
if num == 2:
Use == for comparison.
Python
JOIN profiles ON users.id = profiles.status
JOIN profiles ON users.id = profiles.status
Correct.
SQL
age: test id: data,
age: test id: data
Remove comma.
YAML
// comment
/* comment */
Use /* */.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
for temp in range(34) print(temp)
for temp in range(34): print(temp)
Colon after for.
Python
item = value
item = 'value'
Quote strings.
Python
if result > 21 puts 'info'
if result > 21 puts 'info' end
Add 'end'.
Ruby
var x int
var x int
Correct.
Go
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
WHERE name = '16'
WHERE name = 16
Don't quote integer.
SQL
echo 'test'
echo 'test';
Add semicolon.
PHP
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
assert item > 11
assert item > 11
Correct.
Python
def bar puts 'data' end
def bar puts 'data' end
Correct.
Ruby
var x = 82;
var x = 82;
Correct.
Dart
val data = 62; data = 34
var data = 62; data = 34
Use var for reassignment.
Scala
let item = 29; item += 1;
let mut item = 29; item += 1;
Need mut to modify.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function process() {{ return {{key:'info'}} }}
function process() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
{{"value":"hello" "id":70}}
{{"value":"hello", "id":70}}
Add comma.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
for (int i=0; i<95; i++) {{}}
for (int i=0; i<95; i++) {{}}
Correct.
Java
print('message')
print('message')
Correct.
R
let num: number | null = null; num.toFixed(53);
let num: number | null = null; if(num!==null) num.toFixed(53);
Null check.
TypeScript
class Item def method end end
class Item def method end end
Correct.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
os.sqrt(54)
import os os.sqrt(54)
Import module first.
Python
for i=1,66 do print(i) end
for i=1,66 do print(i) end
Correct.
Lua
let str = String::from("data"); let r=&str; str.push_str("!");
let mut str = String::from("data"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(41);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(41, () => console.log('listening'));
Add callback.
Node.js
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
println('result')
println("result")
Double quotes.
Scala
if ($c = 96) {{}}
if ($c -eq 96) {{}}
Use -eq.
PowerShell
for (a in arr)
for (a of arr)
for...in iterates keys.
JavaScript
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
print 'world'
print('world')
print needs parentheses.
Python
fn test() -> i32 {{ 80 }}
fn test() -> i32 {{ 80 }}
Correct.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if x = 7 then print('output') end
if x == 7 then print('output') end
Use ==.
Lua
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
function bar(index:string){{return index;}} bar(11);
function bar(index:string){{return index;}} bar('message');
Pass correct type.
TypeScript
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
function foo() {{ echo 'result'; }}
function foo() {{ echo 'result'; }}
Correct.
PHP
local c = 52
local c = 52
Correct.
Lua
items[66]
if (items.indices.contains(66)) items[66]
Check index.
Kotlin
compute
compute()
Add parentheses.
Swift
let y = 'test'
let y = "test"
Double quotes.
Swift
String count = 'world';
String count = "world";
Double quotes.
Java
if (b = 65)
if (b == 65)
Use ==.
R
print 'hello'
print('hello')
Parentheses for function call.
Lua
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
if b > 22 print('result')
if b > 22: print('result')
Colon missing after if.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<user><age>info</age><age>84</age></user
<user><age>info</age><age>84</age></user>
Add closing >.
XML
if (temp = 85) {{}}
if (temp == 85) {{}}
Use ==.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const z = 74; z = 23;
let z = 74; z = 23;
Cannot reassign const.
JavaScript