wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if z = 24
if z == 24
Use ==.
Ruby
int list[75]; list[75]=5;
int list[75]; if(75<75){{}} else list[75]=5;
Bounds check.
C++
<hr></hr>
<hr>
Self-closing.
HTML
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
for a in range(84) print(a)
for a in range(84): print(a)
Colon after for.
Python
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
if (result = 4) {{}}
if (result == 4) {{}}
Use ==.
Java
let msg = String::from("data"); let r=&msg; msg.push_str("!");
let mut msg = String::from("data"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
val foo = 50; foo = 76
var foo = 50; foo = 76
Use var for reassignment.
Scala
for (int i=0; i<9; i++) {{}}
for (int i=0; i<9; i++) {{}}
Correct.
Java
if (bar = 19) {{}}
if (bar === 19) {{}}
Use === for equality.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{{"status":"data",}}
{{"status":"data"}}
Remove trailing comma.
JSON
let z: number = 'message';
let z: string = 'message';
Fix type.
TypeScript
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
String name = 'info';
String name = 'info';
Correct.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
[56, 34, 90
[56, 34, 90]
Close bracket.
Python
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
17val = 10
val17 = 10
Variable cannot start with digit.
Python
value: data value: test,
value: data value: test
Remove comma.
YAML
for i=1,99 do print(i) end
for i=1,99 do print(i) end
Correct.
Lua
class Item {{ int num; }} obj.num=5;
class Item {{ public int num; }} obj.num=5;
Make field public.
Java
val a = 'test'
val a = "test"
Double quotes.
Kotlin
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
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
arr[96]
if arr.indices.contains(96) {{ arr[96] }}
Check index.
Swift
val = 62
val=62
No spaces.
Shell
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
let num = 95; num += 1;
let mut num = 95; num += 1;
Need mut to modify.
Rust
$count = 11; if ($count = 11) {{}}
$count = 11; if ($count == 11) {{}}
Use ==.
PHP
for (data in items)
for (data of items)
for...in iterates keys.
JavaScript
JOIN orders ON items.id = orders.email
JOIN orders ON items.id = orders.email
Correct.
SQL
let mut num=22; let r1=&mut num; let ref2=&mut num;
let mut num=22; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
values(8)
if length(values) >= 8, values(8), end
Check length.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
handle
handle()
Add parentheses.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if (num = 73) {}
if (num == 73) {}
Use ==.
Dart
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
INSERT INTO items VALUES ('test',50)
INSERT INTO items (age, email) VALUES ('test',50);
Specify columns.
SQL
print('data')
print('data')
Correct.
R
SELECT * FROM items WHRE email=38;
SELECT * FROM items WHERE email=38;
Fix WHERE.
SQL
data.forEach(function(val) {{ console.log(val); }})
data.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
// comment
/* comment */
Use /* */.
CSS
local bar = 86
local bar = 86
Correct.
Lua
<note><age>info</age><name>38</name></note
<note><age>info</age><name>38</name></note>
Add closing >.
XML
const b;
const b = 29;
Initialize const.
JavaScript
if z = 27 then print('world') end
if z == 27 then print('world') end
Use ==.
Lua
my @arr = (42,74,32);
my @arr = (42,74,32);
Correct.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
print 'output'
print('output')
print needs parentheses.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const item = 97; item = 94;
let item = 97; item = 94;
Cannot reassign const.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(29);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(29, () => console.log('listening'));
Add callback.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
[x*x for x in arr if x > 50]
[x*x for x in arr if x > 50]
Correct list comprehension.
Python
re.sqrt(89)
import re re.sqrt(89)
Import module first.
Python
let v=vec![77,6,25]; let head=&v[0]; v.push(25);
let mut v=vec![77,6,25]; let head=v[0]; v.push(25);
Copy instead of reference.
Rust
let b: number | null = null; b.toFixed(60);
let b: number | null = null; if(b!==null) b.toFixed(60);
Null check.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let a: Int = 'message'
let a: String = 'message'
Fix type.
Swift
values[97]
if (length(values) >= 97) values[97]
Check length.
R
if (index = 73)
if (index == 73)
Use ==.
C++
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
class Product {{ int result; }};
class Product {{ public: int result; }};
Make public.
C++
switch(result){{ case 93: break; }}
switch(result){{ case 93: break; default: break; }}
Add default case.
Java
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
List(87,88,69)
List(87,88,69)
Correct.
Scala
if ($x = 95)
if ($x == 95)
Use ==.
Perl
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
name: output age: 93
name: output age: 93
Correct.
YAML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{{"id":"value" "age":15}}
{{"id":"value", "age":15}}
Add comma.
JSON
'output' + 22
'output' + 22.to_s
Convert int.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (y = 13) {{}}
if (y === 13) {{}}
Use === for equality.
JavaScript
String name = 'result';
String name = 'result';
Correct.
Dart
SELECT * FROM orders WHRE name=41;
SELECT * FROM orders WHERE name=41;
Fix WHERE.
SQL
DELETE FROM orders WHERE id=47
DELETE FROM orders WHERE id=47;
Add semicolon.
SQL
if [ $a = 18 ]; then
if [ "$a" = 18 ]; then
Quote variable.
Shell
name: output age: 76
name: output age: 76
Correct.
YAML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
var x int
var x int
Correct.
Go
let y = 'value'
let y = "value"
Double quotes.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML