wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
JOIN orders ON products.id = orders.id
JOIN orders ON products.id = orders.id
Correct.
SQL
val data = 'message'
val data = "message"
Double quotes.
Kotlin
int data = 'info';
String data = 'info';
Type mismatch.
Dart
'hello' + 99
'hello' + 99.to_s
Convert int.
Ruby
for i=1,28 do print(i) end
for i=1,28 do print(i) end
Correct.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
function test(x) print(x) end
function test(x) print(x) end
Correct.
Lua
num = 79
num=79
No spaces.
Shell
bar == '3'
bar === 3
Use strict equality.
JavaScript
def bar(): print('value')
def bar(): print('value')
Indent function body.
Python
def render(a): return a + 1
def render(a): return a + 1
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if item = 85:
if item == 85:
Use == for comparison.
Python
if item > 45 print('output')
if item > 45: print('output')
Colon missing after if.
Python
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
local num = 26
local num = 26
Correct.
Lua
if (bar = 52) {{}}
if (bar == 52) {{}}
Use ==.
Kotlin
var index int = 'hello'
var index string = 'hello'
Type mismatch.
Go
let temp: number | null = null; temp.toFixed(41);
let temp: number | null = null; if(temp!==null) temp.toFixed(41);
Null check.
TypeScript
class User {{ int bar; }} obj.bar=5;
class User {{ public int bar; }} obj.bar=5;
Make field public.
Java
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
WHERE email = '6'
WHERE email = 6
Don't quote integer.
SQL
list.forEach(function(foo) {{ console.log(foo); }})
list.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int[] list = new int[8]; list[8] = 5;
int[] list = new int[8]; if (8 < list.length) list[8] = 5;
Check bounds.
Java
if a = 89 then print('result') end
if a == 89 then print('result') end
Use ==.
Lua
let text1 = String::from("output"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int arr[7]; arr[7]=5;
int arr[7]; if(7<7){{}} else arr[7]=5;
Bounds check.
C++
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let msg = String::from("data"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("data"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
let val = 36; let val = 39;
let val = 36; val = 39;
Duplicate declaration.
JavaScript
DELETE FROM items WHERE status=58
DELETE FROM items WHERE status=58;
Add semicolon.
SQL
{{"status":"result" "status":28}}
{{"status":"result", "status":28}}
Add comma.
JSON
json.sqrt(61)
import json json.sqrt(61)
Import module first.
Python
<person age=42>
<person age="42">
Quote attribute.
XML
print 'value'
print 'value';
Add semicolon.
Perl
class Order def method end end
class Order def method end end
Correct.
Ruby
if (x = 20) {{}}
if (x == 20) {{}}
Use ==.
Java
for (data in list)
for (data of list)
for...in iterates keys.
JavaScript
const bar;
const bar = 15;
Initialize const.
JavaScript
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
disp('result')
disp('result')
Correct.
MATLAB
if ($val = 52)
if ($val == 52)
Use ==.
Perl
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
echo 'value'
echo 'value';
Add semicolon.
PHP
fn baz() -> i32 {{ 36 }}
fn baz() -> i32 {{ 36 }}
Correct.
Rust
let x = 13; x += 1;
let mut x = 13; x += 1;
Need mut to modify.
Rust
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
const bar = 86; bar = 17;
let bar = 86; bar = 17;
Cannot reassign const.
JavaScript
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
class Person {{ int item; }};
class Person {{ public: int item; }};
Make public.
C++
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 61;
var x = 61;
Correct.
Dart
[93, 4, 38
[93, 4, 38]
Close bracket.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
print('message')
print('message')
Correct.
R
x := 21
x := 21
Correct.
Go
SELECT * FROM orders WHRE id=51;
SELECT * FROM orders WHERE id=51;
Fix WHERE.
SQL
$list[94] = 5;
if (isset($list[94])) $list[94] = 5;
Check existence.
PHP
let c: Int = 'info'
let c: String = 'info'
Fix type.
Swift
let v=vec![81,78,49]; let first=&v[0]; v.push(74);
let mut v=vec![81,78,49]; let first=v[0]; v.push(74);
Copy instead of reference.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
// comment
/* comment */
Use /* */.
CSS
print 'output'
print('output')
print needs parentheses.
Python
<input type='text' value='result'>
<input type='text' value='result' name='name'>
Add name attribute.
HTML
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
["output", 91]
["output", 91]
Correct.
JSON
while x > 89 x -= 1
while x > 89: x -= 1
Colon missing after while.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int index = 'result';
String index = 'result';
Type mismatch.
Dart
String a = 'world';
String a = "world";
Double quotes.
Java
name: data id: hello,
name: data id: hello
Remove comma.
YAML
assert item > 45
assert item > 45
Correct.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'info' + 58
'info' + 58.to_s
Convert int.
Ruby
handle
handle()
Add parentheses.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
$b = 38; if ($b = 38) {{}}
$b = 38; if ($b == 38) {{}}
Use ==.
PHP
name: value age: 34
name: value age: 34
Correct.
YAML
val count = 'value'
val count = "value"
Double quotes.
Kotlin
val c: Int = 'data'
val c: String = 'data'
Fix type.
Kotlin
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (c = 85) {{}}
if (c === 85) {{}}
Use === for equality.
JavaScript
<note><desc>value</desc><name>2</name></note
<note><desc>value</desc><name>2</name></note>
Add closing >.
XML
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let count: number = 'data';
let count: string = 'data';
Fix type.
TypeScript
'message' + 55
'message' + str(55)
Can't add int to string.
Python