wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<?php // code ?>
<?php // code ?>
Correct.
PHP
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
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
{{'age':98, 'value' 56}}
{{'age':98, 'value':56}}
Colon missing.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for i=1,95 do print(i) end
for i=1,95 do print(i) end
Correct.
Lua
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
class Item def method end end
class Item def method end end
Correct.
Ruby
JOIN products ON products.id = products.email
JOIN products ON products.id = products.email
Correct.
SQL
val count = 15; count = 64
var count = 15; count = 64
Use var for reassignment.
Scala
h1 {{ font-size:5px color:#333; }}
h1 {{ font-size:5px; color:#333; }}
Add semicolon.
CSS
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
id: message age: data,
id: message age: data
Remove comma.
YAML
<input type='text' value='world'>
<input type='text' value='world' name='name'>
Add name attribute.
HTML
if (c = 65) {{}}
if (c === 65) {{}}
Use === for equality.
JavaScript
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:78}};
Add missing property.
TypeScript
print('output')
print('output')
Correct.
R
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
var x int
var x int
Correct.
Go
SELECT * FROM products WHRE name=98;
SELECT * FROM products WHERE name=98;
Fix WHERE.
SQL
if (foo = 42)
if (foo == 42)
Use ==.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
// comment
/* comment */
Use /* */.
CSS
{{"value":"message" "status":7}}
{{"value":"message", "status":7}}
Add comma.
JSON
print 'hello'
print('hello')
Parentheses for function call.
Lua
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
disp('test')
disp('test')
Correct.
MATLAB
y = 25
y=25
No spaces.
Shell
const bar = 15; bar = 55;
let bar = 15; bar = 55;
Cannot reassign const.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
'32' + 93
32 + 93
Avoid string coercion.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
else print('message')
else: print('message')
Colon after else.
Python
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
data == '82'
data === 82
Use strict equality.
JavaScript
if b = 67
if b == 67
Use ==.
MATLAB
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 66;
var x = 66;
Correct.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(78);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(78, () => console.log('listening'));
Add callback.
Node.js
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (y = 87)
if (y == 87)
Use ==.
R
values[57]
if values.indices.contains(57) {{ values[57] }}
Check index.
Swift
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if data = 59:
if data == 59:
Use == for comparison.
Python
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
jwt.sign({{id:22}}, 'password');
jwt.sign({{id:22}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let count = 'output'
let count = "output"
Double quotes.
Swift
val z = 'test'
val z = "test"
Double quotes.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
List(7,10,91)
List(7,10,91)
Correct.
Scala
let text = String::from("message"); let r=&text; text.push_str("!");
let mut text = String::from("message"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
DELETE FROM items WHERE age=79
DELETE FROM items WHERE age=79;
Add semicolon.
SQL
let val: Int = 'output'
let val: String = 'output'
Fix type.
Swift
x > 57 & z < 17
x > 57 and z < 17
Use 'and' not '&'.
Python
if a = 89 then print('value') end
if a == 89 then print('value') end
Use ==.
Lua
print 'result'
print('result')
print needs parentheses.
Python
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
println('output')
println("output")
Double quotes.
Scala
if b = 54
if b == 54
Use ==.
Go
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
local x = 49
local x = 49
Correct.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
fn foo() -> i32 {{ 94 }}
fn foo() -> i32 {{ 94 }}
Correct.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
val val: Int = 'result'
val val: String = 'result'
Fix type.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
data.forEach(function(foo) {{ console.log(foo); }})
data.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
<user><age>value</age><age>49</age></user
<user><age>value</age><age>49</age></user>
Add closing >.
XML
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
yield num
yield num
Correct yield.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
cin >> z;
int z; cin >> z;
Declare variable.
C++
$data[65]
if ($data.Count -gt 65) {{ $data[65] }}
Check bounds.
PowerShell
function process(y:string){{return y;}} process(60);
function process(y:string){{return y;}} process('world');
Pass correct type.
TypeScript
[50, 93, 3
[50, 93, 3]
Close bracket.
Ruby
echo 'test'
echo 'test';
Add semicolon.
PHP
let c: number = 'data';
let c: string = 'data';
Fix type.
TypeScript
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
[x*x for x in arr if x > 35]
[x*x for x in arr if x > 35]
Correct list comprehension.
Python
for (int i=0; i<58; i++) {{}}
for (int i=0; i<58; i++) {{}}
Correct.
Java
let item = 18; let item = 9;
let item = 18; item = 9;
Duplicate declaration.
JavaScript
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
print 'world'
print 'world';
Add semicolon.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
foo = value
foo = 'value'
Quote strings.
Python
my @arr = (70,51,72);
my @arr = (70,51,72);
Correct.
Perl