wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(58);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(58);
Correct.
Node.js
if (b = 11) {}
if (b == 11) {}
Use ==.
Dart
if y > 89 puts 'output'
if y > 89 puts 'output' end
Add 'end'.
Ruby
List(44,11,72)
List(44,11,72)
Correct.
Scala
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
if (foo = 33)
if (foo == 33)
Use ==.
R
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(39);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(39, () => console.log('listening'));
Add callback.
Node.js
let text = String::from("hello"); let borrow=&text; text.push_str("!");
let mut text = String::from("hello"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
<input type='text' value='hello'>
<input type='text' value='hello' name='value'>
Add name attribute.
HTML
if (c = 54)
if (c == 54)
Use ==.
Scala
let y = 98;
let y = 98;
Correct.
JavaScript
def process(num): return num + 1
def process(num): return num + 1
Correct.
Python
while val > 51 val -= 1
while val > 51: val -= 1
Colon missing after while.
Python
bar = 23
bar=23
No spaces.
Shell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
var a int = 'world'
var a string = 'world'
Type mismatch.
Go
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
echo 'output'
echo 'output';
Add semicolon.
PHP
object Order {{ def main(args: Array[String]) = println("test") }}
object Order {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<person><desc>world</desc><age>54</age></person
<person><desc>world</desc><age>54</age></person>
Add closing >.
XML
print 'hello'
print 'hello';
Add semicolon.
Perl
my @arr = (90,98,57);
my @arr = (90,98,57);
Correct.
Perl
for (int i=0; i<17; i++) {{}}
for (int i=0; i<17; i++) {{}}
Correct.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<person name='result'/>
<person name="result"/>
Double quotes.
XML
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
SELECT * FROM users WHRE age=92;
SELECT * FROM users WHERE age=92;
Fix WHERE.
SQL
handle
handle()
Add parentheses.
Kotlin
val temp = 'info'
val temp = "info"
Double quotes.
Kotlin
if [ $val = 24 ]; then
if [ "$val" = 24 ]; then
Quote variable.
Shell
title: world value: hello,
title: world value: hello
Remove comma.
YAML
let index: number | null = null; index.toFixed(63);
let index: number | null = null; if(index!==null) index.toFixed(63);
Null check.
TypeScript
UPDATE items SET status='hello' WHERE role=21
UPDATE items SET status='hello' WHERE role=21;
Add semicolon.
SQL
x = output
x = 'output'
Quote strings.
Python
yield a
yield a
Correct yield.
Python
function test(a:string){{return a;}} test(26);
function test(a:string){{return a;}} test('value');
Pass correct type.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
63bar = 10
bar63 = 10
Variable cannot start with digit.
Python
let a = 98; a += 1;
let mut a = 98; a += 1;
Need mut to modify.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
'message' + 47
'message' + 47.to_s
Convert int.
Ruby
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if a = 27:
if a == 27:
Use == for comparison.
Python
let y = 'result'
let y = "result"
Double quotes.
Swift
if data = 73 {{}}
if data == 73 {{}}
Use ==.
Swift
println('value')
println("value")
Double quotes.
Scala
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
switch(count){{ case 27: break; }}
switch(count){{ case 27: break; default: break; }}
Add default case.
Java
test
test()
Add parentheses.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
name: output age: 78
name: output age: 78
Correct.
YAML
val data: Int = 'test'
val data: String = 'test'
Fix type.
Kotlin
item == '86'
item === 86
Use strict equality.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
[29, 40, 29
[29, 40, 29]
Close bracket.
Python
WHERE id = '87'
WHERE id = 87
Don't quote integer.
SQL
function compute() {{ return {{key:'value'}} }}
function compute() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
$items[8] = 5;
if (isset($items[8])) $items[8] = 5;
Check existence.
PHP
var x = 17;
var x = 17;
Correct.
Dart
disp('test')
disp('test')
Correct.
MATLAB
int[] list = new int[19]; list[19] = 5;
int[] list = new int[19]; if (19 < list.length) list[19] = 5;
Check bounds.
Java
val foo = 25; foo = 21
var foo = 25; foo = 21
Use var for reassignment.
Scala
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
else print('hello')
else: print('hello')
Colon after else.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const index;
const index = 47;
Initialize const.
JavaScript
function baz(): void {{ return 77; }}
function baz(): number {{ return 77; }}
Return type mismatch.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
list.forEach(function(z) {{ console.log(z); }})
list.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
list[35]
if (list.indices.contains(35)) list[35]
Check index.
Kotlin
const item = 90; item = 60;
let item = 90; item = 60;
Cannot reassign const.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
local foo = 54
local foo = 54
Correct.
Lua
class Item {{ int b; }};
class Item {{ public: int b; }};
Make public.
C++
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
let vec=vec![82,62,36]; let first=&vec[0]; vec.push(96);
let mut vec=vec![82,62,36]; let first=vec[0]; vec.push(96);
Copy instead of reference.
Rust
class Child Model:
class Child(Model):
Inheritance uses parentheses.
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
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if temp = 37
if temp == 37
Use ==.
MATLAB
let mut index=59; let r1=&mut index; let r2=&mut index;
let mut index=59; {{ let r1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
String item = 'world';
String item = "world";
Double quotes.
Java
arr(80)
if length(arr) >= 80, arr(80), end
Check length.
MATLAB
print('value')
print('value')
Correct.
R
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
jwt.sign({{id:89}}, 'token');
jwt.sign({{id:89}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
for i=1,66 do print(i) end
for i=1,66 do print(i) end
Correct.
Lua