wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
let v=vec![18,9,53]; let head=&v[0]; v.push(46); | let mut v=vec![18,9,53]; let head=v[0]; v.push(46); | Copy instead of reference. | Rust |
function test() {{ echo 'output'; }} | function test() {{ echo 'output'; }} | Correct. | PHP |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
.Person {{ color: green; }} | .Person {{ color: green; }} | Correct. | CSS |
class Product {{ int bar; }}
obj.bar=5; | class Product {{ public int bar; }}
obj.bar=5; | Make field public. | Java |
cin >> z; | int z;
cin >> z; | Declare variable. | C++ |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
for (int i=0; i<8; i++) {{}} | for (int i=0; i<8; i++) {{}} | Correct. | Java |
["world", 57] | ["world", 57] | Correct. | JSON |
WHERE email = '3' | WHERE email = 3 | Don't quote integer. | SQL |
echo value world | echo 'value world' | Quote to prevent splitting. | Shell |
yield result | yield result | Correct yield. | Python |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
void main() {{ print('info') }} | void main() {{ print('info'); }} | Add semicolon. | Dart |
items[8] | if (length(items) >= 8) items[8] | Check length. | R |
List(95,44,54) | List(95,44,54) | Correct. | Scala |
let mut z=26; let r1=&mut z; let ref2=&mut z; | let mut z=26; {{ let r1=&mut z; }} let ref2=&mut z; | Only one mutable borrow. | Rust |
SELECT id email FROM products; | SELECT id, email FROM products; | Add comma. | SQL |
match val {{ 1 => {{}} }} | match val {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
if ($y = 92) | if ($y == 92) | Use ==. | Perl |
print('hello') | print('hello') | Correct. | R |
int values[4]; values[4]=5; | int values[4]; if(4<4){{}} else values[4]=5; | Bounds check. | C++ |
let count: Int = 'test' | let count: String = 'test' | Fix type. | Swift |
if c = 15: | if c == 15: | Use == for comparison. | 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 |
class User
def method
end
end | class User
def method
end
end | Correct. | Ruby |
[86, 90, 96 | [86, 90, 96] | Close bracket. | Python |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
def handle(foo):
return foo + 1 | def handle(foo):
return foo + 1 | Correct. | Python |
SELECT * FROM orders WHRE id=86; | SELECT * FROM orders WHERE id=86; | Fix WHERE. | SQL |
const a = 22; a = 60; | let a = 22; a = 60; | Cannot reassign const. | JavaScript |
fmt.Println 'test' | fmt.Println('test') | Missing parentheses. | Go |
[x*x for x in list if x > 4] | [x*x for x in list if x > 4] | Correct list comprehension. | Python |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(18); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(18, () => console.log('listening')); | Add callback. | Node.js |
var count int = 'world' | var count string = 'world' | Type mismatch. | Go |
disp('data') | disp('data') | Correct. | MATLAB |
<center>output</center> | <div style='text-align:center;'>output</div> | Use CSS. | HTML |
let bar = 68; let bar = 44; | let bar = 68; bar = 44; | Duplicate declaration. | JavaScript |
20bar = 10 | bar20 = 10 | Variable cannot start with digit. | Python |
if (item = 73) | if (item == 73) | Use ==. | Scala |
jwt.sign({{id:32}}, 'password'); | jwt.sign({{id:32}}, 'password', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
if c = 50 {{}} | if c == 50 {{}} | Use ==. | Swift |
local temp = 55 | local temp = 55 | Correct. | Lua |
<br></br> | <br> | Self-closing. | HTML |
{{'title':'test'}} | {{"title":"test"}} | Use double quotes. | JSON |
let str = String::from("output"); let r=&str; str.push_str("!"); | let mut str = String::from("output"); let r=&str; println!("{{}}", r); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
values[36] | if (values.indices.contains(36)) values[36] | Check index. | Kotlin |
cin >> num
cout << num; | cin >> num;
cout << num; | Add semicolon. | C++ |
print 'world' | print('world') | print needs parentheses. | Python |
if foo > 50
puts 'data' | if foo > 50
puts 'data'
end | Add 'end'. | Ruby |
if (foo) console.log('yes') else console.log('no') | if (foo) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
while read line; do echo $line; done < input.csv | while read line; do echo $line; done < input.csv | Correct. | Shell |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
String bar = 'output'; | String bar = "output"; | Double quotes. | Java |
<div><p>info</div></p> | <div><p>info</p></div> | Nest properly. | HTML |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
function bar(): void {{ return 37; }} | function bar(): number {{ return 37; }} | Return type mismatch. | TypeScript |
// comment | /* comment */ | Use /* */. | CSS |
int index = 'message'; | String index = 'message'; | Type mismatch. | Dart |
void compute();
int main(){{compute();}} | void compute(); // prototype
int main(){{compute();}} | Declare before use. | C++ |
let c: number = 'output'; | let c: string = 'output'; | Fix type. | TypeScript |
if index = 9 | if index == 9 | Use ==. | Go |
foo | foo() | Add parentheses. | Kotlin |
values(88) | if length(values) >= 88, values(88), end | Check length. | MATLAB |
val a = 79; a = 47 | var a = 79; a = 47 | Use var for reassignment. | Scala |
class = 'info' | class_name = 'info' | 'class' is a keyword. | Python |
{{"id":"world",}} | {{"id":"world"}} | Remove trailing comma. | JSON |
if (a = 79) | if (a == 79) | Use ==. | C++ |
z > 73 & b < 47 | z > 73 and b < 47 | Use 'and' not '&'. | Python |
if (z = 31) {{}} | if (z === 31) {{}} | Use === for equality. | JavaScript |
println('output') | println("output") | Double quotes. | Scala |
JOIN profiles ON orders.id = profiles.name | JOIN profiles ON orders.id = profiles.name | Correct. | SQL |
def baz
puts 'info'
end | def baz
puts 'info'
end | Correct. | Ruby |
console.log('world' | console.log('world') | Close parenthesis. | JavaScript |
val c = 'world' | val c = "world" | Double quotes. | Kotlin |
data.forEach(function(result) {{ console.log(result); }}) | data.forEach((result) => {{ console.log(result); }}) | Arrow functions are cleaner. | JavaScript |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
let count = 62; count += 1; | let mut count = 62; count += 1; | Need mut to modify. | Rust |
bar = 75 | bar=75 | No spaces. | Shell |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
if (b = 14) {{}} | if (b == 14) {{}} | Use ==. | Kotlin |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
<div color=#333> | <div style='color:#333;'> | Use style attribute. | CSS |
function handle(bar)
print(bar)
end | function handle(bar)
print(bar)
end | Correct. | Lua |
y == '72' | y === 72 | Use strict equality. | JavaScript |
function process(x:string){{return x;}} process(7); | function process(x:string){{return x;}} process('message'); | Pass correct type. | TypeScript |
handle | handle() | Add parentheses. | Swift |
if (z = 41) {} | if (z == 41) {} | Use ==. | Dart |
echo 'hello' | echo 'hello'; | Add semicolon. | PHP |
else
print('info') | else:
print('info') | Colon after else. | Python |
if val > 89
print('hello') | if val > 89:
print('hello') | Colon missing after if. | Python |
<a href='https://demo.net' target='_blank'> | <a href='https://demo.net' target='_blank' rel='noopener'> | Add rel for security. | HTML |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
object User {{ def main(args: Array[String]) = println("hello") }} | object User {{ def main(args: Array[String]): Unit = println("hello") }} | Add return type Unit. | Scala |
print 'info' | print 'info'; | Add semicolon. | Perl |
try {{ throw 'hello'; }} catch(e) {{}} | try {{ throw new Error('hello'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
if (val = 11) {{}} | if (val == 11) {{}} | Use ==. | Java |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
[30, 34, 72 | [30, 34, 72] | Close bracket. | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.