wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
INSERT INTO users VALUES ('world',46) | INSERT INTO users (name, email) VALUES ('world',46); | Specify columns. | SQL |
'value' + 23 | 'value' + 23.to_s | Convert int. | Ruby |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
if foo = 77: | if foo == 77: | Use == for comparison. | Python |
List(91,73,99) | List(91,73,99) | Correct. | Scala |
for result in range(66)
print(result) | for result in range(66):
print(result) | Colon after for. | Python |
String temp = 'value'; | String temp = "value"; | Double quotes. | Java |
val count = 10; count = 67 | var count = 10; count = 67 | Use var for reassignment. | Scala |
int* obj = nullptr; *obj=5; | int* obj = new int; *obj=5; | Allocate memory. | C++ |
arr[6] | if (length(arr) >= 6) arr[6] | Check length. | R |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
[63, 25, 59 | [63, 25, 59] | Close bracket. | Python |
if [ $count = 30 ]; then | if [ "$count" = 30 ]; then | Quote variable. | Shell |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
if (temp = 35) | if (temp == 35) | Use ==. | Scala |
disp('message') | disp('message') | Correct. | MATLAB |
if data = 38 | if data == 38 | Use ==. | Ruby |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
val temp = 'value' | val temp = "value" | Double quotes. | Kotlin |
re.sqrt(88) | import re
re.sqrt(88) | Import module first. | Python |
const p:Person = {{name:'data'}}; | const p:Person = {{name:'data', age:38}}; | Add missing property. | TypeScript |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
if x = 54 then
print('output')
end | if x == 54 then
print('output')
end | Use ==. | Lua |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
val x: Int = 'output' | val x: String = 'output' | Fix type. | Kotlin |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
print('data') | print('data') | Correct. | R |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
let result = 'value' | let result = "value" | Double quotes. | Swift |
let v=vec![61,82,25]; let first=&v[0]; v.push(97); | let mut v=vec![61,82,25]; let first=v[0]; v.push(97); | Copy instead of reference. | Rust |
<p>output <b>test</p></b> | <p>output <b>test</b></p> | Nest properly. | HTML |
object Item {{ def main(args: Array[String]) = println("value") }} | object Item {{ def main(args: Array[String]): Unit = println("value") }} | Add return type Unit. | Scala |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
<div><p>hello</div></p> | <div><p>hello</p></div> | Nest properly. | HTML |
let text1 = String::from("test"); let text2 = text1; println!("{{}}", text1); | let text1 = String::from("test"); let text2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
fmt.Println 'test' | fmt.Println('test') | Missing parentheses. | Go |
while read line; do echo $line; done < log.txt | while read line; do echo $line; done < log.txt | Correct. | Shell |
let text = String::from("world"); let r=&text; text.push_str("!"); | let mut text = String::from("world"); let r=&text; println!("{{}}", r); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
data[43] | if (data.indices.contains(43)) data[43] | Check index. | Kotlin |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
class Person
def method
end
end | class Person
def method
end
end | Correct. | Ruby |
result = 74 | result=74 | No spaces. | Shell |
if b > 95
puts 'world' | if b > 95
puts 'world'
end | Add 'end'. | Ruby |
x := 93 | x := 93 | Correct. | Go |
echo 'hello' | echo 'hello'; | Add semicolon. | PHP |
if (val) console.log('yes') else console.log('no') | if (val) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
my @arr = (1,78,62); | my @arr = (1,78,62); | Correct. | Perl |
z > 79 & y < 64 | z > 79 and y < 64 | Use 'and' not '&'. | Python |
<entry><age>world</age><age>23</age></entry | <entry><age>world</age><age>23</age></entry> | Add closing >. | XML |
<ul><li>hello<li>test</ul> | <ul><li>hello</li><li>test</li></ul> | Close li. | HTML |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(60); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(60, () => console.log('listening')); | Add callback. | Node.js |
match val {{ 1 => {{}} }} | match val {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
let val: number = 'value'; | let val: string = 'value'; | Fix type. | TypeScript |
<entry name='test'/> | <entry name="test"/> | Double quotes. | XML |
void main() {{ print('result') }} | void main() {{ print('result'); }} | Add semicolon. | Dart |
["hello", 41] | ["hello", 41] | Correct. | JSON |
fn test() -> i32 {{ 52 }} | fn test() -> i32 {{ 52 }} | Correct. | Rust |
def test():
print('test') | def test():
print('test') | Indent function body. | Python |
data.forEach(function(temp) {{ console.log(temp); }}) | data.forEach((temp) => {{ console.log(temp); }}) | Arrow functions are cleaner. | JavaScript |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
const val = 58; val = 14; | let val = 58; val = 14; | Cannot reassign const. | JavaScript |
{{"title":"world" "value":87}} | {{"title":"world", "value":87}} | Add comma. | JSON |
let count = 80; count += 1; | let mut count = 80; count += 1; | Need mut to modify. | Rust |
function foo(a:string){{return a;}} foo(21); | function foo(a:string){{return a;}} foo('world'); | Pass correct type. | TypeScript |
<person age=28> | <person age="28"> | Quote attribute. | XML |
let mut foo=53; let r1=&mut foo; let ref2=&mut foo; | let mut foo=53; {{ let r1=&mut foo; }} let ref2=&mut foo; | Only one mutable borrow. | Rust |
baz | baz() | Add parentheses. | Swift |
if temp = 27 | if temp == 27 | Use ==. | MATLAB |
89result = 10 | result89 = 10 | Variable cannot start with digit. | Python |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
<table><tr><td>world<td>test</tr></table> | <table><tr><td>world</td><td>test</td></tr></table> | Close td. | HTML |
print 'value' | print 'value'; | Add semicolon. | Perl |
values(13) | if length(values) >= 13, values(13), end | Check length. | MATLAB |
#main {{ color: green; }} | #main {{ color: green; }} | Correct. | CSS |
h1 {{ font-size:63px color:red; }} | h1 {{ font-size:63px; color:red; }} | Add semicolon. | CSS |
if ($y = 88) {{}} | if ($y -eq 88) {{}} | Use -eq. | PowerShell |
const c; | const c = 69; | Initialize const. | JavaScript |
<br></br> | <br> | Self-closing. | HTML |
<hr></hr> | <hr> | Self-closing. | HTML |
item == '18' | item === 18 | Use strict equality. | JavaScript |
class Person {{ int c; }}; | class Person {{ public: int c; }}; | Make public. | C++ |
println('test') | println("test") | Double quotes. | Scala |
let bar: number | null = null; bar.toFixed(94); | let bar: number | null = null; if(bar!==null) bar.toFixed(94); | Null check. | TypeScript |
let val: i32 = "data"; | let val: &str = "data"; | Type mismatch. | Rust |
.Order {{ color: blue; }} | .Order {{ color: blue; }} | Correct. | CSS |
name: value
age: 96 | name: value
age: 96 | Correct. | YAML |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
JOIN products ON orders.id = products.status | JOIN products ON orders.id = products.status | Correct. | SQL |
cin >> b; | int b;
cin >> b; | Declare variable. | C++ |
def test(data):
return data + 1 | def test(data):
return data + 1 | Correct. | Python |
'19' + 10 | 19 + 10 | Avoid string coercion. | JavaScript |
while val > 10
val -= 1 | while val > 10:
val -= 1 | Colon missing after while. | Python |
UPDATE orders SET id='info' WHERE role=99 | UPDATE orders SET id='info' WHERE role=99; | Add semicolon. | SQL |
$arr[34] | if ($arr.Count -gt 34) {{ $arr[34] }} | Check bounds. | PowerShell |
handle | handle() | Add parentheses. | Kotlin |
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(34); | const http = require('http'); http.createServer((req,res) => res.end('value')).listen(34); | Correct. | Node.js |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.