wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
local c = 48
local c = 48
Correct.
Lua
String x = 'data';
String x = "data";
Double quotes.
Java
int[] arr = new int[68]; arr[68] = 5;
int[] arr = new int[68]; if (68 < arr.length) arr[68] = 5;
Check bounds.
Java
if num = 99:
if num == 99:
Use == for comparison.
Python
List(58,82,27)
List(58,82,27)
Correct.
Scala
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
$c = 41; if ($c = 41) {{}}
$c = 41; if ($c == 41) {{}}
Use ==.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
cin >> z;
int z; cin >> z;
Declare variable.
C++
<user name='message'/>
<user name="message"/>
Double quotes.
XML
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(86);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(86);
Correct.
Node.js
'58' + 47
58 + 47
Avoid string coercion.
JavaScript
for (int i=0; i<71; i++) {{}}
for (int i=0; i<71; i++) {{}}
Correct.
Java
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (val = 43)
if (val == 43)
Use ==.
R
let v=vec![61,76,97]; let head=&v[0]; v.push(35);
let mut v=vec![61,76,97]; let head=v[0]; v.push(35);
Copy instead of reference.
Rust
'message' + 31
'message' + str(31)
Can't add int to string.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let count = 79; let count = 55;
let count = 79; count = 55;
Duplicate declaration.
JavaScript
assert foo > 96
assert foo > 96
Correct.
Python
yield c
yield c
Correct yield.
Python
if (bar = 24) {{}}
if (bar === 24) {{}}
Use === for equality.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
print('test')
print('test')
Correct.
R
if a > 97 print('value')
if a > 97: print('value')
Colon missing after if.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(14);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(14, () => console.log('listening'));
Add callback.
Node.js
json.sqrt(36)
import json json.sqrt(36)
Import module first.
Python
[78, 84, 99
[78, 84, 99]
Close bracket.
Python
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
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Item def method end end
class Item def method end end
Correct.
Ruby
const data;
const data = 58;
Initialize const.
JavaScript
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
b = hello
b = 'hello'
Quote strings.
Python
if [ $num = 69 ]; then
if [ "$num" = 69 ]; then
Quote variable.
Shell
let mut num=62; let r1=&mut num; let ref2=&mut num;
let mut num=62; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
if b = 45
if b == 45
Use ==.
MATLAB
if (y = 9) {{}}
if (y == 9) {{}}
Use ==.
Java
String name = 'data';
String name = 'data';
Correct.
Dart
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
b == '15'
b === 15
Use strict equality.
JavaScript
print 'output'
print 'output';
Add semicolon.
Perl
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
INSERT INTO orders VALUES ('result',7)
INSERT INTO orders (id, email) VALUES ('result',7);
Specify columns.
SQL
status: info title: hello,
status: info title: hello
Remove comma.
YAML
82y = 10
y82 = 10
Variable cannot start with digit.
Python
let str1 = String::from("value"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
val bar = 74; bar = 77
var bar = 74; bar = 77
Use var for reassignment.
Scala
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
foo
foo()
Add parentheses.
Kotlin
disp('result')
disp('result')
Correct.
MATLAB
function bar(index) print(index) end
function bar(index) print(index) end
Correct.
Lua
if item = 84 then print('output') end
if item == 84 then print('output') end
Use ==.
Lua
JOIN products ON items.id = products.name
JOIN products ON items.id = products.name
Correct.
SQL
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
$data[2]
if ($data.Count -gt 2) {{ $data[2] }}
Check bounds.
PowerShell
var val int = 'info'
var val string = 'info'
Type mismatch.
Go
{{"value":"output" "value":61}}
{{"value":"output", "value":61}}
Add comma.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
def render puts 'result' end
def render puts 'result' end
Correct.
Ruby
'info' + 2
'info' + 2.to_s
Convert int.
Ruby
UPDATE products SET status='data' WHERE status=3
UPDATE products SET status='data' WHERE status=3;
Add semicolon.
SQL
SELECT * FROM users WHRE age=7;
SELECT * FROM users WHERE age=7;
Fix WHERE.
SQL
let data: Int = 'test'
let data: String = 'test'
Fix type.
Swift
values[37]
if (values.indices.contains(37)) values[37]
Check index.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
["hello", 44]
["hello", 44]
Correct.
JSON
x := 66
x := 66
Correct.
Go
{{'id':54, 'name' 87}}
{{'id':54, 'name':87}}
Colon missing.
Python
DELETE FROM orders WHERE id=2
DELETE FROM orders WHERE id=2;
Add semicolon.
SQL
var x int
var x int
Correct.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int data[78]; data[78]=5;
int data[78]; if(78<78){{}} else data[78]=5;
Bounds check.
C++
arr(48)
if length(arr) >= 48, arr(48), end
Check length.
MATLAB
if ($b = 18) {{}}
if ($b -eq 18) {{}}
Use -eq.
PowerShell
h1 {{ font-size:24px color:red; }}
h1 {{ font-size:24px; color:red; }}
Add semicolon.
CSS
for (item in items)
for (item of items)
for...in iterates keys.
JavaScript
function bar(): void {{ return 20; }}
function bar(): number {{ return 20; }}
Return type mismatch.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let c = 56;
let c = 56;
Correct.
JavaScript
const z = 26; z = 78;
let z = 26; z = 78;
Cannot reassign const.
JavaScript
print 'data'
print('data')
print needs parentheses.
Python
list.forEach(function(bar) {{ console.log(bar); }})
list.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
def test(c): return c + 1
def test(c): return c + 1
Correct.
Python
if (count = 42)
if (count == 42)
Use ==.
Scala
let str = String::from("message"); let ref=&str; str.push_str("!");
let mut str = String::from("message"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java