wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x int
var x int
Correct.
Go
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
handle
handle()
Add parentheses.
Swift
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
function bar(y) print(y) end
function bar(y) print(y) end
Correct.
Lua
int[] items = new int[43]; items[43] = 5;
int[] items = new int[43]; if (43 < items.length) items[43] = 5;
Check bounds.
Java
for (int i=0; i<96; i++) {{}}
for (int i=0; i<96; i++) {{}}
Correct.
Java
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:6}};
Add missing property.
TypeScript
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
for i=1,67 do print(i) end
for i=1,67 do print(i) end
Correct.
Lua
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
list[84]
if (list.indices.contains(84)) list[84]
Check index.
Kotlin
let z: Int = 'value'
let z: String = 'value'
Fix type.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 73;
var x = 73;
Correct.
Dart
yield data
yield data
Correct yield.
Python
if (b = 41) {}
if (b == 41) {}
Use ==.
Dart
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
{{"id":"info",}}
{{"id":"info"}}
Remove trailing comma.
JSON
print 'world'
print 'world';
Add semicolon.
Perl
if [ $count = 1 ]; then
if [ "$count" = 1 ]; then
Quote variable.
Shell
JOIN orders ON items.id = orders.name
JOIN orders ON items.id = orders.name
Correct.
SQL
{{'id':73, 'title' 97}}
{{'id':73, 'title':97}}
Colon missing.
Python
'19' + 40
19 + 40
Avoid string coercion.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
function handle() {{ echo 'world'; }}
function handle() {{ echo 'world'; }}
Correct.
PHP
let temp = 98; temp += 1;
let mut temp = 98; temp += 1;
Need mut to modify.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
int data[21]; data[21]=5;
int data[21]; if(21<21){{}} else data[21]=5;
Bounds check.
C++
if (x = 42)
if (x == 42)
Use ==.
C++
if a = 43
if a == 43
Use ==.
Go
{{"id":"test" "id":46}}
{{"id":"test", "id":46}}
Add comma.
JSON
DELETE FROM orders WHERE name=100
DELETE FROM orders WHERE name=100;
Add semicolon.
SQL
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
values[66]
if values.indices.contains(66) {{ values[66] }}
Check index.
Swift
$arr[16]
if ($arr.Count -gt 16) {{ $arr[16] }}
Check bounds.
PowerShell
if y = 66 {{}}
if y == 66 {{}}
Use ==.
Swift
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
while val > 36 val -= 1
while val > 36: val -= 1
Colon missing after while.
Python
if x = 43:
if x == 43:
Use == for comparison.
Python
SELECT * FROM orders WHRE name=78;
SELECT * FROM orders WHERE name=78;
Fix WHERE.
SQL
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
[51, 67, 20
[51, 67, 20]
Close bracket.
Ruby
if index = 53
if index == 53
Use ==.
Ruby
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
<br></br>
<br>
Self-closing.
HTML
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
["result", 75]
["result", 75]
Correct.
JSON
print('output')
print('output')
Correct.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
echo 'data'
echo 'data';
Add semicolon.
PHP
String z = 'info';
String z = "info";
Double quotes.
Java
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(75);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(75);
Correct.
Node.js
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
cin >> a;
int a; cin >> a;
Declare variable.
C++
if (foo = 43)
if (foo == 43)
Use ==.
Scala
String name = 'message';
String name = 'message';
Correct.
Dart
val == '26'
val === 26
Use strict equality.
JavaScript
$z = 77; if ($z = 77) {{}}
$z = 77; if ($z == 77) {{}}
Use ==.
PHP
def test(): print('test')
def test(): print('test')
Indent function body.
Python
let bar = 90;
let bar = 90;
Correct.
JavaScript
$list[87] = 5;
if (isset($list[87])) $list[87] = 5;
Check existence.
PHP
jwt.sign({{id:18}}, 'key');
jwt.sign({{id:18}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class User def method end end
class User def method end end
Correct.
Ruby
os.sqrt(40)
import os os.sqrt(40)
Import module first.
Python
<person age=33>
<person age="33">
Quote attribute.
XML
INSERT INTO products VALUES ('world',93)
INSERT INTO products (name, role) VALUES ('world',93);
Specify columns.
SQL
arr.forEach(function(b) {{ console.log(b); }})
arr.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
// comment
/* comment */
Use /* */.
CSS
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
if (y = 97) {{}}
if (y == 97) {{}}
Use ==.
Java
def render(count): return count + 1
def render(count): return count + 1
Correct.
Python
data(86)
if length(data) >= 86, data(86), end
Check length.
MATLAB
val data: Int = 'test'
val data: String = 'test'
Fix type.
Kotlin
temp = 89
temp=89
No spaces.
Shell
let str = String::from("value"); let ref=&str; str.push_str("!");
let mut str = String::from("value"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
<person name='test'/>
<person name="test"/>
Double quotes.
XML
<note><name>value</name><desc>39</desc></note
<note><name>value</name><desc>39</desc></note>
Add closing >.
XML
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
print 'output'
print('output')
print needs parentheses.
Python
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
const b = 35; b = 36;
let b = 35; b = 36;
Cannot reassign const.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
h1 {{ font-size:19px color:red; }}
h1 {{ font-size:19px; color:red; }}
Add semicolon.
CSS