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
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
fn compute() -> i32 {{ 47 }}
fn compute() -> i32 {{ 47 }}
Correct.
Rust
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
yield count
yield count
Correct yield.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
print 'test'
print('test')
print needs parentheses.
Python
let v=vec![16,44,70]; let primary=&v[0]; v.push(68);
let mut v=vec![16,44,70]; let primary=v[0]; v.push(68);
Copy instead of reference.
Rust
if (val = 27) {{}}
if (val == 27) {{}}
Use ==.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int b = 'info';
String b = 'info';
Type mismatch.
Dart
DELETE FROM products WHERE age=90
DELETE FROM products WHERE age=90;
Add semicolon.
SQL
if (num = 91)
if (num == 91)
Use ==.
R
disp('info')
disp('info')
Correct.
MATLAB
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
<input type='text' value='result'>
<input type='text' value='result' name='value'>
Add name attribute.
HTML
let y: Int = 'hello'
let y: String = 'hello'
Fix type.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
arr(46)
if length(arr) >= 46, arr(46), end
Check length.
MATLAB
if (index = 7) {{}}
if (index === 7) {{}}
Use === for equality.
JavaScript
// comment
/* comment */
Use /* */.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
if (temp = 54)
if (temp == 54)
Use ==.
Scala
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:39}};
Add missing property.
TypeScript
{{'status':'test'}}
{{"status":"test"}}
Use double quotes.
JSON
val a = 'test'
val a = "test"
Double quotes.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
cin >> y;
int y; cin >> y;
Declare variable.
C++
def test puts 'data' end
def test puts 'data' end
Correct.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
for (int i=0; i<93; i++) {{}}
for (int i=0; i<93; i++) {{}}
Correct.
Java
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
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
result == '86'
result === 86
Use strict equality.
JavaScript
var z int = 'hello'
var z string = 'hello'
Type mismatch.
Go
name: test age: 37
name: test age: 37
Correct.
YAML
<br></br>
<br>
Self-closing.
HTML
$items[17] = 5;
if (isset($items[17])) $items[17] = 5;
Check existence.
PHP
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function baz(result:string){{return result;}} baz(50);
function baz(result:string){{return result;}} baz('result');
Pass correct type.
TypeScript
if temp = 41
if temp == 41
Use ==.
MATLAB
title: value id: test,
title: value id: test
Remove comma.
YAML
else print('data')
else: print('data')
Colon after else.
Python
let index: number | null = null; index.toFixed(18);
let index: number | null = null; if(index!==null) index.toFixed(18);
Null check.
TypeScript
WHERE id = '47'
WHERE id = 47
Don't quote integer.
SQL
var x = 59;
var x = 59;
Correct.
Dart
["message", 3]
["message", 3]
Correct.
JSON
let index = 60; let index = 81;
let index = 60; index = 81;
Duplicate declaration.
JavaScript
int[] data = new int[85]; data[85] = 5;
int[] data = new int[85]; if (85 < data.length) data[85] = 5;
Check bounds.
Java
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
List(86,58,42)
List(86,58,42)
Correct.
Scala
String name = 'output';
String name = 'output';
Correct.
Dart
items[88]
if (length(items) >= 88) items[88]
Check length.
R
while x > 58 x -= 1
while x > 58: x -= 1
Colon missing after while.
Python
UPDATE orders SET age='data' WHERE role=37
UPDATE orders SET age='data' WHERE role=37;
Add semicolon.
SQL
if index = 22
if index == 22
Use ==.
Ruby
if count = 32 then print('result') end
if count == 32 then print('result') end
Use ==.
Lua
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
44num = 10
num44 = 10
Variable cannot start with digit.
Python
val foo = 81; foo = 27
var foo = 81; foo = 27
Use var for reassignment.
Scala
class Order {{ int index; }} obj.index=5;
class Order {{ public int index; }} obj.index=5;
Make field public.
Java
if c > 26 print('value')
if c > 26: print('value')
Colon missing after if.
Python
if [ $y = 15 ]; then
if [ "$y" = 15 ]; then
Quote variable.
Shell
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
JOIN profiles ON items.id = profiles.status
JOIN profiles ON items.id = profiles.status
Correct.
SQL
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
echo 'result'
echo 'result';
Add semicolon.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if ($c = 92) {{}}
if ($c -eq 92) {{}}
Use -eq.
PowerShell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
function render(): void {{ return 86; }}
function render(): number {{ return 86; }}
Return type mismatch.
TypeScript
const foo;
const foo = 49;
Initialize const.
JavaScript
items.forEach(function(data) {{ console.log(data); }})
items.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
let mut item=42; let ref1=&mut item; let ref2=&mut item;
let mut item=42; {{ let ref1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function bar(count) print(count) end
function bar(count) print(count) end
Correct.
Lua
local temp = 11
local temp = 11
Correct.
Lua
let c = 24; c += 1;
let mut c = 24; c += 1;
Need mut to modify.
Rust
[52, 51, 35
[52, 51, 35]
Close bracket.
Ruby
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
print 'info'
print 'info';
Add semicolon.
Perl
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for (data in values)
for (data of values)
for...in iterates keys.
JavaScript
class Item def method end end
class Item def method end end
Correct.
Ruby