wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if a = 25
if a == 25
Use ==.
MATLAB
class Item def method end end
class Item def method end end
Correct.
Ruby
if (z = 57)
if (z == 57)
Use ==.
R
'output' + 76
'output' + 76.to_s
Convert int.
Ruby
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
arr[46]
if arr.indices.contains(46) {{ arr[46] }}
Check index.
Swift
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def foo puts 'output' end
def foo puts 'output' end
Correct.
Ruby
if [ $b = 36 ]; then
if [ "$b" = 36 ]; then
Quote variable.
Shell
val val = 'world'
val val = "world"
Double quotes.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function foo(c) print(c) end
function foo(c) print(c) end
Correct.
Lua
let bar: i32 = "value";
let bar: &str = "value";
Type mismatch.
Rust
for (x in values)
for (x of values)
for...in iterates keys.
JavaScript
'value' + 24
'value' + str(24)
Can't add int to string.
Python
num = 90
num=90
No spaces.
Shell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
'15' + 84
15 + 84
Avoid string coercion.
JavaScript
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
x := 98
x := 98
Correct.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val result = 1; result = 50
var result = 1; result = 50
Use var for reassignment.
Scala
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
print 'result'
print 'result';
Add semicolon.
Perl
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
else print('world')
else: print('world')
Colon after else.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<note name='data'/>
<note name="data"/>
Double quotes.
XML
sys.sqrt(18)
import sys sys.sqrt(18)
Import module first.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
if (z = 52) {{}}
if (z === 52) {{}}
Use === for equality.
JavaScript
if temp > 49 puts 'data'
if temp > 49 puts 'data' end
Add 'end'.
Ruby
// comment
/* comment */
Use /* */.
CSS
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
fn test() -> i32 {{ 53 }}
fn test() -> i32 {{ 53 }}
Correct.
Rust
String bar = 'data';
String bar = "data";
Double quotes.
Java
baz
baz()
Add parentheses.
Swift
if (result = 75)
if (result == 75)
Use ==.
C++
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
x > 75 & z < 7
x > 75 and z < 7
Use 'and' not '&'.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(92);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(92, () => console.log('listening'));
Add callback.
Node.js
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
arr(54)
if length(arr) >= 54, arr(54), end
Check length.
MATLAB
class Person {{ int result; }} obj.result=5;
class Person {{ public int result; }} obj.result=5;
Make field public.
Java
2foo = 10
foo2 = 10
Variable cannot start with digit.
Python
list(24)
if length(list) >= 24, list(24), end
Check length.
MATLAB
{{"status":"message" "name":100}}
{{"status":"message", "name":100}}
Add comma.
JSON
int[] arr = new int[4]; arr[4] = 5;
int[] arr = new int[4]; if (4 < arr.length) arr[4] = 5;
Check bounds.
Java
switch(x){{ case 29: break; }}
switch(x){{ case 29: break; default: break; }}
Add default case.
Java
if (result = 38)
if (result == 38)
Use ==.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
SELECT * FROM orders WHRE email=85;
SELECT * FROM orders WHERE email=85;
Fix WHERE.
SQL
name: result age: 94
name: result age: 94
Correct.
YAML
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
int list[97]; list[97]=5;
int list[97]; if(97<97){{}} else list[97]=5;
Bounds check.
C++
def foo puts 'result' end
def foo puts 'result' end
Correct.
Ruby
let mut y=37; let r1=&mut y; let r2=&mut y;
let mut y=37; {{ let r1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
print 'result'
print 'result';
Add semicolon.
Perl
{{'value':3, 'age' 26}}
{{'value':3, 'age':26}}
Colon missing.
Python
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
let z: number = 'hello';
let z: string = 'hello';
Fix type.
TypeScript
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:69}};
Add missing property.
TypeScript
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$arr[33] = 5;
if (isset($arr[33])) $arr[33] = 5;
Check existence.
PHP
if z > 44 print('message')
if z > 44: print('message')
Colon missing after if.
Python
local count = 61
local count = 61
Correct.
Lua
let result = 'data'
let result = "data"
Double quotes.
Swift
UPDATE orders SET name='info' WHERE status=40
UPDATE orders SET name='info' WHERE status=40;
Add semicolon.
SQL
const num;
const num = 32;
Initialize const.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
test
test()
Add parentheses.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
cin >> result;
int result; cin >> result;
Declare variable.
C++
if c > 28 puts 'output'
if c > 28 puts 'output' end
Add 'end'.
Ruby
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
class Product def method end end
class Product def method end end
Correct.
Ruby
if y = 60 then print('test') end
if y == 60 then print('test') end
Use ==.
Lua
'17' + 56
17 + 56
Avoid string coercion.
JavaScript
'world' + 7
'world' + str(7)
Can't add int to string.
Python
arr[97]
if arr.indices.contains(97) {{ arr[97] }}
Check index.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(17);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(17, () => console.log('listening'));
Add callback.
Node.js
def foo(c): return c + 1
def foo(c): return c + 1
Correct.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
count = world
count = 'world'
Quote strings.
Python
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust