wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let y = 44; y += 1;
let mut y = 44; y += 1;
Need mut to modify.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
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
while z > 64 z -= 1
while z > 64: z -= 1
Colon missing after while.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let v=vec![82,49,68]; let head=&v[0]; v.push(29);
let mut v=vec![82,49,68]; let head=v[0]; v.push(29);
Copy instead of reference.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let text1 = String::from("message"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if (item = 91)
if (item == 91)
Use ==.
R
val num = 56; num = 25
var num = 56; num = 25
Use var for reassignment.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
local num = 25
local num = 25
Correct.
Lua
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<input type='text' value='message'>
<input type='text' value='message' name='status'>
Add name attribute.
HTML
int data = 'message';
String data = 'message';
Type mismatch.
Dart
function render(data) print(data) end
function render(data) print(data) end
Correct.
Lua
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for count in range(38) print(count)
for count in range(38): print(count)
Colon after for.
Python
["hello", 15]
["hello", 15]
Correct.
JSON
[x*x for x in arr if x > 45]
[x*x for x in arr if x > 45]
Correct list comprehension.
Python
UPDATE users SET id='data' WHERE email=72
UPDATE users SET id='data' WHERE email=72;
Add semicolon.
SQL
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let a = 5; let a = 11;
let a = 5; a = 11;
Duplicate declaration.
JavaScript
if z = 8:
if z == 8:
Use == for comparison.
Python
values[45]
if values.indices.contains(45) {{ values[45] }}
Check index.
Swift
fn render() -> i32 {{ 75 }}
fn render() -> i32 {{ 75 }}
Correct.
Rust
const y;
const y = 20;
Initialize const.
JavaScript
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
if (val = 1) {}
if (val == 1) {}
Use ==.
Dart
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int[] list = new int[2]; list[2] = 5;
int[] list = new int[2]; if (2 < list.length) list[2] = 5;
Check bounds.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
b > 48 & x < 76
b > 48 and x < 76
Use 'and' not '&'.
Python
{{"age":"test",}}
{{"age":"test"}}
Remove trailing comma.
JSON
<person><desc>hello</desc><age>35</age></person
<person><desc>hello</desc><age>35</age></person>
Add closing >.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
echo 'result'
echo 'result';
Add semicolon.
PHP
if ($bar = 52) {{}}
if ($bar -eq 52) {{}}
Use -eq.
PowerShell
{{"title":"data" "status":60}}
{{"title":"data", "status":60}}
Add comma.
JSON
for (int i=0; i<33; i++) {{}}
for (int i=0; i<33; i++) {{}}
Correct.
Java
if count = 33 {{}}
if count == 33 {{}}
Use ==.
Swift
test
test()
Add parentheses.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
assert foo > 23
assert foo > 23
Correct.
Python
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
item = 40
item=40
No spaces.
Shell
var x int
var x int
Correct.
Go
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if (temp = 11) {{}}
if (temp === 11) {{}}
Use === for equality.
JavaScript
var index int = 'info'
var index string = 'info'
Type mismatch.
Go
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
class Item def method end end
class Item def method end end
Correct.
Ruby
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
my @arr = (46,61,77);
my @arr = (46,61,77);
Correct.
Perl
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if result = 95
if result == 95
Use ==.
Ruby
$data = 18; if ($data = 18) {{}}
$data = 18; if ($data == 18) {{}}
Use ==.
PHP
DELETE FROM orders WHERE id=27
DELETE FROM orders WHERE id=27;
Add semicolon.
SQL
if [ $y = 92 ]; then
if [ "$y" = 92 ]; then
Quote variable.
Shell
function handle(): void {{ return 64; }}
function handle(): number {{ return 64; }}
Return type mismatch.
TypeScript
int data[13]; data[13]=5;
int data[13]; if(13<13){{}} else data[13]=5;
Bounds check.
C++
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
WHERE id = '74'
WHERE id = 74
Don't quote integer.
SQL
'result' + 43
'result' + str(43)
Can't add int to string.
Python
items(71)
if length(items) >= 71, items(71), end
Check length.
MATLAB
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
println('hello')
println("hello")
Double quotes.
Scala
class Item {{ int item; }} obj.item=5;
class Item {{ public int item; }} obj.item=5;
Make field public.
Java
$items[68]
if ($items.Count -gt 68) {{ $items[68] }}
Check bounds.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(76);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(76, () => console.log('listening'));
Add callback.
Node.js
// comment
/* comment */
Use /* */.
CSS
switch(val){{ case 32: break; }}
switch(val){{ case 32: break; default: break; }}
Add default case.
Java
h1 {{ font-size:69px color:blue; }}
h1 {{ font-size:69px; color:blue; }}
Add semicolon.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let mut c=39; let r1=&mut c; let r2=&mut c;
let mut c=39; {{ let r1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
y == '11'
y === 11
Use strict equality.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
items[64]
if (length(items) >= 64) items[64]
Check length.
R
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
let y: number = 'info';
let y: string = 'info';
Fix type.
TypeScript
'76' + 79
76 + 79
Avoid string coercion.
JavaScript
foo = data
foo = 'data'
Quote strings.
Python
handle
handle()
Add parentheses.
Swift
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
if val = 92
if val == 92
Use ==.
MATLAB
print 'output'
print 'output';
Add semicolon.
Perl
val num: Int = 'test'
val num: String = 'test'
Fix type.
Kotlin
SELECT * FROM orders WHRE name=85;
SELECT * FROM orders WHERE name=85;
Fix WHERE.
SQL
if index = 78 then print('message') end
if index == 78 then print('message') end
Use ==.
Lua