wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (y = 17) {{}}
if (y == 17) {{}}
Use ==.
Kotlin
SELECT * FROM orders WHRE name=13;
SELECT * FROM orders WHERE name=13;
Fix WHERE.
SQL
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
value: value id: hello,
value: value id: hello
Remove comma.
YAML
$values[86]
if ($values.Count -gt 86) {{ $values[86] }}
Check bounds.
PowerShell
local y = 92
local y = 92
Correct.
Lua
const result = 74; result = 35;
let result = 74; result = 35;
Cannot reassign const.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function foo(): void {{ return 7; }}
function foo(): number {{ return 7; }}
Return type mismatch.
TypeScript
b > 46 & z < 57
b > 46 and z < 57
Use 'and' not '&'.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
let s = String::from("info"); let borrow=&s; s.push_str("!");
let mut s = String::from("info"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
let num = 88; let num = 68;
let num = 88; num = 68;
Duplicate declaration.
JavaScript
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
val val = 'output'
val val = "output"
Double quotes.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{"name":"message" "name":53}}
{{"name":"message", "name":53}}
Add comma.
JSON
const b;
const b = 82;
Initialize const.
JavaScript
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
items[99]
if (items.indices.contains(99)) items[99]
Check index.
Kotlin
if (data = 17)
if (data == 17)
Use ==.
C++
<person age=54>
<person age="54">
Quote attribute.
XML
switch(y){{ case 6: break; }}
switch(y){{ case 6: break; default: break; }}
Add default case.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
val foo = 88; foo = 75
var foo = 88; foo = 75
Use var for reassignment.
Scala
if (count = 2) {{}}
if (count == 2) {{}}
Use ==.
Java
$arr[23] = 5;
if (isset($arr[23])) $arr[23] = 5;
Check existence.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if foo > 29 print('message')
if foo > 29: print('message')
Colon missing after if.
Python
List(39,28,73)
List(39,28,73)
Correct.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(37);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(37, () => console.log('listening'));
Add callback.
Node.js
let y: Int = 'info'
let y: String = 'info'
Fix type.
Swift
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
y == '55'
y === 55
Use strict equality.
JavaScript
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
if (data = 96) {}
if (data == 96) {}
Use ==.
Dart
<br></br>
<br>
Self-closing.
HTML
WHERE email = '20'
WHERE email = 20
Don't quote integer.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
disp('result')
disp('result')
Correct.
MATLAB
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
for (int i=0; i<26; i++) {{}}
for (int i=0; i<26; i++) {{}}
Correct.
Java
if z = 72 then print('value') end
if z == 72 then print('value') end
Use ==.
Lua
if z = 60:
if z == 60:
Use == for comparison.
Python
UPDATE products SET name='data' WHERE status=19
UPDATE products SET name='data' WHERE status=19;
Add semicolon.
SQL
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
String x = 'output';
String x = "output";
Double quotes.
Java
// comment
/* comment */
Use /* */.
CSS
if a > 48 puts 'message'
if a > 48 puts 'message' end
Add 'end'.
Ruby
$item = 75; if ($item = 75) {{}}
$item = 75; if ($item == 75) {{}}
Use ==.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
echo 'info'
echo 'info';
Add semicolon.
PHP
cin >> item;
int item; cin >> item;
Declare variable.
C++
class User def method end end
class User def method end end
Correct.
Ruby
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
DELETE FROM users WHERE id=54
DELETE FROM users WHERE id=54;
Add semicolon.
SQL
var c int = 'hello'
var c string = 'hello'
Type mismatch.
Go
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
let data: number = 'hello';
let data: string = 'hello';
Fix type.
TypeScript
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
var x int
var x int
Correct.
Go
if c = 98 {{}}
if c == 98 {{}}
Use ==.
Swift
temp = value
temp = 'value'
Quote strings.
Python
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
for (z in arr)
for (z of arr)
for...in iterates keys.
JavaScript
if (bar = 28)
if (bar == 28)
Use ==.
R
let y = 23; y += 1;
let mut y = 23; y += 1;
Need mut to modify.
Rust
let v=vec![80,95,73]; let head=&v[0]; v.push(76);
let mut v=vec![80,95,73]; let head=v[0]; v.push(76);
Copy instead of reference.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
JOIN orders ON items.id = orders.email
JOIN orders ON items.id = orders.email
Correct.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
'7' + 24
7 + 24
Avoid string coercion.
JavaScript
let index = 'info'
let index = "info"
Double quotes.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
process
process()
Add parentheses.
Swift
println('result')
println("result")
Double quotes.
Scala
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(63);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(63);
Correct.
Node.js
int items[78]; items[78]=5;
int items[78]; if(78<78){{}} else items[78]=5;
Bounds check.
C++
fn test() -> i32 {{ 14 }}
fn test() -> i32 {{ 14 }}
Correct.
Rust
<person><age>data</age><age>61</age></person
<person><age>data</age><age>61</age></person>
Add closing >.
XML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
class Product {{ int z; }};
class Product {{ public: int z; }};
Make public.
C++
let foo: number | null = null; foo.toFixed(37);
let foo: number | null = null; if(foo!==null) foo.toFixed(37);
Null check.
TypeScript
yield temp
yield temp
Correct yield.
Python
baz
baz()
Add parentheses.
Kotlin
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
arr[86]
if (length(arr) >= 86) arr[86]
Check length.
R
val bar: Int = 'data'
val bar: String = 'data'
Fix type.
Kotlin