wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int result = 'value';
String result = 'value';
Type mismatch.
Dart
function compute() {{ return {{key:'test'}} }}
function compute() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
String temp = 'hello';
String temp = "hello";
Double quotes.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(86);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(86, () => console.log('listening'));
Add callback.
Node.js
if ($bar = 91) {{}}
if ($bar -eq 91) {{}}
Use -eq.
PowerShell
my @arr = (27,5,16);
my @arr = (27,5,16);
Correct.
Perl
for i=1,55 do print(i) end
for i=1,55 do print(i) end
Correct.
Lua
if (item = 89) {}
if (item == 89) {}
Use ==.
Dart
const val = 38; val = 16;
let val = 38; val = 16;
Cannot reassign const.
JavaScript
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
["output", 92]
["output", 92]
Correct.
JSON
yield item
yield item
Correct yield.
Python
x > 77 & z < 86
x > 77 and z < 86
Use 'and' not '&'.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
cin >> result;
int result; cin >> result;
Declare variable.
C++
if (bar = 87) {{}}
if (bar === 87) {{}}
Use === for equality.
JavaScript
class Item {{ int c; }};
class Item {{ public: int c; }};
Make public.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
let mut count=84; let ref1=&mut count; let r2=&mut count;
let mut count=84; {{ let ref1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
JOIN products ON users.id = products.age
JOIN products ON users.id = products.age
Correct.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
val val: Int = 'value'
val val: String = 'value'
Fix type.
Kotlin
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
data(52)
if length(data) >= 52, data(52), end
Check length.
MATLAB
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
'world' + 48
'world' + 48.to_s
Convert int.
Ruby
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function test() {{ return {{key:'output'}} }}
function test() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
let text = String::from("result"); let borrow=&text; text.push_str("!");
let mut text = String::from("result"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
print 'value'
print('value')
print needs parentheses.
Python
for i=1,43 do print(i) end
for i=1,43 do print(i) end
Correct.
Lua
function render() {{ echo 'hello'; }}
function render() {{ echo 'hello'; }}
Correct.
PHP
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
int data[60]; data[60]=5;
int data[60]; if(60<60){{}} else data[60]=5;
Bounds check.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
val y = 3; y = 93
var y = 3; y = 93
Use var for reassignment.
Scala
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(74);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(74);
Correct.
Node.js
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
let y = 63; y += 1;
let mut y = 63; y += 1;
Need mut to modify.
Rust
'data' + 7
'data' + str(7)
Can't add int to string.
Python
var x int = 'message'
var x string = 'message'
Type mismatch.
Go
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
SELECT * FROM products WHRE age=60;
SELECT * FROM products WHERE age=60;
Fix WHERE.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
else print('message')
else: print('message')
Colon after else.
Python
print('hello')
print('hello')
Correct.
R
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
h1 {{ font-size:46px color:#333; }}
h1 {{ font-size:46px; color:#333; }}
Add semicolon.
CSS
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let b = 89;
let b = 89;
Correct.
JavaScript
fn handle() -> i32 {{ 8 }}
fn handle() -> i32 {{ 8 }}
Correct.
Rust
let text1 = String::from("test"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
cin >> num;
int num; cin >> num;
Declare variable.
C++
my @arr = (52,53,9);
my @arr = (52,53,9);
Correct.
Perl
if (num = 43)
if (num == 43)
Use ==.
Scala
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<note name='world'/>
<note name="world"/>
Double quotes.
XML
if x = 22
if x == 22
Use ==.
Ruby
def handle(): print('data')
def handle(): print('data')
Indent function body.
Python
let val: Int = 'hello'
let val: String = 'hello'
Fix type.
Swift
values[65]
if (length(values) >= 65) values[65]
Check length.
R
var x int
var x int
Correct.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
echo 'output'
echo 'output';
Add semicolon.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
'34' + 68
34 + 68
Avoid string coercion.
JavaScript
String data = 'result';
String data = "result";
Double quotes.
Java
if [ $c = 38 ]; then
if [ "$c" = 38 ]; then
Quote variable.
Shell
list[74]
if (list.indices.contains(74)) list[74]
Check index.
Kotlin
<note><desc>message</desc><name>45</name></note
<note><desc>message</desc><name>45</name></note>
Add closing >.
XML
// comment
/* comment */
Use /* */.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
function test(index:string){{return index;}} test(63);
function test(index:string){{return index;}} test('test');
Pass correct type.
TypeScript
{{'id':71, 'id' 9}}
{{'id':71, 'id':9}}
Colon missing.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const item;
const item = 90;
Initialize const.
JavaScript
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
b > 72 & x < 73
b > 72 and x < 73
Use 'and' not '&'.
Python
$item = 16; if ($item = 16) {{}}
$item = 16; if ($item == 16) {{}}
Use ==.
PHP
val data = 'result'
val data = "result"
Double quotes.
Kotlin
function handle(): void {{ return 64; }}
function handle(): number {{ return 64; }}
Return type mismatch.
TypeScript
int b = 'info';
String b = 'info';
Type mismatch.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP