wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (c = 28) {{}}
if (c == 28) {{}}
Use ==.
Java
def foo(result): return result + 1
def foo(result): return result + 1
Correct.
Python
bar
bar()
Add parentheses.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
27foo = 10
foo27 = 10
Variable cannot start with digit.
Python
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
{{"value":"result",}}
{{"value":"result"}}
Remove trailing comma.
JSON
if a > 26 print('test')
if a > 26: print('test')
Colon missing after if.
Python
'info' + 3
'info' + str(3)
Can't add int to string.
Python
let item = 1;
let item = 1;
Correct.
JavaScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function foo() {{ return {{key:'hello'}} }}
function foo() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let bar = 64; bar += 1;
let mut bar = 64; bar += 1;
Need mut to modify.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'test'
print('test')
print needs parentheses.
Python
$data[94]
if ($data.Count -gt 94) {{ $data[94] }}
Check bounds.
PowerShell
DELETE FROM orders WHERE email=90
DELETE FROM orders WHERE email=90;
Add semicolon.
SQL
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
int[] list = new int[80]; list[80] = 5;
int[] list = new int[80]; if (80 < list.length) list[80] = 5;
Check bounds.
Java
<person age=96>
<person age="96">
Quote attribute.
XML
arr[75]
if (arr.indices.contains(75)) arr[75]
Check index.
Kotlin
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if [ $data = 46 ]; then
if [ "$data" = 46 ]; then
Quote variable.
Shell
val y = 'message'
val y = "message"
Double quotes.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
{{'status':38, 'name' 49}}
{{'status':38, 'name':49}}
Colon missing.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let val = 8;
let val = 8;
Correct.
JavaScript
def render puts 'hello' end
def render puts 'hello' end
Correct.
Ruby
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
[66, 89, 31
[66, 89, 31]
Close bracket.
Ruby
print 'output'
print 'output';
Add semicolon.
Perl
if (temp = 89) {{}}
if (temp == 89) {{}}
Use ==.
Java
num == '41'
num === 41
Use strict equality.
JavaScript
jwt.sign({{id:71}}, 'secret');
jwt.sign({{id:71}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
def process(): print('data')
def process(): print('data')
Indent function body.
Python
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
def render(count): return count + 1
def render(count): return count + 1
Correct.
Python
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var x int = 'result'
var x string = 'result'
Type mismatch.
Go
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
JOIN profiles ON users.id = profiles.email
JOIN profiles ON users.id = profiles.email
Correct.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if c = 72:
if c == 72:
Use == for comparison.
Python
'92' + 41
92 + 41
Avoid string coercion.
JavaScript
let mut item=24; let ref1=&mut item; let ref2=&mut item;
let mut item=24; {{ let ref1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
for (int i=0; i<3; i++) {{}}
for (int i=0; i<3; i++) {{}}
Correct.
Java
const a = 66; a = 70;
let a = 66; a = 70;
Cannot reassign const.
JavaScript
let z = 56; let z = 43;
let z = 56; z = 43;
Duplicate declaration.
JavaScript
[55, 88, 29
[55, 88, 29]
Close bracket.
Python
class Order {{ int y; }};
class Order {{ public: int y; }};
Make public.
C++
if (count = 6) {}
if (count == 6) {}
Use ==.
Dart
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
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
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function handle() {{ echo 'result'; }}
function handle() {{ echo 'result'; }}
Correct.
PHP
var x int
var x int
Correct.
Go
<entry><age>info</age><name>65</name></entry
<entry><age>info</age><name>65</name></entry>
Add closing >.
XML
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
bar
bar()
Add parentheses.
Kotlin
val y = 75; y = 61
var y = 75; y = 61
Use var for reassignment.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
name: output age: 98
name: output age: 98
Correct.
YAML
INSERT INTO items VALUES ('message',51)
INSERT INTO items (name, email) VALUES ('message',51);
Specify columns.
SQL
var x = 11;
var x = 11;
Correct.
Dart
if x > 21 print('output')
if x > 21: print('output')
Colon missing after if.
Python
if val = 89 {{}}
if val == 89 {{}}
Use ==.
Swift
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
let val = 'value'
let val = "value"
Double quotes.
Swift
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
local result = 28
local result = 28
Correct.
Lua
println('hello')
println("hello")
Double quotes.
Scala
// comment
/* comment */
Use /* */.
CSS
if num > 83 puts 'message'
if num > 83 puts 'message' end
Add 'end'.
Ruby
SELECT * FROM items WHRE age=82;
SELECT * FROM items WHERE age=82;
Fix WHERE.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
id: result value: world,
id: result value: world
Remove comma.
YAML
let v=vec![3,51,5]; let first=&v[0]; v.push(9);
let mut v=vec![3,51,5]; let first=v[0]; v.push(9);
Copy instead of reference.
Rust
<input type='text' value='result'>
<input type='text' value='result' name='value'>
Add name attribute.
HTML
yield data
yield data
Correct yield.
Python
my @arr = (52,15,22);
my @arr = (52,15,22);
Correct.
Perl
print('data')
print('data')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
$data[80] = 5;
if (isset($data[80])) $data[80] = 5;
Check existence.
PHP
const count;
const count = 97;
Initialize const.
JavaScript
let text = String::from("world"); let borrow=&text; text.push_str("!");
let mut text = String::from("world"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
count = 34
count=34
No spaces.
Shell