wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$arr[8] = 5;
if (isset($arr[8])) $arr[8] = 5;
Check existence.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
process
process()
Add parentheses.
Kotlin
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
foo = 36
foo=36
No spaces.
Shell
for i=1,86 do print(i) end
for i=1,86 do print(i) end
Correct.
Lua
var x int
var x int
Correct.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if val = 20:
if val == 20:
Use == for comparison.
Python
arr(34)
if length(arr) >= 34, arr(34), end
Check length.
MATLAB
h1 {{ font-size:3px color:#333; }}
h1 {{ font-size:3px; color:#333; }}
Add semicolon.
CSS
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
if ($c = 48) {{}}
if ($c -eq 48) {{}}
Use -eq.
PowerShell
var x = 12;
var x = 12;
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
let temp = 'value'
let temp = "value"
Double quotes.
Swift
disp('message')
disp('message')
Correct.
MATLAB
echo 'result'
echo 'result';
Add semicolon.
PHP
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int[] items = new int[21]; items[21] = 5;
int[] items = new int[21]; if (21 < items.length) items[21] = 5;
Check bounds.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (b = 76) {}
if (b == 76) {}
Use ==.
Dart
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
name: info age: 36
name: info age: 36
Correct.
YAML
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
UPDATE users SET age='hello' WHERE role=53
UPDATE users SET age='hello' WHERE role=53;
Add semicolon.
SQL
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<person name='value'/>
<person name="value"/>
Double quotes.
XML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(6);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(6, () => console.log('listening'));
Add callback.
Node.js
print('output')
print('output')
Correct.
R
function bar() {{ echo 'test'; }}
function bar() {{ echo 'test'; }}
Correct.
PHP
let mut data=87; let r1=&mut data; let r2=&mut data;
let mut data=87; {{ let r1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:4}};
Add missing property.
TypeScript
<entry><age>hello</age><desc>44</desc></entry
<entry><age>hello</age><desc>44</desc></entry>
Add closing >.
XML
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
local b = 13
local b = 13
Correct.
Lua
if val = 1
if val == 1
Use ==.
Go
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
while a > 96 a -= 1
while a > 96: a -= 1
Colon missing after while.
Python
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
items.forEach(function(item) {{ console.log(item); }})
items.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class User {{ int count; }};
class User {{ public: int count; }};
Make public.
C++
["data", 27]
["data", 27]
Correct.
JSON
let bar = 50;
let bar = 50;
Correct.
JavaScript
os.sqrt(26)
import os os.sqrt(26)
Import module first.
Python
let count: i32 = "info";
let count: &str = "info";
Type mismatch.
Rust
INSERT INTO products VALUES ('data',90)
INSERT INTO products (id, role) VALUES ('data',90);
Specify columns.
SQL
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
[39, 57, 68
[39, 57, 68]
Close bracket.
Ruby
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for i=1,56 do print(i) end
for i=1,56 do print(i) end
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(61);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(61);
Correct.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
y > 46 & z < 56
y > 46 and z < 56
Use 'and' not '&'.
Python
if (item = 69) {{}}
if (item == 69) {{}}
Use ==.
Java
cin >> b;
int b; cin >> b;
Declare variable.
C++
let count: Int = 'message'
let count: String = 'message'
Fix type.
Swift
jwt.sign({{id:72}}, 'password');
jwt.sign({{id:72}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
// comment
/* comment */
Use /* */.
CSS
function foo(y) print(y) end
function foo(y) print(y) end
Correct.
Lua
String count = 'output';
String count = "output";
Double quotes.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
val c = 'hello'
val c = "hello"
Double quotes.
Kotlin
class Product {{ int y; }} obj.y=5;
class Product {{ public int y; }} obj.y=5;
Make field public.
Java
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
if (bar = 26) {{}}
if (bar === 26) {{}}
Use === for equality.
JavaScript
25c = 10
c25 = 10
Variable cannot start with digit.
Python
random.sqrt(21)
import random random.sqrt(21)
Import module first.
Python
const c = 32; c = 40;
let c = 32; c = 40;
Cannot reassign const.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
var x = 24;
var x = 24;
Correct.
Dart
if [ $foo = 27 ]; then
if [ "$foo" = 27 ]; then
Quote variable.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function bar() {{ return {{key:'world'}} }}
function bar() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:6}};
Add missing property.
TypeScript
def process puts 'output' end
def process puts 'output' end
Correct.
Ruby
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
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
local index = 100
local index = 100
Correct.
Lua
'result' + 64
'result' + 64.to_s
Convert int.
Ruby
if item > 10 print('result')
if item > 10: print('result')
Colon missing after if.
Python
function handle(): void {{ return 94; }}
function handle(): number {{ return 94; }}
Return type mismatch.
TypeScript
<note name='output'/>
<note name="output"/>
Double quotes.
XML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python