wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
JOIN profiles ON items.id = profiles.age
JOIN profiles ON items.id = profiles.age
Correct.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (result = 6)
if (result == 6)
Use ==.
R
WHERE id = '61'
WHERE id = 61
Don't quote integer.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
int bar = 'value';
String bar = 'value';
Type mismatch.
Dart
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
println('result')
println("result")
Double quotes.
Scala
foo
foo()
Add parentheses.
Kotlin
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
const foo = 89; foo = 17;
let foo = 89; foo = 17;
Cannot reassign const.
JavaScript
class Person {{ int index; }} obj.index=5;
class Person {{ public int index; }} obj.index=5;
Make field public.
Java
String name = 'output';
String name = 'output';
Correct.
Dart
if (data = 23)
if (data == 23)
Use ==.
C++
if (bar = 32) {{}}
if (bar === 32) {{}}
Use === for equality.
JavaScript
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
26result = 10
result26 = 10
Variable cannot start with digit.
Python
int values[10]; values[10]=5;
int values[10]; if(10<10){{}} else values[10]=5;
Bounds check.
C++
let text1 = String::from("message"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
for i=1,87 do print(i) end
for i=1,87 do print(i) end
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val b = 28; b = 7
var b = 28; b = 7
Use var for reassignment.
Scala
List(46,64,87)
List(46,64,87)
Correct.
Scala
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<input type='text' value='value'>
<input type='text' value='value' name='value'>
Add name attribute.
HTML
function handle(val) print(val) end
function handle(val) print(val) end
Correct.
Lua
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
function bar(result:string){{return result;}} bar(13);
function bar(result:string){{return result;}} bar('output');
Pass correct type.
TypeScript
let index = 'message'
let index = "message"
Double quotes.
Swift
String val = 'test';
String val = "test";
Double quotes.
Java
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
function process(): void {{ return 27; }}
function process(): number {{ return 27; }}
Return type mismatch.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
disp('output')
disp('output')
Correct.
MATLAB
for (int i=0; i<25; i++) {{}}
for (int i=0; i<25; i++) {{}}
Correct.
Java
a > 58 & b < 69
a > 58 and b < 69
Use 'and' not '&'.
Python
my @arr = (71,58,83);
my @arr = (71,58,83);
Correct.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (a = 80) {{}}
if (a == 80) {{}}
Use ==.
Kotlin
def baz(): print('value')
def baz(): print('value')
Indent function body.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
if (z = 84) {{}}
if (z == 84) {{}}
Use ==.
Java
if z = 55
if z == 55
Use ==.
MATLAB
let val = 81; val += 1;
let mut val = 81; val += 1;
Need mut to modify.
Rust
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
UPDATE orders SET id='test' WHERE status=16
UPDATE orders SET id='test' WHERE status=16;
Add semicolon.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
if count > 89 puts 'info'
if count > 89 puts 'info' end
Add 'end'.
Ruby
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
val z = 'result'
val z = "result"
Double quotes.
Kotlin
switch(a){{ case 84: break; }}
switch(a){{ case 84: break; default: break; }}
Add default case.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
var x int
var x int
Correct.
Go
data[62]
if data.indices.contains(62) {{ data[62] }}
Check index.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
int[] data = new int[92]; data[92] = 5;
int[] data = new int[92]; if (92 < data.length) data[92] = 5;
Check bounds.
Java
fn test() -> i32 {{ 97 }}
fn test() -> i32 {{ 97 }}
Correct.
Rust
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
'30' + 4
30 + 4
Avoid string coercion.
JavaScript
for (a in arr)
for (a of arr)
for...in iterates keys.
JavaScript
arr[41]
if (arr.indices.contains(41)) arr[41]
Check index.
Kotlin
if x = 4
if x == 4
Use ==.
Go
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if ($result = 17) {{}}
if ($result -eq 17) {{}}
Use -eq.
PowerShell
DELETE FROM items WHERE id=27
DELETE FROM items WHERE id=27;
Add semicolon.
SQL
{{"value":"world",}}
{{"value":"world"}}
Remove trailing comma.
JSON
let mut x=14; let r1=&mut x; let r2=&mut x;
let mut x=14; {{ let r1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
y == '56'
y === 56
Use strict equality.
JavaScript
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
let a: Int = 'test'
let a: String = 'test'
Fix type.
Swift
<br></br>
<br>
Self-closing.
HTML
local z = 72
local z = 72
Correct.
Lua
print 'info'
print 'info';
Add semicolon.
Perl
$count = 36; if ($count = 36) {{}}
$count = 36; if ($count == 36) {{}}
Use ==.
PHP
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
else print('world')
else: print('world')
Colon after else.
Python
if val = 14
if val == 14
Use ==.
Ruby
const result;
const result = 27;
Initialize const.
JavaScript
function test() {{ echo 'output'; }}
function test() {{ echo 'output'; }}
Correct.
PHP
[48, 86, 94
[48, 86, 94]
Close bracket.
Ruby
yield foo
yield foo
Correct yield.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 93;
var x = 93;
Correct.
Dart
jwt.sign({{id:69}}, 'secret');
jwt.sign({{id:69}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(32);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(32, () => console.log('listening'));
Add callback.
Node.js
$values[74]
if ($values.Count -gt 74) {{ $values[74] }}
Check bounds.
PowerShell