Quantcast
[ 3 / biz / cgl / ck / diy / fa / g / ic / jp / lit / sci / tg / vr / vt ] [ index / top / reports / report a bug ] [ 4plebs / archived.moe / rbt ]

/vt/ is now archived.Become a Patron!

/g/ - Technology


View post   

[ Toggle deleted replies ]
File: 54 KB, 549x558, Screenshot 2016-03-09 15.12.33.png [View same] [iqdb] [saucenao] [google] [report]
53401579 No.53401579 [Reply] [Original] [archived.moe] [rbt]

so which one is it?

>> No.53401602

None

>> No.53401631

1 because that is what the sample codes I learned from looked like.

>> No.53401763

why are these the absolute shittiest options

there are only 2 correct answers and neither of them are in this image

>> No.53401811

2

>> No.53401812

>>53401579
def main:
print("Hello World")
return 0

>> No.53401826

>>53401579

int main() {
printf('hello world');
return 0;
}

>> No.53401849

int main(int argc, char *argv) {

return 0;
}

>> No.53401859

int main(void)
you retard.

>> No.53401893

function {
main : int
printf(
"hello world"
);
return 0;
}

>> No.53401902
File: 62 KB, 500x504, drink.jpg [View same] [iqdb] [saucenao] [google] [report]
53401902

>>53401579
Allman style is the only right one, if you use K&R, you are a dumb sheep and I hate you for creating ugly code.

>> No.53401904

allman/bsd forever

it doesnt save as much space, but it's cleaner

>> No.53401915

2 and 4 are fucking despicable

>> No.53401918
File: 21 KB, 268x265, 1430838685171.jpg [View same] [iqdb] [saucenao] [google] [report]
53401918

>>53401579
Which one is the most retarded, you ask?
Probably the last one

>> No.53401977

>>53401904
I agree ti's cleaner, but i like the K&R version more.

>> No.53402004

>>53401579
<h2 style="color:#000000;">Hello World</h2>

>> No.53402035
File: 48 KB, 849x804, K&R_it_is.png [View same] [iqdb] [saucenao] [google] [report]
53402035

>>53401579

>> No.53402095

2, if the printf line had a carriage return after the opening curly brace and before the closing brace.

At least that's how I've always done it. It allows me to avoid simple errors like forgetting the opening or closing braces.

>> No.53402185

>>53401579
int main () {
printf('Nope.avi');

return 0;
};

>> No.53402200

I'm a professional programmer, and this is the only way to properly style your brackets

if (condition)
{
doThis();
} else {
doThat();
}

>> No.53402227

>>53401893
i like it

>> No.53402241

Fucking plebs. You have to combine their powers.

Brackets on same line if nested loops.
Brackets on new line if anything else.

>> No.53402273

>>53401579
Both of those are fucking disgusting.
Only acceptable style of programming:
int main()
{
puts("hello world");
return 0;
}

Also, you can't use single quotes for string literals on C.

>> No.53402296

>>53402200
Correction:
if (condition)
{
doThis();
}
else
{
doThat();
}

>> No.53402304

>>53402273
tell me why puts is so much better than prtinf

i honestly have no idea and i want to know why

>> No.53402325

>>53401579
I like the linux styling guide

#include <stdio.h>

int main()
{
printf("Hello, World!\n");
}

>> No.53402350
File: 34 KB, 355x342, your_mother_is_so_fat.jpg [View same] [iqdb] [saucenao] [google] [report]
53402350

>>53402200
I'm Dennis Ritchie and this makes me turn in my grave.

>> No.53402358

int main() {
printf("Hello World");
return 0; }

>> No.53402372

>>53402304
printf for format string.
puts for printing raw strings.

correct usage of printf:
printf("x = %i\n", x);
incorrect usage of printf:
printf("blah blah this is string\n");
which should be corrected to:
puts("blah blah this is string");

printf has lots of overhead, so use it only when you actually need to.

>> No.53402378

>>53402358
Do you think this is a fucking game!?

>> No.53402390

>>53402372
thank you, anon

>> No.53402401

