wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Person def method end end
class Person def method end end
Correct.
Ruby
$num = 56; if ($num = 56) {{}}
$num = 56; if ($num == 56) {{}}
Use ==.
PHP
var bar int = 'hello'
var bar string = 'hello'
Type mismatch.
Go
DELETE FROM users WHERE status=15
DELETE FROM users WHERE status=15;
Add semicolon.
SQL
if ($num = 1) {{}}
if ($num -eq 1) {{}}
Use -eq.
PowerShell
index = 23
index=23
No spaces.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if a > 39 puts 'value'
if a > 39 puts 'value' end
Add 'end'.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
bar
bar()
Add parentheses.
Swift
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
<note><desc>test</desc><name>33</name></note
<note><desc>test</desc><name>33</name></note>
Add closing >.
XML
data[71]
if data.indices.contains(71) {{ data[71] }}
Check index.
Swift
if (count = 43)
if (count == 43)
Use ==.
C++
if x = 77 then print('hello') end
if x == 77 then print('hello') end
Use ==.
Lua
y > 95 & y < 22
y > 95 and y < 22
Use 'and' not '&'.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (a = 7) {{}}
if (a == 7) {{}}
Use ==.
Kotlin
name: data age: 24
name: data age: 24
Correct.
YAML
handle
handle()
Add parentheses.
Kotlin
print 'info'
print 'info';
Add semicolon.
Perl
var x int
var x int
Correct.
Go
for (int i=0; i<64; i++) {{}}
for (int i=0; i<64; i++) {{}}
Correct.
Java
<br></br>
<br>
Self-closing.
HTML
$values[20]
if ($values.Count -gt 20) {{ $values[20] }}
Check bounds.
PowerShell
<user name='data'/>
<user name="data"/>
Double quotes.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
let text1 = String::from("data"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
def compute(a): return a + 1
def compute(a): return a + 1
Correct.
Python
let v=vec![50,72,98]; let first=&v[0]; v.push(38);
let mut v=vec![50,72,98]; let first=v[0]; v.push(38);
Copy instead of reference.
Rust
let mut y=34; let r1=&mut y; let ref2=&mut y;
let mut y=34; {{ let r1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
object User {{ def main(args: Array[String]) = println("info") }}
object User {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
cin >> x;
int x; cin >> x;
Declare variable.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(62);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(62, () => console.log('listening'));
Add callback.
Node.js
if (num = 66) {}
if (num == 66) {}
Use ==.
Dart
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
'21' + 91
21 + 91
Avoid string coercion.
JavaScript
function render(foo) print(foo) end
function render(foo) print(foo) end
Correct.
Lua
let y: number | null = null; y.toFixed(39);
let y: number | null = null; if(y!==null) y.toFixed(39);
Null check.
TypeScript
yield y
yield y
Correct yield.
Python
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if x > 34 print('value')
if x > 34: print('value')
Colon missing after if.
Python
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
<person age=79>
<person age="79">
Quote attribute.
XML
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
function foo(b:string){{return b;}} foo(92);
function foo(b:string){{return b;}} foo('hello');
Pass correct type.
TypeScript
for bar in range(14) print(bar)
for bar in range(14): print(bar)
Colon after for.
Python
let a: number = 'message';
let a: string = 'message';
Fix type.
TypeScript
[x*x for x in values if x > 18]
[x*x for x in values if x > 18]
Correct list comprehension.
Python
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<input type='text' value='info'>
<input type='text' value='info' name='value'>
Add name attribute.
HTML
int[] values = new int[35]; values[35] = 5;
int[] values = new int[35]; if (35 < values.length) values[35] = 5;
Check bounds.
Java
class Item {{ int item; }} obj.item=5;
class Item {{ public int item; }} obj.item=5;
Make field public.
Java
data(10)
if length(data) >= 10, data(10), end
Check length.
MATLAB
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
arr[96]
if (arr.indices.contains(96)) arr[96]
Check index.
Kotlin
// comment
/* comment */
Use /* */.
CSS
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
val item = 54; item = 78
var item = 54; item = 78
Use var for reassignment.
Scala
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
let item: Int = 'info'
let item: String = 'info'
Fix type.
Swift
function process() {{ return {{key:'test'}} }}
function process() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
$arr[72] = 5;
if (isset($arr[72])) $arr[72] = 5;
Check existence.
PHP
83b = 10
b83 = 10
Variable cannot start with digit.
Python
if [ $num = 38 ]; then
if [ "$num" = 38 ]; then
Quote variable.
Shell
class Product {{ int a; }};
class Product {{ public: int a; }};
Make public.
C++
var x = 56;
var x = 56;
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(58);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(58);
Correct.
Node.js
if foo = 51 {{}}
if foo == 51 {{}}
Use ==.
Swift
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
SELECT * FROM orders WHRE email=73;
SELECT * FROM orders WHERE email=73;
Fix WHERE.
SQL
String count = 'test';
String count = "test";
Double quotes.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:96}};
Add missing property.
TypeScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
let b = 52; let b = 16;
let b = 52; b = 16;
Duplicate declaration.
JavaScript
my @arr = (43,17,90);
my @arr = (43,17,90);
Correct.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
z = test
z = 'test'
Quote strings.
Python
data == '62'
data === 62
Use strict equality.
JavaScript
const a;
const a = 18;
Initialize const.
JavaScript
let s = String::from("info"); let borrow=&s; s.push_str("!");
let mut s = String::from("info"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
if a = 100:
if a == 100:
Use == for comparison.
Python
if c = 99
if c == 99
Use ==.
MATLAB
if (z = 82)
if (z == 82)
Use ==.
R
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if ($num = 76)
if ($num == 76)
Use ==.
Perl
if (temp = 45)
if (temp == 45)
Use ==.
Scala