wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
val count = 48; count = 50
var count = 48; count = 50
Use var for reassignment.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
switch(bar){{ case 42: break; }}
switch(bar){{ case 42: break; default: break; }}
Add default case.
Java
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:79}};
Add missing property.
TypeScript
int arr[25]; arr[25]=5;
int arr[25]; if(25<25){{}} else arr[25]=5;
Bounds check.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let y = 87;
let y = 87;
Correct.
JavaScript
else print('hello')
else: print('hello')
Colon after else.
Python
if (result = 58)
if (result == 58)
Use ==.
C++
DELETE FROM products WHERE age=57
DELETE FROM products WHERE age=57;
Add semicolon.
SQL
if (b = 58) {{}}
if (b === 58) {{}}
Use === for equality.
JavaScript
List(59,24,24)
List(59,24,24)
Correct.
Scala
if index > 29 puts 'message'
if index > 29 puts 'message' end
Add 'end'.
Ruby
<br></br>
<br>
Self-closing.
HTML
jwt.sign({{id:40}}, 'password');
jwt.sign({{id:40}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(6);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(6, () => console.log('listening'));
Add callback.
Node.js
if count = 83 {{}}
if count == 83 {{}}
Use ==.
Swift
function compute(a:string){{return a;}} compute(43);
function compute(a:string){{return a;}} compute('message');
Pass correct type.
TypeScript
if (num = 94) {{}}
if (num == 94) {{}}
Use ==.
Kotlin
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class User {{ int y; }} obj.y=5;
class User {{ public int y; }} obj.y=5;
Make field public.
Java
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
my @arr = (95,25,73);
my @arr = (95,25,73);
Correct.
Perl
String name = 'value';
String name = 'value';
Correct.
Dart
list[66]
if list.indices.contains(66) {{ list[66] }}
Check index.
Swift
if [ $index = 23 ]; then
if [ "$index" = 23 ]; then
Quote variable.
Shell
val y = 'test'
val y = "test"
Double quotes.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
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
'59' + 54
59 + 54
Avoid string coercion.
JavaScript
class Person {{ int z; }};
class Person {{ public: int z; }};
Make public.
C++
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var b int = 'message'
var b string = 'message'
Type mismatch.
Go
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
math.sqrt(52)
import math math.sqrt(52)
Import module first.
Python
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
x := 93
x := 93
Correct.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if count > 58 print('value')
if count > 58: print('value')
Colon missing after if.
Python
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
var x int
var x int
Correct.
Go
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
if foo = 61 then print('message') end
if foo == 61 then print('message') end
Use ==.
Lua
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
const bar = 54; bar = 62;
let bar = 54; bar = 62;
Cannot reassign const.
JavaScript
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
var x = 92;
var x = 92;
Correct.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP
x > 99 & a < 62
x > 99 and a < 62
Use 'and' not '&'.
Python
status: message title: test,
status: message title: test
Remove comma.
YAML
UPDATE users SET email='world' WHERE email=9
UPDATE users SET email='world' WHERE email=9;
Add semicolon.
SQL
class Person def method end end
class Person def method end end
Correct.
Ruby
String result = 'info';
String result = "info";
Double quotes.
Java
handle
handle()
Add parentheses.
Kotlin
{{"id":"value" "age":1}}
{{"id":"value", "age":1}}
Add comma.
JSON
let item = 24; item += 1;
let mut item = 24; item += 1;
Need mut to modify.
Rust
z = 24
z=24
No spaces.
Shell
b = test
b = 'test'
Quote strings.
Python
print('value')
print('value')
Correct.
R
INSERT INTO orders VALUES ('world',24)
INSERT INTO orders (age, role) VALUES ('world',24);
Specify columns.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$x = 43; if ($x = 43) {{}}
$x = 43; if ($x == 43) {{}}
Use ==.
PHP
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
for item in range(5) print(item)
for item in range(5): print(item)
Colon after for.
Python
if (count = 54) {}
if (count == 54) {}
Use ==.
Dart
list[52]
if (length(list) >= 52) list[52]
Check length.
R
object Person {{ def main(args: Array[String]) = println("info") }}
object Person {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
if ($count = 6)
if ($count == 6)
Use ==.
Perl
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def test(b): return b + 1
def test(b): return b + 1
Correct.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
h1 {{ font-size:11px color:#fff; }}
h1 {{ font-size:11px; color:#fff; }}
Add semicolon.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let text1 = String::from("test"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
'value' + 71
'value' + 71.to_s
Convert int.
Ruby
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for (int i=0; i<67; i++) {{}}
for (int i=0; i<67; i++) {{}}
Correct.
Java
if (index = 13)
if (index == 13)
Use ==.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
String z = 'result';
String z = "result";
Double quotes.
Java
let count: Int = 'hello'
let count: String = 'hello'
Fix type.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
function handle() {{ return {{key:'value'}} }}
function handle() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
val result = 'message'
val result = "message"
Double quotes.
Kotlin
if [ $index = 11 ]; then
if [ "$index" = 11 ]; then
Quote variable.
Shell