[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
so which one is it?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 133
Thread images: 6
File: Screenshot 2016-03-09 15.12.33.png (54 KB, 549x558) Image search: [Google]
Screenshot 2016-03-09 15.12.33.png
54 KB, 549x558
so which one is it?
>>
None
>>
1 because that is what the sample codes I learned from looked like.
>>
why are these the absolute shittiest options

there are only 2 correct answers and neither of them are in this image
>>
2
>>
>>53401579
def main:
print("Hello World")
return 0
>>
>>53401579

int main() {
printf('hello world');
return 0;
}
>>
int main(int argc, char *argv) {

return 0;
}
>>
int main(void)

you retard.
>>
function {
main : int
printf(
"hello world"
);
return 0;
}
>>
File: drink.jpg (62 KB, 500x504) Image search: [Google]
drink.jpg
62 KB, 500x504
>>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.
>>
allman/bsd forever

it doesnt save as much space, but it's cleaner
>>
2 and 4 are fucking despicable
>>
File: 1430838685171.jpg (21 KB, 268x265) Image search: [Google]
1430838685171.jpg
21 KB, 268x265
>>53401579
Which one is the most retarded, you ask?
Probably the last one
>>
>>53401904
I agree ti's cleaner, but i like the K&R version more.
>>
>>53401579
<h2 style="color:#000000;">Hello World</h2>
>>
File: K&R_it_is.png (48 KB, 849x804) Image search: [Google]
K&R_it_is.png
48 KB, 849x804
>>53401579
>>
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.
>>
>>53401579
int main () {
printf('Nope.avi');

return 0;
};
>>
I'm a professional programmer, and this is the only way to properly style your brackets

if (condition)
{
doThis();
} else {
doThat();
}
>>
>>53401893
i like it
>>
Fucking plebs. You have to combine their powers.

Brackets on same line if nested loops.
Brackets on new line if anything else.
>>
>>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.
>>
>>53402200
Correction:
if (condition)
{
doThis();
}
else
{
doThat();
}
>>
>>53402273
tell me why puts is so much better than prtinf

i honestly have no idea and i want to know why
>>
>>53401579
I like the linux styling guide

#include <stdio.h>

int main()
{
printf("Hello, World!\n");
}
>>
File: your_mother_is_so_fat.jpg (34 KB, 355x342) Image search: [Google]
your_mother_is_so_fat.jpg
34 KB, 355x342
>>53402200
I'm Dennis Ritchie and this makes me turn in my grave.
>>
int main()                                               {
printf("Hello World");
return 0; }
>>
>>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.
>>
>>53402358
Do you think this is a fucking game!?
>>
>>53402372
thank you, anon
>>
>>53402372
>Your hello_world isn't optimized

Just kidding, being anal about these things is actually a good thing. Keep it up!
>>
int
func(int param)
{
//code
}
>>
>>53402200
>professional programmer
code monkey*
>>
>>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.
>>
>>53402412
>
int
func

I vomited.
>>
>>53402442
Yes I know about fputs.
>>
>>53402452
> uneducated opinion
Go scrub another toilet you mental midget
>>
>>53402464
i didn't know the difference
>>
>>53402452
>not wanting to find function defintions by greping for '^funcname('

>>53402464
I just added to your post.
>>
int main() {

puts( "noob" );

return 0;

}
>>
#include <iostream>

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

return EXIT_SUCCESS;
}
>>
>>53401579
Java
(){

}

c#
()
{

}
>>
>>53402350
>not using optimized recursive tail calls
>>
>>53401826
The one true correct answer
>>
>>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().
>>
>>53402304
Both gcc and clang replaces printf with just a string with puts.
>>
int function()
{
if(wat) {
butts()
}
}
>>
>>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
>>
>>53401579
Last one for C
>>
>>53401579
int main(){ return cout<<"hello world", 0; }
>>
>>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.
>>
>/g/ doesn't even realize this is bait
>>
>>53401826
at least some people aren't retarded
>>
int main() 
{
puts("Hello World!");
return 0;
}
>>
>>53402273
This tbqh.
>>
>>53402493

acceptable
>>
>>53404918
thanks senpai
>>
int main (){printf('hello world'); return 0;}
>>
>>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.
>>
quick someone post those cs degree graduate code images
>>
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
>>
int
main
(
)
{ printf
( "hello word"
)
; return 0
;
}
>>
>>53401579
The fourth one if you're not an autistic retard.
>>
>>53401826
Correct
>>
int main                (
)
{
printf (
"hello world" )
;
return 0 ;
}
>>
File: 1446496110018.jpg (52 KB, 640x478) Image search: [Google]
1446496110018.jpg
52 KB, 640x478
>>53405214
this desu, senpai

