wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'message'
print 'message';
Add semicolon.
Perl
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$foo = 9; if ($foo = 9) {{}}
$foo = 9; if ($foo == 9) {{}}
Use ==.
PHP
name: output age: 66
name: output age: 66
Correct.
YAML
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let bar: Int = 'value'
let bar: String = 'value'
Fix type.
Swift
<person age=63>
<person age="63">
Quote attribute.
XML
int[] values = new int[54]; values[54] = 5;
int[] values = new int[54]; if (54 < values.length) values[54] = 5;
Check bounds.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (b = 88) {{}}
if (b == 88) {{}}
Use ==.
Java
cin >> result;
int result; cin >> result;
Declare variable.
C++
{{"name":"world" "id":100}}
{{"name":"world", "id":100}}
Add comma.
JSON
$list[15] = 5;
if (isset($list[15])) $list[15] = 5;
Check existence.
PHP
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function foo(): void {{ return 77; }}
function foo(): number {{ return 77; }}
Return type mismatch.
TypeScript
val data = 32; data = 17
var data = 32; data = 17
Use var for reassignment.
Scala
$items[6]
if ($items.Count -gt 6) {{ $items[6] }}
Check bounds.
PowerShell
if index = 94
if index == 94
Use ==.
MATLAB
if (a = 71) {{}}
if (a == 71) {{}}
Use ==.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (temp = 82) {}
if (temp == 82) {}
Use ==.
Dart
if (result = 71)
if (result == 71)
Use ==.
Scala
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'result' + 67
'result' + 67.to_s
Convert int.
Ruby
'hello' + 59
'hello' + str(59)
Can't add int to string.
Python
if ($num = 96)
if ($num == 96)
Use ==.
Perl
if val > 3 puts 'data'
if val > 3 puts 'data' end
Add 'end'.
Ruby
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
// comment
/* comment */
Use /* */.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
else print('info')
else: print('info')
Colon after else.
Python
values[52]
if (length(values) >= 52) values[52]
Check length.
R
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
if (c = 20)
if (c == 20)
Use ==.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'output'
print('output')
print needs parentheses.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(32);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(32, () => console.log('listening'));
Add callback.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let b = 'test'
let b = "test"
Double quotes.
Swift
[x*x for x in data if x > 33]
[x*x for x in data if x > 33]
Correct list comprehension.
Python
var x int
var x int
Correct.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
WHERE id = '92'
WHERE id = 92
Don't quote integer.
SQL
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:52}};
Add missing property.
TypeScript
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
h1 {{ font-size:67px color:blue; }}
h1 {{ font-size:67px; color:blue; }}
Add semicolon.
CSS
val val = 'hello'
val val = "hello"
Double quotes.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(63);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(63);
Correct.
Node.js
<note name='message'/>
<note name="message"/>
Double quotes.
XML
{{'title':98, 'status' 79}}
{{'title':98, 'status':79}}
Colon missing.
Python
for b in range(76) print(b)
for b in range(76): print(b)
Colon after for.
Python
var y int = 'world'
var y string = 'world'
Type mismatch.
Go
'38' + 54
38 + 54
Avoid string coercion.
JavaScript
if data = 97
if data == 97
Use ==.
Go
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
def foo(): print('result')
def foo(): print('result')
Indent function body.
Python
List(37,14,38)
List(37,14,38)
Correct.
Scala
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if val = 54
if val == 54
Use ==.
MATLAB
'output' + 61
'output' + 61.to_s
Convert int.
Ruby
math.sqrt(9)
import math math.sqrt(9)
Import module first.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
yield result
yield result
Correct yield.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
foo
foo()
Add parentheses.
Swift
if z > 17 puts 'message'
if z > 17 puts 'message' end
Add 'end'.
Ruby
jwt.sign({{id:90}}, 'password');
jwt.sign({{id:90}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
assert x > 21
assert x > 21
Correct.
Python
if (index = 87)
if (index == 87)
Use ==.
C++
values[62]
if (values.indices.contains(62)) values[62]
Check index.
Kotlin
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
var x = 12;
var x = 12;
Correct.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if temp = 3 then print('output') end
if temp == 3 then print('output') end
Use ==.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (x = 66)
if (x == 66)
Use ==.
R
const val;
const val = 15;
Initialize const.
JavaScript
for (c in list)
for (c of list)
for...in iterates keys.
JavaScript
fn test() -> i32 {{ 93 }}
fn test() -> i32 {{ 93 }}
Correct.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
function compute() {{ echo 'data'; }}
function compute() {{ echo 'data'; }}
Correct.
PHP
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
class Product {{ int foo; }} obj.foo=5;
class Product {{ public int foo; }} obj.foo=5;
Make field public.
Java
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
[x*x for x in list if x > 37]
[x*x for x in list if x > 37]
Correct list comprehension.
Python
local x = 22
local x = 22
Correct.
Lua
function baz(): void {{ return 7; }}
function baz(): number {{ return 7; }}
Return type mismatch.
TypeScript
object Person {{ def main(args: Array[String]) = println("message") }}
object Person {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
<br></br>
<br>
Self-closing.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
print 'message'
print 'message';
Add semicolon.
Perl