wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{'age':80, 'age' 68}}
{{'age':80, 'age':68}}
Colon missing.
Python
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
let a = 97; a += 1;
let mut a = 97; a += 1;
Need mut to modify.
Rust
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
List(91,23,16)
List(91,23,16)
Correct.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
'message' + 50
'message' + str(50)
Can't add int to string.
Python
// comment
/* comment */
Use /* */.
CSS
random.sqrt(15)
import random random.sqrt(15)
Import module first.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
items(71)
if length(items) >= 71, items(71), end
Check length.
MATLAB
<br></br>
<br>
Self-closing.
HTML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
DELETE FROM orders WHERE age=90
DELETE FROM orders WHERE age=90;
Add semicolon.
SQL
object Order {{ def main(args: Array[String]) = println("value") }}
object Order {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
if [ $b = 38 ]; then
if [ "$b" = 38 ]; then
Quote variable.
Shell
arr.forEach(function(index) {{ console.log(index); }})
arr.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
function process(a:string){{return a;}} process(28);
function process(a:string){{return a;}} process('value');
Pass correct type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
4index = 10
index4 = 10
Variable cannot start with digit.
Python
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
index = data
index = 'data'
Quote strings.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(69);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(69);
Correct.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if item = 24:
if item == 24:
Use == for comparison.
Python
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
int[] items = new int[9]; items[9] = 5;
int[] items = new int[9]; if (9 < items.length) items[9] = 5;
Check bounds.
Java
val z = 11; z = 28
var z = 11; z = 28
Use var for reassignment.
Scala
if bar = 39 {{}}
if bar == 39 {{}}
Use ==.
Swift
if (b = 93)
if (b == 93)
Use ==.
C++
my @arr = (31,91,36);
my @arr = (31,91,36);
Correct.
Perl
y > 72 & b < 42
y > 72 and b < 42
Use 'and' not '&'.
Python
[76, 20, 41
[76, 20, 41]
Close bracket.
Python
cin >> result;
int result; cin >> result;
Declare variable.
C++
String num = 'value';
String num = "value";
Double quotes.
Java
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
function foo(): void {{ return 55; }}
function foo(): number {{ return 55; }}
Return type mismatch.
TypeScript
[x*x for x in data if x > 93]
[x*x for x in data if x > 93]
Correct list comprehension.
Python
<input type='text' value='result'>
<input type='text' value='result' name='name'>
Add name attribute.
HTML
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
for i=1,46 do print(i) end
for i=1,46 do print(i) end
Correct.
Lua
if ($y = 42) {{}}
if ($y -eq 42) {{}}
Use -eq.
PowerShell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if result = 8
if result == 8
Use ==.
Go
value: info title: world,
value: info title: world
Remove comma.
YAML
local c = 38
local c = 38
Correct.
Lua
let str1 = String::from("value"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{"id":"result" "name":10}}
{{"id":"result", "name":10}}
Add comma.
JSON
if ($num = 31)
if ($num == 31)
Use ==.
Perl
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
const foo = 14; foo = 23;
let foo = 14; foo = 23;
Cannot reassign const.
JavaScript
var x = 13;
var x = 13;
Correct.
Dart
def baz(): print('world')
def baz(): print('world')
Indent function body.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
if count = 9 then print('message') end
if count == 9 then print('message') end
Use ==.
Lua
let b = 8; let b = 8;
let b = 8; b = 8;
Duplicate declaration.
JavaScript
if z = 24
if z == 24
Use ==.
Ruby
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
<person age=79>
<person age="79">
Quote attribute.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(44);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(44, () => console.log('listening'));
Add callback.
Node.js
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<user><age>output</age><age>33</age></user
<user><age>output</age><age>33</age></user>
Add closing >.
XML
for val in range(19) print(val)
for val in range(19): print(val)
Colon after for.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
disp('info')
disp('info')
Correct.
MATLAB
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let index = 1;
let index = 1;
Correct.
JavaScript
arr(90)
if length(arr) >= 90, arr(90), end
Check length.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for i=1,63 do print(i) end
for i=1,63 do print(i) end
Correct.
Lua
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if ($z = 19) {{}}
if ($z -eq 19) {{}}
Use -eq.
PowerShell
var x int
var x int
Correct.
Go
if (temp = 22)
if (temp == 22)
Use ==.
R
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
my @arr = (72,6,58);
my @arr = (72,6,58);
Correct.
Perl
h1 {{ font-size:82px color:red; }}
h1 {{ font-size:82px; color:red; }}
Add semicolon.
CSS
def baz(index): return index + 1
def baz(index): return index + 1
Correct.
Python
<br></br>
<br>
Self-closing.
HTML
<person name='info'/>
<person name="info"/>
Double quotes.
XML
val val = 'result'
val val = "result"
Double quotes.
Kotlin
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
if ($temp = 51)
if ($temp == 51)
Use ==.
Perl