my teacher says to keep my algorithms well documented
>>
>>53401849
It's either char **argv or char *argv[]
>>
>>53405214
TWO WORDS:

WHITE
SPACE
>>
>>53405359
I laughed at this more than I should have.
>>
>>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;
}
>>
int main(void) {
printf("Hello World");
return 0;
}


Read the spec.
>>
>>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
>>
>>53401579
Everything on one line
>>
>>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();
}
>>
>>53403175
How do you use tail recursion with addition?..
>>
>>53401579
func dogoo[param] {
print.toScreen('this is a ' :cons: param :cons: ' dogoo!')>
return>
}
>>
>>53402296
>>53402200
Correction:
if (condition) {
doThis();
} else {
doThat();
}
>>
Brackets go on the next line you incredible fuckwit
>>
>>53406238
This. Because vertical screen space is a precious resource that should not be wasted.
>>
>>53405224
LOL WHAT
>>
>>53401579
int main()
{
printf('hello world');
return 0;
}
>>
Sweet Joseph Smith, 2 and 3 are fucking scary
>>
Genuinely curious. Does anyone actually do

int whatever(void)

Or

return void
>>
>>53406880
what does void even do
>>
>>53406880
Nope, we do.
def whatever():
""" Does nothing """

>>
>>53406951
ikr lmao
>>
>>53406238
correction:
if(condition){
doThis();
}
else {
doThat();
}
>>
>>53406973
genuine question, honestly
>>
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.
>>
>>53407039
specifies that a function does not return anything.
>>
Usually 1
2 and 4 are not comfy
3 is full retard
>>
>>53407080
okay, really does seem pointless
>>
>>53407132
why?
>>
>>53405607

>>ohgod.gif
>>vomit in mouth
>>swallow
>>fetal position
>>cry
>>
function Main returns Integer is
begin
return 0;
end Main
>>
>>53407144
well when is it mostly used, if statements?
>>
>>53407192
no, if statements dont have a return type.

Only functions/methods do.

No offense anon, but have you ever done any programming?
>>
>>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?
>>
>>53407233

Dmanit I just noticed

int
main()

on the last one and realized these are all trolling.
>>
>>53407192
Most common is type casting to a void* or stating a function returns nothing
>>
>>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.
>>
>>53401579
who here actually puts the type above the definition?

Just wondering because i've never seen it be done outside of books
>>
>>53407329
the people who write mysql apparently
>>
>>53407329

What book did you see that in?
>>
>>53401579
Depends on language
>>
>>53401826
>Affirmative
>>
>>53407377

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

Clearly this is all a troll.
>>
>>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.
>>
Just use clang format with Google defaults
>>
>>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
>>
>>53405214
Holy fuck, I lost my sides
>>
>>53401579
int main() {
printf('hello world');
return 0;
}
>>
>>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.
>>
echo world
>>
cat /dev/urandom | grep "Hello world!"
>>
>>53401579
int main() {
printf("Hello world");
return 0; }
>>
1

Who the fuck uses 2 and 3?
>>
>>53405607
pls don't
>>
#include <stdio.h>

int main (void) {
printf ("Hello World!\r\n");
return 0;
}
>>
Always thought I was a lol ahead of the curve. Then I started to TRY learning c++
TFW I'm a retard
>>
>>53410774
No, anon, C++ is retard
>>
OK, serious question here. What about this?
int main() {
printf('hello world');
return 0;
}
>>
>>53410790
Don't get my jimmies unrustled if you don't mean it
>>
>>53401579
int main(void)
{
printf('harro word');
return 0;
}
>>
>>53410774
Don't give up anon, just get trough syntax. CS50 on edx is nice beginners course.
>>
>not following the kernel style guide
https://www.kernel.org/doc/Documentation/CodingStyle
>>
int
main() {printf('hello world');


return 0;
}
>>
>>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++
>>
>>53407303
>what is really going on with a computer
dude plz don't get into the shitfest that happens under the hood
>>
>>53410847
go correct my assignments, teach
>>
>>53410845
>>53410912
Thanks for the advice
>>
>>53401826
This is the best option.
Thread replies: 133
Thread images: 6

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.