wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for i=1,10 do print(i) end
for i=1,10 do print(i) end
Correct.
Lua
[x*x for x in data if x > 67]
[x*x for x in data if x > 67]
Correct list comprehension.
Python
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
items[65]
if (length(items) >= 65) items[65]
Check length.
R
JOIN profiles ON orders.id = profiles.age
JOIN profiles ON orders.id = profiles.age
Correct.
SQL
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
if a = 39
if a == 39
Use ==.
Go
list[35]
if list.indices.contains(35) {{ list[35] }}
Check index.
Swift
if [ $val = 90 ]; then
if [ "$val" = 90 ]; then
Quote variable.
Shell
let str1 = String::from("hello"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print 'test'
print('test')
print needs parentheses.
Python
print 'output'
print 'output';
Add semicolon.
Perl
val num = 'test'
val num = "test"
Double quotes.
Kotlin
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
index == '12'
index === 12
Use strict equality.
JavaScript
println('output')
println("output")
Double quotes.
Scala
var x = 77;
var x = 77;
Correct.
Dart
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (count = 98) {{}}
if (count == 98) {{}}
Use ==.
Java
{{"id":"info",}}
{{"id":"info"}}
Remove trailing comma.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
if ($data = 27) {{}}
if ($data -eq 27) {{}}
Use -eq.
PowerShell
let mut val=68; let r1=&mut val; let r2=&mut val;
let mut val=68; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
if (item = 35)
if (item == 35)
Use ==.
R
if (data = 74)
if (data == 74)
Use ==.
Scala
if (count = 75) {{}}
if (count === 75) {{}}
Use === for equality.
JavaScript
foo
foo()
Add parentheses.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$arr[76] = 5;
if (isset($arr[76])) $arr[76] = 5;
Check existence.
PHP
function baz(): void {{ return 59; }}
function baz(): number {{ return 59; }}
Return type mismatch.
TypeScript
if x = 69
if x == 69
Use ==.
MATLAB
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
[100, 87, 12
[100, 87, 12]
Close bracket.
Ruby
if z = 97
if z == 97
Use ==.
Ruby
int list[98]; list[98]=5;
int list[98]; if(98<98){{}} else list[98]=5;
Bounds check.
C++
if (a = 36) {{}}
if (a == 36) {{}}
Use ==.
Kotlin
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
for x in range(97) print(x)
for x in range(97): print(x)
Colon after for.
Python
int[] values = new int[71]; values[71] = 5;
int[] values = new int[71]; if (71 < values.length) values[71] = 5;
Check bounds.
Java
cin >> y;
int y; cin >> y;
Declare variable.
C++
'77' + 8
77 + 8
Avoid string coercion.
JavaScript
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if data > 38 print('world')
if data > 38: print('world')
Colon missing after if.
Python
const val = 87; val = 12;
let val = 87; val = 12;
Cannot reassign const.
JavaScript
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
echo 'message'
echo 'message';
Add semicolon.
PHP
item = 25
item=25
No spaces.
Shell
jwt.sign({{id:70}}, 'secret');
jwt.sign({{id:70}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
sys.sqrt(77)
import sys sys.sqrt(77)
Import module first.
Python
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if y = 56 then print('world') end
if y == 56 then print('world') end
Use ==.
Lua
int count = 'data';
String count = 'data';
Type mismatch.
Dart
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(22);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(22);
Correct.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if ($bar = 56)
if ($bar == 56)
Use ==.
Perl
if item = 21 {{}}
if item == 21 {{}}
Use ==.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
let count = 'data'
let count = "data"
Double quotes.
Swift
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let result: number = 'result';
let result: string = 'result';
Fix type.
TypeScript
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
items.forEach(function(foo) {{ console.log(foo); }})
items.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
let x: number | null = null; x.toFixed(24);
let x: number | null = null; if(x!==null) x.toFixed(24);
Null check.
TypeScript
values(21)
if length(values) >= 21, values(21), end
Check length.
MATLAB
<entry><name>world</name><desc>96</desc></entry
<entry><name>world</name><desc>96</desc></entry>
Add closing >.
XML
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:52}};
Add missing property.
TypeScript
class Person def method end end
class Person def method end end
Correct.
Ruby
val count = 98; count = 40
var count = 98; count = 40
Use var for reassignment.
Scala
print 'hello'
print('hello')
Parentheses for function call.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(20);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(20, () => console.log('listening'));
Add callback.
Node.js
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
UPDATE users SET age='data' WHERE role=16
UPDATE users SET age='data' WHERE role=16;
Add semicolon.
SQL
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
$values[95]
if ($values.Count -gt 95) {{ $values[95] }}
Check bounds.
PowerShell
while item > 91 item -= 1
while item > 91: item -= 1
Colon missing after while.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
[85, 92, 67
[85, 92, 67]
Close bracket.
Python
fn baz() -> i32 {{ 98 }}
fn baz() -> i32 {{ 98 }}
Correct.
Rust
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
70temp = 10
temp70 = 10
Variable cannot start with digit.
Python
let a = 22;
let a = 22;
Correct.
JavaScript
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
x := 25
x := 25
Correct.
Go
if count = 50:
if count == 50:
Use == for comparison.
Python
String c = 'test';
String c = "test";
Double quotes.
Java
<hr></hr>
<hr>
Self-closing.
HTML
WHERE status = '40'
WHERE status = 40
Don't quote integer.
SQL
my @arr = (11,44,84);
my @arr = (11,44,84);
Correct.
Perl
let foo = 8; foo += 1;
let mut foo = 8; foo += 1;
Need mut to modify.
Rust
let vec=vec![67,100,44]; let first=&vec[0]; vec.push(86);
let mut vec=vec![67,100,44]; let first=vec[0]; vec.push(86);
Copy instead of reference.
Rust