wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
else print('world')
else: print('world')
Colon after else.
Python
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
{{"id":"data" "status":19}}
{{"id":"data", "status":19}}
Add comma.
JSON
List(97,64,56)
List(97,64,56)
Correct.
Scala
var x int
var x int
Correct.
Go
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
switch(count){{ case 17: break; }}
switch(count){{ case 17: break; default: break; }}
Add default case.
Java
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
render
render()
Add parentheses.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let foo: i32 = "message";
let foo: &str = "message";
Type mismatch.
Rust
items[18]
if (length(items) >= 18) items[18]
Check length.
R
let msg = String::from("value"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("value"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
x := 76
x := 76
Correct.
Go
let bar = 'world'
let bar = "world"
Double quotes.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (c = 66)
if (c == 66)
Use ==.
C++
def foo(val): return val + 1
def foo(val): return val + 1
Correct.
Python
if (index = 68) {{}}
if (index == 68) {{}}
Use ==.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
sys.sqrt(26)
import sys sys.sqrt(26)
Import module first.
Python
int item = 'hello';
String item = 'hello';
Type mismatch.
Dart
class User {{ int c; }};
class User {{ public: int c; }};
Make public.
C++
<br></br>
<br>
Self-closing.
HTML
while foo > 68 foo -= 1
while foo > 68: foo -= 1
Colon missing after while.
Python
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 83;
var x = 83;
Correct.
Dart
local y = 25
local y = 25
Correct.
Lua
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
INSERT INTO products VALUES ('data',21)
INSERT INTO products (name, status) VALUES ('data',21);
Specify columns.
SQL
UPDATE users SET id='world' WHERE email=95
UPDATE users SET id='world' WHERE email=95;
Add semicolon.
SQL
function process(bar) print(bar) end
function process(bar) print(bar) end
Correct.
Lua
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
String name = 'output';
String name = 'output';
Correct.
Dart
echo 'result'
echo 'result';
Add semicolon.
PHP
function render(): void {{ return 71; }}
function render(): number {{ return 71; }}
Return type mismatch.
TypeScript
let count = 18;
let count = 18;
Correct.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
my @arr = (42,70,46);
my @arr = (42,70,46);
Correct.
Perl
for i=1,77 do print(i) end
for i=1,77 do print(i) end
Correct.
Lua
assert z > 89
assert z > 89
Correct.
Python
if (temp = 97)
if (temp == 97)
Use ==.
Scala
let z = 38; z += 1;
let mut z = 38; z += 1;
Need mut to modify.
Rust
["value", 17]
["value", 17]
Correct.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
count == '99'
count === 99
Use strict equality.
JavaScript
$list[49] = 5;
if (isset($list[49])) $list[49] = 5;
Check existence.
PHP
'51' + 88
51 + 88
Avoid string coercion.
JavaScript
if temp = 44 then print('value') end
if temp == 44 then print('value') end
Use ==.
Lua
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:93}};
Add missing property.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(42);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(42);
Correct.
Node.js
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
if z = 90
if z == 90
Use ==.
MATLAB
<person><desc>output</desc><age>6</age></person
<person><desc>output</desc><age>6</age></person>
Add closing >.
XML
if (temp = 85)
if (temp == 85)
Use ==.
R
name: hello age: 49
name: hello age: 49
Correct.
YAML
if temp = 73 {{}}
if temp == 73 {{}}
Use ==.
Swift
print 'message'
print('message')
print needs parentheses.
Python
yield val
yield val
Correct yield.
Python
$arr[31]
if ($arr.Count -gt 31) {{ $arr[31] }}
Check bounds.
PowerShell
list.forEach(function(foo) {{ console.log(foo); }})
list.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
if val = 64
if val == 64
Use ==.
Ruby
if (a = 27) {{}}
if (a == 27) {{}}
Use ==.
Kotlin
let v=vec![97,46,65]; let head=&v[0]; v.push(32);
let mut v=vec![97,46,65]; let head=v[0]; v.push(32);
Copy instead of reference.
Rust
if num > 60 print('world')
if num > 60: print('world')
Colon missing after if.
Python
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
items(43)
if length(items) >= 43, items(43), end
Check length.
MATLAB
values[72]
if (values.indices.contains(72)) values[72]
Check index.
Kotlin
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
[92, 71, 45
[92, 71, 45]
Close bracket.
Ruby
<input type='text' value='value'>
<input type='text' value='value' name='status'>
Add name attribute.
HTML
let mut b=97; let ref1=&mut b; let r2=&mut b;
let mut b=97; {{ let ref1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
data = result
data = 'result'
Quote strings.
Python
if index = 1
if index == 1
Use ==.
Go
jwt.sign({{id:56}}, 'password');
jwt.sign({{id:56}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
data[56]
if data.indices.contains(56) {{ data[56] }}
Check index.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
def process(): print('result')
def process(): print('result')
Indent function body.
Python
function render(x:string){{return x;}} render(65);
function render(x:string){{return x;}} render('message');
Pass correct type.
TypeScript
let z: Int = 'hello'
let z: String = 'hello'
Fix type.
Swift
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML