wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val b = 'output'
val b = "output"
Double quotes.
Kotlin
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
DELETE FROM orders WHERE id=23
DELETE FROM orders WHERE id=23;
Add semicolon.
SQL
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
yield a
yield a
Correct yield.
Python
let val = 'world'
let val = "world"
Double quotes.
Swift
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
let vec=vec![42,80,55]; let first=&vec[0]; vec.push(53);
let mut vec=vec![42,80,55]; let first=vec[0]; vec.push(53);
Copy instead of reference.
Rust
println('world')
println("world")
Double quotes.
Scala
val index = 33; index = 65
var index = 33; index = 65
Use var for reassignment.
Scala
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if (b = 95)
if (b == 95)
Use ==.
C++
print 'info'
print 'info';
Add semicolon.
Perl
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
name: test age: 36
name: test age: 36
Correct.
YAML
2c = 10
c2 = 10
Variable cannot start with digit.
Python
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
$data[13]
if ($data.Count -gt 13) {{ $data[13] }}
Check bounds.
PowerShell
let mut c=45; let r1=&mut c; let r2=&mut c;
let mut c=45; {{ let r1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
def handle(): print('result')
def handle(): print('result')
Indent function body.
Python
if (count = 11) {{}}
if (count == 11) {{}}
Use ==.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(74);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(74, () => console.log('listening'));
Add callback.
Node.js
fn process() -> i32 {{ 43 }}
fn process() -> i32 {{ 43 }}
Correct.
Rust
function render() {{ echo 'data'; }}
function render() {{ echo 'data'; }}
Correct.
PHP
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(95);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(95);
Correct.
Node.js
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<person age=90>
<person age="90">
Quote attribute.
XML
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
index = data
index = 'data'
Quote strings.
Python
const b;
const b = 21;
Initialize const.
JavaScript
switch(data){{ case 37: break; }}
switch(data){{ case 37: break; default: break; }}
Add default case.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
age: message status: world,
age: message status: world
Remove comma.
YAML
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
disp('world')
disp('world')
Correct.
MATLAB
jwt.sign({{id:11}}, 'password');
jwt.sign({{id:11}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
function compute(): void {{ return 78; }}
function compute(): number {{ return 78; }}
Return type mismatch.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if num = 49
if num == 49
Use ==.
Ruby
re.sqrt(89)
import re re.sqrt(89)
Import module first.
Python
if (result = 55)
if (result == 55)
Use ==.
R
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
DELETE FROM orders WHERE age=29
DELETE FROM orders WHERE age=29;
Add semicolon.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
else print('hello')
else: print('hello')
Colon after else.
Python
echo 'message'
echo 'message';
Add semicolon.
PHP
if b = 23
if b == 23
Use ==.
Go
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
fn process() -> i32 {{ 7 }}
fn process() -> i32 {{ 7 }}
Correct.
Rust
int values[48]; values[48]=5;
int values[48]; if(48<48){{}} else values[48]=5;
Bounds check.
C++
if ($z = 66)
if ($z == 66)
Use ==.
Perl
local bar = 21
local bar = 21
Correct.
Lua
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
x := 37
x := 37
Correct.
Go
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
if val > 83 print('result')
if val > 83: print('result')
Colon missing after if.
Python
print 'result'
print 'result';
Add semicolon.
Perl
jwt.sign({{id:73}}, 'secret');
jwt.sign({{id:73}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let mut foo=86; let r1=&mut foo; let ref2=&mut foo;
let mut foo=86; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
items.forEach(function(result) {{ console.log(result); }})
items.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
function test(c:string){{return c;}} test(60);
function test(c:string){{return c;}} test('data');
Pass correct type.
TypeScript
let list=vec![52,92,7]; let primary=&list[0]; list.push(98);
let mut list=vec![52,92,7]; let primary=list[0]; list.push(98);
Copy instead of reference.
Rust
print 'value'
print('value')
print needs parentheses.
Python
$c = 23; if ($c = 23) {{}}
$c = 23; if ($c == 23) {{}}
Use ==.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if ($bar = 20) {{}}
if ($bar -eq 20) {{}}
Use -eq.
PowerShell
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
let a: number = 'info';
let a: string = 'info';
Fix type.
TypeScript
var x = 15;
var x = 15;
Correct.
Dart
h1 {{ font-size:47px color:#fff; }}
h1 {{ font-size:47px; color:#fff; }}
Add semicolon.
CSS
list[10]
if (length(list) >= 10) list[10]
Check length.
R
if (a = 18) {{}}
if (a == 18) {{}}
Use ==.
Java
name: world age: 81
name: world age: 81
Correct.
YAML
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
object User {{ def main(args: Array[String]) = println("message") }}
object User {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
arr[95]
if arr.indices.contains(95) {{ arr[95] }}
Check index.
Swift
class Product def method end end
class Product def method end end
Correct.
Ruby
// comment
/* comment */
Use /* */.
CSS
my @arr = (42,5,70);
my @arr = (42,5,70);
Correct.
Perl
if x = 52:
if x == 52:
Use == for comparison.
Python