>>53402372
>Your hello_world isn't optimized

Just kidding, being anal about these things is actually a good thing. Keep it up!

>> No.53402412

int
func(int param)
{
//code
}

>> No.53402417

>>53402200
>professional programmer
code monkey*

>> No.53402442

>>53402372
You also want to know about
fputs("free as in freedom", stdout);
instead of
printf("free as in freedom");
puts() always adds a newline, which is not always the wanted behaviour.

>> No.53402452

>>53402412
>int
func

I vomited.

>> No.53402464

>>53402442
Yes I know about fputs.

>> No.53402481

>>53402452
> uneducated opinion
Go scrub another toilet you mental midget

>> No.53402483

>>53402464
i didn't know the difference

>> No.53402491

>>53402452
>not wanting to find function defintions by greping for '^funcname('

>>53402464
I just added to your post.

>> No.53402493

int main() {

puts( "noob" );

return 0;

}

>> No.53402514

#include <iostream>

int main(int argc, char** argv)
{
std::cout << "Jello"
<< " "
<< "Quarrel"
<< std::endl;

return EXIT_SUCCESS;
}

>> No.53402535

>>53401579
Java
(){

}

c#
()
{

}

>> No.53403175

>>53402350
>not using optimized recursive tail calls

>> No.53403319

>>53401826
The one true correct answer

>> No.53404149

>>53402273
>>53402304
Any modern compiler will swap out any call to printf with puts anyway if you pass a static string. Try it yourself:

gcc printf.c -o printf

objdump -d printf

Notice the call to puts() instead of printf().

>> No.53404247

>>53402304
Both gcc and clang replaces printf with just a string with puts.

>> No.53404267

int function()
{
if(wat) {
butts()
}
}

>> No.53404276

>>53404149
>>53404247
well isn't it good to use puts for maximum portability though?

what if for some reason you need to compile it on an ancient platform with no modern compilers

>> No.53404277

>>53401579
Last one for C

>> No.53404294

>>53401579
int main(){ return cout<<"hello world", 0; }

>> No.53404323

