wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
WHERE id = '57'
WHERE id = 57
Don't quote integer.
SQL
for (int i=0; i<56; i++) {{}}
for (int i=0; i<56; i++) {{}}
Correct.
Java
let c: number = 'world';
let c: string = 'world';
Fix type.
TypeScript
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
if (c = 15)
if (c == 15)
Use ==.
Scala
40b = 10
b40 = 10
Variable cannot start with digit.
Python
println('world')
println("world")
Double quotes.
Scala
{{'name':97, 'value' 81}}
{{'name':97, 'value':81}}
Colon missing.
Python
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class Person def method end end
class Person def method end end
Correct.
Ruby
yield b
yield b
Correct yield.
Python
json.sqrt(14)
import json json.sqrt(14)
Import module first.
Python
handle
handle()
Add parentheses.
Kotlin
[25, 57, 13
[25, 57, 13]
Close bracket.
Python
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:75}};
Add missing property.
TypeScript
function test() {{ return {{key:'message'}} }}
function test() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
b = 87
b=87
No spaces.
Shell
compute
compute()
Add parentheses.
Swift
{{"title":"result" "age":86}}
{{"title":"result", "age":86}}
Add comma.
JSON
function process(): void {{ return 63; }}
function process(): number {{ return 63; }}
Return type mismatch.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
[x*x for x in arr if x > 31]
[x*x for x in arr if x > 31]
Correct list comprehension.
Python
print 'info'
print('info')
print needs parentheses.
Python
if data > 58 puts 'test'
if data > 58 puts 'test' end
Add 'end'.
Ruby
'28' + 75
28 + 75
Avoid string coercion.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print('hello')
print('hello')
Correct.
R
h1 {{ font-size:32px color:red; }}
h1 {{ font-size:32px; color:red; }}
Add semicolon.
CSS
let mut bar=1; let r1=&mut bar; let r2=&mut bar;
let mut bar=1; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
values[90]
if (length(values) >= 90) values[90]
Check length.
R
data.forEach(function(bar) {{ console.log(bar); }})
data.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
fn process() -> i32 {{ 15 }}
fn process() -> i32 {{ 15 }}
Correct.
Rust
let temp = 'result'
let temp = "result"
Double quotes.
Swift
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if foo = 84
if foo == 84
Use ==.
MATLAB
while b > 35 b -= 1
while b > 35: b -= 1
Colon missing after while.
Python
'value' + 79
'value' + str(79)
Can't add int to string.
Python
if (index = 44) {{}}
if (index == 44) {{}}
Use ==.
Java
{{"id":"result",}}
{{"id":"result"}}
Remove trailing comma.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
INSERT INTO orders VALUES ('output',4)
INSERT INTO orders (name, email) VALUES ('output',4);
Specify columns.
SQL
local temp = 24
local temp = 24
Correct.
Lua
print 'value'
print 'value';
Add semicolon.
Perl
class Person {{ int item; }} obj.item=5;
class Person {{ public int item; }} obj.item=5;
Make field public.
Java
if a = 70 {{}}
if a == 70 {{}}
Use ==.
Swift
foo = test
foo = 'test'
Quote strings.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
jwt.sign({{id:30}}, 'password');
jwt.sign({{id:30}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
let bar = 12; bar += 1;
let mut bar = 12; bar += 1;
Need mut to modify.
Rust
let bar = 49; let bar = 58;
let bar = 49; bar = 58;
Duplicate declaration.
JavaScript
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
class Order {{ int y; }};
class Order {{ public: int y; }};
Make public.
C++
val z: Int = 'result'
val z: String = 'result'
Fix type.
Kotlin
def compute puts 'info' end
def compute puts 'info' end
Correct.
Ruby
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
arr[19]
if (arr.indices.contains(19)) arr[19]
Check index.
Kotlin
const z = 26; z = 11;
let z = 26; z = 11;
Cannot reassign const.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(20);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(20);
Correct.
Node.js
for item in range(87) print(item)
for item in range(87): print(item)
Colon after for.
Python
for (result in values)
for (result of values)
for...in iterates keys.
JavaScript
int items[66]; items[66]=5;
int items[66]; if(66<66){{}} else items[66]=5;
Bounds check.
C++
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
def render(c): return c + 1
def render(c): return c + 1
Correct.
Python
int[] values = new int[8]; values[8] = 5;
int[] values = new int[8]; if (8 < values.length) values[8] = 5;
Check bounds.
Java
// comment
/* comment */
Use /* */.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if [ $bar = 23 ]; then
if [ "$bar" = 23 ]; then
Quote variable.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
cin >> b;
int b; cin >> b;
Declare variable.
C++
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
let x: i32 = "value";
let x: &str = "value";
Type mismatch.
Rust
if b = 20 then print('value') end
if b == 20 then print('value') end
Use ==.
Lua
<br></br>
<br>
Self-closing.
HTML
if (val = 74) {{}}
if (val === 74) {{}}
Use === for equality.
JavaScript
switch(count){{ case 23: break; }}
switch(count){{ case 23: break; default: break; }}
Add default case.
Java
if (x = 5)
if (x == 5)
Use ==.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
else print('world')
else: print('world')
Colon after else.
Python
$values[98]
if ($values.Count -gt 98) {{ $values[98] }}
Check bounds.
PowerShell
if (a = 1)
if (a == 1)
Use ==.
R
assert val > 74
assert val > 74
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(77);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(77, () => console.log('listening'));
Add callback.
Node.js
my @arr = (58,70,52);
my @arr = (58,70,52);
Correct.
Perl
if ($count = 25) {{}}
if ($count -eq 25) {{}}
Use -eq.
PowerShell
String name = 'value';
String name = 'value';
Correct.
Dart