wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
var z int = 'data' | var z string = 'data' | Type mismatch. | Go |
WHERE email = '33' | WHERE email = 33 | Don't quote integer. | SQL |
<entry name='value'/> | <entry name="value"/> | Double quotes. | XML |
[48, 76, 100 | [48, 76, 100] | Close bracket. | Ruby |
if result = 49 | if result == 49 | Use ==. | Ruby |
<br></br> | <br> | Self-closing. | HTML |
class = 'test' | class_name = 'test' | 'class' is a keyword. | Python |
System.out.println('test') | System.out.println('test'); | Add semicolon. | Java |
let num = 92; | let num = 92; | Correct. | JavaScript |
my @arr = (61,25,70); | my @arr = (61,25,70); | Correct. | Perl |
if result > 8
print('data') | if result > 8:
print('data') | Colon missing after if. | Python |
if bar = 31 {{}} | if bar == 31 {{}} | Use ==. | Swift |
console.log('message' | console.log('message') | Close parenthesis. | JavaScript |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
list[45] | if (list.indices.contains(45)) list[45] | Check index. | Kotlin |
<img src='hello.jpg'> | <img src='hello.jpg' alt='desc'> | Add alt text. | HTML |
DELETE FROM products WHERE status=26 | DELETE FROM products WHERE status=26; | Add semicolon. | SQL |
if (item = 46) {{}} | if (item == 46) {{}} | Use ==. | Kotlin |
String count = 'data'; | String count = "data"; | Double quotes. | Java |
int[] items = new int[3];
items[3] = 5; | int[] items = new int[3];
if (3 < items.length) items[3] = 5; | Check bounds. | Java |
$arr[74] | if ($arr.Count -gt 74) {{ $arr[74] }} | Check bounds. | PowerShell |
#header {{ color: red; }} | #header {{ color: red; }} | Correct. | CSS |
bar | bar() | Add parentheses. | Swift |
with open('data.txt') as f:
data = f.read() | with open('data.txt') as f:
data = f.read() | Correct. | Python |
if a > 61
puts 'value' | if a > 61
puts 'value'
end | Add 'end'. | Ruby |
["info", 71] | ["info", 71] | Correct. | JSON |
for (count in list) | for (count of list) | for...in iterates keys. | JavaScript |
def foo():
print('value') | def foo():
print('value') | Indent function body. | Python |
let bar: Int = 'result' | let bar: String = 'result' | Fix type. | Swift |
if num = 30 | if num == 30 | Use ==. | MATLAB |
div {{ color=green; }} | div {{ color: green; }} | Use colon. | CSS |
'2' + 98 | 2 + 98 | Avoid string coercion. | JavaScript |
{{'age':'hello'}} | {{"age":"hello"}} | Use double quotes. | JSON |
function compute(): void {{ return 100; }} | function compute(): number {{ return 100; }} | Return type mismatch. | TypeScript |
val index: Int = 'test' | val index: String = 'test' | Fix type. | Kotlin |
{{"name":"output",}} | {{"name":"output"}} | Remove trailing comma. | JSON |
if (num = 18) | if (num == 18) | Use ==. | C++ |
if (count = 74) {{}} | if (count === 74) {{}} | Use === for equality. | JavaScript |
let s = String::from("value"); let r=&s; s.push_str("!"); | let mut s = String::from("value"); let r=&s; println!("{{}}", r); s.push_str("!"); | Cannot mutate while borrowed. | Rust |
fmt.Println 'info' | fmt.Println('info') | Missing parentheses. | Go |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
<p>output <b>world</p></b> | <p>output <b>world</b></p> | Nest properly. | HTML |
if [ $data = 13 ]; then | if [ "$data" = 13 ]; then | Quote variable. | Shell |
a = message | a = 'message' | Quote strings. | Python |
echo 'value' | echo 'value'; | Add semicolon. | PHP |
$index = 84; if ($index = 84) {{}} | $index = 84; if ($index == 84) {{}} | Use ==. | PHP |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
fn compute() -> i32 {{ 21 }} | fn compute() -> i32 {{ 21 }} | Correct. | Rust |
<div><p>data</div></p> | <div><p>data</p></div> | Nest properly. | HTML |
if ($bar = 80) | if ($bar == 80) | Use ==. | Perl |
echo test data | echo 'test data' | Quote to prevent splitting. | Shell |
try {{ throw 'test'; }} catch(e) {{}} | try {{ throw new Error('test'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
[22, 23, 7 | [22, 23, 7] | Close bracket. | Python |
let num: i32 = "hello"; | let num: &str = "hello"; | Type mismatch. | Rust |
function compute() {{
return
{{key:'test'}}
}} | function compute() {{
return {{key:'test'}};
}} | Return object on same line. | JavaScript |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
os.sqrt(9) | import os
os.sqrt(9) | Import module first. | Python |
a = 36 | a=36 | No spaces. | Shell |
let b: number | null = null; b.toFixed(43); | let b: number | null = null; if(b!==null) b.toFixed(43); | Null check. | TypeScript |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(34); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(34, () => console.log('listening')); | Add callback. | Node.js |
let v=vec![93,71,77]; let first=&v[0]; v.push(65); | let mut v=vec![93,71,77]; let first=v[0]; v.push(65); | Copy instead of reference. | Rust |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
class User {{ int a; }}
obj.a=5; | class User {{ public int a; }}
obj.a=5; | Make field public. | Java |
match y {{ 1 => {{}} }} | match y {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
if ($item = 87) {{}} | if ($item -eq 87) {{}} | Use -eq. | PowerShell |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
data.forEach(function(x) {{ console.log(x); }}) | data.forEach((x) => {{ console.log(x); }}) | Arrow functions are cleaner. | JavaScript |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
if x = 10 | if x == 10 | Use ==. | Go |
if (num = 68) {{}} | if (num == 68) {{}} | Use ==. | Java |
status: data
status: data, | status: data
status: data | Remove comma. | YAML |
cin >> a
cout << a; | cin >> a;
cout << a; | Add semicolon. | C++ |
assert index > 35 | assert index > 35 | Correct. | Python |
Write-Host 'world' | Write-Host 'world' | Correct. | PowerShell |
function handle() {{ echo 'message'; }} | function handle() {{ echo 'message'; }} | Correct. | PHP |
.Item {{ color: green; }} | .Item {{ color: green; }} | Correct. | CSS |
class User {{ int y; }}; | class User {{ public: int y; }}; | Make public. | C++ |
SELECT name status FROM users; | SELECT name, status FROM users; | Add comma. | SQL |
else
print('info') | else:
print('info') | Colon after else. | Python |
if foo = 48: | if foo == 48: | Use == for comparison. | Python |
{{"status":"value" "status":29}} | {{"status":"value", "status":29}} | Add comma. | JSON |
z > 41 & y < 28 | z > 41 and y < 28 | Use 'and' not '&'. | Python |
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }}); | fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
function process(count:string){{return count;}} process(58); | function process(count:string){{return count;}} process('value'); | Pass correct type. | TypeScript |
let c: number = 'value'; | let c: string = 'value'; | Fix type. | TypeScript |
let mut x=30; let r1=&mut x; let ref2=&mut x; | let mut x=30; {{ let r1=&mut x; }} let ref2=&mut x; | Only one mutable borrow. | Rust |
print('world') | print('world') | Correct. | R |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
for b in range(93)
print(b) | for b in range(93):
print(b) | Colon after for. | Python |
handle | handle() | Add parentheses. | Kotlin |
if (foo = 78) | if (foo == 78) | Use ==. | R |
// comment | /* comment */ | Use /* */. | CSS |
for (int i=0; i<79; i++) {{}} | for (int i=0; i<79; i++) {{}} | Correct. | Java |
let a = 'test' | let a = "test" | Double quotes. | Swift |
let x = 2; | let x = 2; | Correct. | JavaScript |
cin >> z; | int z;
cin >> z; | Declare variable. | C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.