>>53404276
Then you should know what you're doing. I'd argue that the majority of people here who would ever need to be concerned with such things (which I'm sure is very few if any) already know standard C and the lower level semantics of it. For the vast majority, using printf is fine.

>> No.53404329

>/g/ doesn't even realize this is bait

>> No.53404728

>>53401826
at least some people aren't retarded

>> No.53404785

int main()
{
puts("Hello World!");
return 0;
}

>> No.53404809

>>53402273
This tbqh.

>> No.53404918

>>53402493

acceptable

>> No.53405013

>>53404918
thanks senpai

>> No.53405089

int main (){printf('hello world'); return 0;}

>> No.53405091

>>53401579
first one is what ive come to use.
i oficially learned to do it the 4th way but the first one is more readable to me id put return on its own line though.

>> No.53405131

quick someone post those cs degree graduate code images

>> No.53405214

int // return type for the main function
main // name for the main function
( // start of main function arguments
) // end of main function arguments
{ // start of main function code block
puts // puts
( // start arguments for puts function call
"Hello World!" // first argument for puts function call, it's a string containing the words Hello and World (both capitalised), followed by a decapitated upside down quadriplegic
) // enf of arguments for puts function call
; // end puts function call statment
return // start of retrn statment
0 // return value, it's a zero
; // end of return statment
} // end of main function code block

>> No.53405224

int
main
(
)
{ printf
( "hello word"
)
; return 0
;
}

>> No.53405237

>>53401579
The fourth one if you're not an autistic retard.

>> No.53405342

>>53401826
Correct

>> No.53405359

int main (
)
{
printf (
"hello world" )
;
return 0 ;
}

>> No.53405400
File: 52 KB, 640x478, 1446496110018.jpg [View same] [iqdb] [saucenao] [google] [report]
53405400

>>53405214
this desu, senpai

my teacher says to keep my algorithms well documented

>> No.53405427

>>53401849
It's either char **argv or char *argv[]

>> No.53405429

>>53405214
TWO WORDS:

WHITE
SPACE

>> No.53405445

>>53405359
I laughed at this more than I should have.

>> No.53405456

>>53401579
#include <stdio.h>

int main () {
printf("If you don't do it this way, you're wasting your time pressing return.\n");

if (fuckYou) {
goToBed(youFaggot);
} else {
goFapYouFaggot();
}

return 0;
}

>> No.53405489

int main(void) {
printf("Hello World");
return 0;
}


Read the spec.

>> No.53405607

>>53405359
#include \
<stdio.h>
int main (
)
{
int i ;
for (
i = 1 ;
i <= 100 ;
++i )
{
if (
i < 50 )
{
printf (
"ur an faget\n" )
;
}
else {
printf (
"memes\n" )
;
}
}
}

this is how I'm doing all my programming from now on

>> No.53405609

>>53401579
Everything on one line

>> No.53405819

>>53402200
>>53402273
you both suck.

consider this superior alternative:
// reasonably vertically compact with same-line opening brace
if (condition) {
doThis();
}
// can insert/remove comment here without touching non-comment lines in diffs
else {
doThat();
}

>> No.53405974

>>53403175
How do you use tail recursion with addition?..

>> No.53406193

>>53401579
func dogoo[param] {
print.toScreen('this is a ' :cons: param :cons: ' dogoo!')>
return>
}

>> No.53406238

>>53402296
>>53402200
Correction:
if (condition) {
doThis();
} else {
doThat();
}

>> No.53406264

Brackets go on the next line you incredible fuckwit

>> No.53406266

>>53406238
This. Because vertical screen space is a precious resource that should not be wasted.

>> No.53406490

>>53405224
LOL WHAT

>> No.53406710

>>53401579
int main()
{
printf('hello world');
return 0;
}

>> No.53406747

Sweet Joseph Smith, 2 and 3 are fucking scary

>> No.53406880

Genuinely curious. Does anyone actually do

int whatever(void)

Or

return void

>> No.53406951

>>53406880
what does void even do

>> No.53406953

>>53406880
Nope, we do.
def whatever():
""" Does nothing """

>> No.53406973

>>53406951
ikr lmao

>> No.53407013

>>53406238
correction:
if(condition){
doThis();
}
else {
doThat();
}

>> No.53407039

>>53406973
genuine question, honestly

>> No.53407046

It doesn't matter. Do what you like. Anyone expressing strong opinions about this is a terrible programmer. Good programmers have more important things to hold strong opinions about.

>> No.53407080

>>53407039
specifies that a function does not return anything.

>> No.53407115

Usually 1
2 and 4 are not comfy
3 is full retard

>> No.53407132

>>53407080
okay, really does seem pointless

>> No.53407144

>>53407132
why?

>> No.53407157

>>53405607

>>ohgod.gif
>>vomit in mouth
>>swallow
>>fetal position
>>cry

>> No.53407181

function Main returns Integer is
begin
return 0;
end Main

>> No.53407192

>>53407144
well when is it mostly used, if statements?

>> No.53407208

>>53407192
no, if statements dont have a return type.

Only functions/methods do.

No offense anon, but have you ever done any programming?

>> No.53407233

>>53401579

Nobody on the planet earth does any of those except the last one; whereass the first one would be a favorite if the return value wasn't on the same line as printf like that for some unknown crazy reason...nobody does that do they?

>> No.53407252

>>53407233

Dmanit I just noticed

int
main()

on the last one and realized these are all trolling.

>> No.53407259

>>53407192
Most common is type casting to a void* or stating a function returns nothing

>> No.53407303

>>53407132

All functions return something.

If you don't put 'return' that doesn't magically make the function not return anything; most languages just baby you and fill in the blanks to make stuff easier.

C is supposed to be a right-above-low-level-language and therefore does not encourage this type of thing even though compilers will put a 'return 0' if you just leave it blank most of the time; that's not good practice.

This has to do with assembly, memory, etc. etc. and if you'd like to learn about it this is a good place:

http://opensecuritytraining.info/IntroX86.html

tl;dr What is going on in your head as you are thinking about code is nothing like what is really going on with a computer and learning more about what is actually going on with the computer is very enjoyable and useful.

>> No.53407329

>>53401579
who here actually puts the type above the definition?

Just wondering because i've never seen it be done outside of books

>> No.53407353

>>53407329
the people who write mysql apparently

>> No.53407354

>>53407329

What book did you see that in?

>> No.53407377

>>53401579
Depends on language

>> No.53407385

>>53401826
>Affirmative

>> No.53407388

>>53407377

What language would you use ANY of those formatting options in?

Clearly this is all a troll.

>> No.53407753

>>53401579
All of those are just wrong. At minimum the return 0 should be on its own line and they should only be single indented from the function that are in.

The only subjective thing is weather the first bracket should be on its own line or not.

>> No.53407865

Just use clang format with Google defaults

>> No.53408041

>>53401579
int main()
{
printf('hello world');
return 0;
}


or


int main() {
printf('hello world');
return 0;
}


if you're doing anything other than this then get the fuck out you faggot ass motherfucking fuck a niggas fuckin dumb shit

>> No.53408058

>>53405214
Holy fuck, I lost my sides

>> No.53408069

>>53401579
int main() {
printf('hello world');
return 0;
}

>> No.53410286

>>53407303
>all functions return something
Depends on what you mean by "return". At the end of every function, eax/rax (the 32/64bit registers that store the return value in x86 conventions) will have a value, but what that value is, and whether or not it was even modified by the function is compiler defined, and can be affected by any number of optimization flags even on the same compiler. So yeah, it "returns" in the sense that you can pull the value off of the return register, but is it really returning that value if the function never sets it during its execution? In this case, I'd argue it isn't actually returning a value in the traditional sense, and you are creating undefined behavior, where the return value could be anything that it was set to prior to the function call.

>> No.53410631

echo world

>> No.53410644

cat /dev/urandom | grep "Hello world!"

>> No.53410692

>>53401579
int main() {
printf("Hello world");
return 0; }

>> No.53410723

1

Who the fuck uses 2 and 3?

>> No.53410724

>>53405607
pls don't

>> No.53410764

#include <stdio.h>

int main (void) {
printf ("Hello World!\r\n");
return 0;
}

>> No.53410774

Always thought I was a lol ahead of the curve. Then I started to TRY learning c++
TFW I'm a retard

>> No.53410790

>>53410774
No, anon, C++ is retard

>> No.53410796

OK, serious question here. What about this?
int main() {
printf('hello world');
return 0;
}

>> No.53410819

>>53410790
Don't get my jimmies unrustled if you don't mean it

>> No.53410826

>>53401579
int main(void)
{
printf('harro word');
return 0;
}

>> No.53410845

>>53410774
Don't give up anon, just get trough syntax. CS50 on edx is nice beginners course.

>> No.53410847

>not following the kernel style guide
https://www.kernel.org/doc/Documentation/CodingStyle

>> No.53410864

int
main() {printf('hello world');


return 0;
}

>> No.53410912

>>53410819

My advice - make sure you only learn C++ when you know your shit with something simpler like C and feel like you need all the additional stuff in order to move forwards

learning C is 4 parts programming concepts, and one part syntax (with a sprinkling of undefined behaviour and GNU quirks, but you don't have to learn all of it for most purposes)
learning C++ is those same 4 parts programming, 10 additional parts syntax, 20 parts OO / metaprogramming, and 99 parts learning implementation details of features that have been tacked on the the standard library

the only fun bit in any of those is the programming, and that's the only thing that could possibly motivate anyone to learn C++

>> No.53410948

>>53407303
>what is really going on with a computer
dude plz don't get into the shitfest that happens under the hood

>> No.53410992

>>53410847
go correct my assignments, teach

>> No.53411048

>>53410845
>>53410912
Thanks for the advice

>> No.53411746

>>53401826
This is the best option.

>>
Name (leave empty)
Comment (leave empty)
Name
E-mail
Subject
Comment
Password [?]Password used for file deletion.
Captcha
Action