wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if item > 71 puts 'data'
if item > 71 puts 'data' end
Add 'end'.
Ruby
class User def method end end
class User def method end end
Correct.
Ruby
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
let z: i32 = "output";
let z: &str = "output";
Type mismatch.
Rust
for i=1,64 do print(i) end
for i=1,64 do print(i) end
Correct.
Lua
let data: number = 'info';
let data: string = 'info';
Fix type.
TypeScript
h1 {{ font-size:60px color:#333; }}
h1 {{ font-size:60px; color:#333; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
var x = 57;
var x = 57;
Correct.
Dart
else print('data')
else: print('data')
Colon after else.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if x > 70 print('data')
if x > 70: print('data')
Colon missing after if.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
yield temp
yield temp
Correct yield.
Python
if (data = 22)
if (data == 22)
Use ==.
Scala
class Item {{ int data; }} obj.data=5;
class Item {{ public int data; }} obj.data=5;
Make field public.
Java
name: message age: 57
name: message age: 57
Correct.
YAML
JOIN profiles ON orders.id = profiles.status
JOIN profiles ON orders.id = profiles.status
Correct.
SQL
result = value
result = 'value'
Quote strings.
Python
disp('data')
disp('data')
Correct.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for (index in values)
for (index of values)
for...in iterates keys.
JavaScript
fn bar() -> i32 {{ 59 }}
fn bar() -> i32 {{ 59 }}
Correct.
Rust
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
function foo(data:string){{return data;}} foo(39);
function foo(data:string){{return data;}} foo('value');
Pass correct type.
TypeScript
echo world data
echo 'world data'
Quote to prevent splitting.
Shell
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
print 'data'
print('data')
print needs parentheses.
Python
if (a = 28)
if (a == 28)
Use ==.
R
println('result')
println("result")
Double quotes.
Scala
if count = 68
if count == 68
Use ==.
Ruby
int count = 'hello';
String count = 'hello';
Type mismatch.
Dart
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(71);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(71);
Correct.
Node.js
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
data(24)
if length(data) >= 24, data(24), end
Check length.
MATLAB
const data;
const data = 91;
Initialize const.
JavaScript
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
while bar > 7 bar -= 1
while bar > 7: bar -= 1
Colon missing after while.
Python
int items[58]; items[58]=5;
int items[58]; if(58<58){{}} else items[58]=5;
Bounds check.
C++
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
echo 'test'
echo 'test';
Add semicolon.
PHP
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if bar = 65
if bar == 65
Use ==.
MATLAB
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
local c = 13
local c = 13
Correct.
Lua
DELETE FROM products WHERE id=33
DELETE FROM products WHERE id=33;
Add semicolon.
SQL
print 'message'
print 'message';
Add semicolon.
Perl
if (result = 47)
if (result == 47)
Use ==.
C++
assert data > 80
assert data > 80
Correct.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
function render() {{ echo 'data'; }}
function render() {{ echo 'data'; }}
Correct.
PHP
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (z = 43) {{}}
if (z === 43) {{}}
Use === for equality.
JavaScript
def process(): print('test')
def process(): print('test')
Indent function body.
Python
age: output id: test,
age: output id: test
Remove comma.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[3, 47, 39
[3, 47, 39]
Close bracket.
Python
["hello", 43]
["hello", 43]
Correct.
JSON
// comment
/* comment */
Use /* */.
CSS
if ($temp = 24) {{}}
if ($temp -eq 24) {{}}
Use -eq.
PowerShell
let s = String::from("hello"); let borrow=&s; s.push_str("!");
let mut s = String::from("hello"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
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
$data[60] = 5;
if (isset($data[60])) $data[60] = 5;
Check existence.
PHP
String b = 'value';
String b = "value";
Double quotes.
Java
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
if [ $val = 86 ]; then
if [ "$val" = 86 ]; then
Quote variable.
Shell
let index = 63; index += 1;
let mut index = 63; index += 1;
Need mut to modify.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
val z = 69; z = 98
var z = 69; z = 98
Use var for reassignment.
Scala
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
let c = 77; let c = 60;
let c = 77; c = 60;
Duplicate declaration.
JavaScript
compute
compute()
Add parentheses.
Swift
UPDATE items SET email='message' WHERE role=85
UPDATE items SET email='message' WHERE role=85;
Add semicolon.
SQL
<person age=59>
<person age="59">
Quote attribute.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const val = 17; val = 3;
let val = 17; val = 3;
Cannot reassign const.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
List(49,71,86)
List(49,71,86)
Correct.
Scala
foo
foo()
Add parentheses.
Kotlin
if foo = 53:
if foo == 53:
Use == for comparison.
Python
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
data[93]
if (data.indices.contains(93)) data[93]
Check index.
Kotlin
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
if (count = 10) {}
if (count == 10) {}
Use ==.
Dart
function baz(temp) print(temp) end
function baz(temp) print(temp) end
Correct.
Lua
for (int i=0; i<63; i++) {{}}
for (int i=0; i<63; i++) {{}}
Correct.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if (data = 39) {{}}
if (data == 39) {{}}
Use ==.
Kotlin
let bar: Int = 'test'
let bar: String = 'test'
Fix type.
Swift
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int[] values = new int[32]; values[32] = 5;
int[] values = new int[32]; if (32 < values.length) values[32] = 5;
Check bounds.
Java