Beautified That For You
-
-
@Dragnslcr Yeah, the canned example was always funny to me:
IM IN YER LOOP UPPIN YER VAR TIL BOTH SAEM VAR AND 10 // ... KTHX
-
@Magus said in Beautified That For You:
@Dragnslcr Yeah, the canned example was always funny to me:
IM IN YER LOOP UPPIN YER VAR TIL BOTH SAEM VAR AND 10 // ... KTHX
I'm having trouble interpreting this language...
-
@Tsaukpaetra It's LOLCODE, the programming language based on the speech of LOLCATs! It's one of the most easily readable languages ever written imo.
-
-
@Magus Of course there's always ArnoldC
Example a = (4 + b) * 2
GET TO THE CHOPPER a HERE IS MY INVITATION 4 GET UP b YOU'RE FIRED 2 ENOUGH TALK
-
@clatter said in Beautified That For You:
I don't know of any diff program which can successfully ignore the line break changes.
IntelliJ's diff viewer / merge tool does.
-
Syntax issues? Let's ask ... @ScholRLEA? @Schol_R_LEA? Weird name guy who likes LISP and such.
-
@aliceif said in Beautified That For You:
Syntax issues? Let's ask ... @ScholRLEA? @Schol_R_LEA? Weird name guy who likes LISP and such.
This thread does make Lisp weenies seem sane in comparison. I should know, I used to be one of them.
-
@antiquarian said in Beautified That For You:
This thread does make Lisp weenies seem sane in comparison.
Now, now, let's not be rash here. That many parentheses can't possibly be good for you.
-
@Dreikin I would want to learn lisp if those parenthesis didn't annoy me just looking at it
-
@clatter said in Beautified That For You:
Indeed, but if I de-uglify on checkout it makes a mess of the diff for work in progress. I'll have to create a de-uglified working branch for each change, and re-uglify before reintegration.
I think with a git smudge filter it won't make a mess of the diff. But it might not be worth it to set it up.
-
@clatter said in Beautified That For You:
measured by Columns of Code.
We need a name for that... hmmm... Columns Of Code... Columns Of Code Count... CoCC? Nah, those two Cs right next to each other bother me...
CoCK. Yes, that works. You enlarged your CoCK! Well done!
-
@anotherusername said in Beautified That For You:
@clatter by jove, you're right. Instead of one badly-aligned column, there's two columns.
Actually, shouldn't that be:
int main( int argc, char ** argv ) { const char * str = "Hello, world!"; printf( "%s\n", str ); return 0; }
Can we please modify the C* spec so that this (and the OP) don't compile? Please? The world will be better for it
FILED UNDER:
Sytax Error C1337: Here's a nickel, kid, get yourself a better code style
-
@fbmac You can use brackets and parentheses interchangeably in many Scheme (one of the silly LISP languages) implementations.
-
@sloosecannon
Go has something like that.
-
-
This whole thread serves as another reminder why C syntax is shit. It was okay in its time (1970) but it could've gotten a makeover since.
-
@Dreikin You don't need them in JavaScript either:
-
@clatter said in Beautified That For You:
Beautiful new code:
int main( int argc, char ** argv) { const char * str = "Hello, world!"; printf("%s\n", str); return 0; }
I got close...
pjh@pjh-thinkpad:~$ cat /tmp/hello.c int main (int argc,char**argv){ const char *str = "Hello, world!"; printf ("%s\n", str); return 0; }
pjh@pjh-thinkpad:~$ indent /tmp/hello.c -st -bad -bfda -bfde -di50 -prs int main ( int argc, char **argv ) { const char *str = "Hello, world!"; printf ( "%s\n", str ); return 0; }
Do I win anything?
-
@lucas1 that doesn't say anything about parentheses not being required.
I can think of only one situation in which parentheses around an arguments list are not required in Javascript, and that is defining a fat-arrow function that has exactly 1 argument. And you do still need parentheses around the arguments list to call it:
var fn = x => x * 2; alert(fn(5)); // alerts 10
-
@anotherusername I reckon there could be a way of doing it, if I epically abused the interpreter.
-
@PJH
Excellent attempt, congratulations! You can choose any prize from the bottom shelf.
Here, someone actually customised an open source tool to get that beautiful new code just right.
-
@lucas1 pretty sure there's not. But feel free to try.
-
@PJH I like how there's a -bad flag.
-
@JazzyJosh said in Beautified That For You:
@PJH I like how there's a -bad flag.
There's also
-bap
,-nip
,-nut
,-pmt
,-sob
and - of course ---Bill-Shannon
,
-
Take the octopus thing @PJH , it looks cool!
-
@Onyx said in Beautified That For You:
Take the octopus thing @PJH , it looks cool!
It's a space invader, and it's not on the bottom shelf...
-
@PJH how is that a space... Stupid emoji!
Also, darn!
-
It's clearly missing 6 legs to be a octopus.
-
@clatter said in Beautified That For You:
Management has introduced a mandatory code beautifier. Hooray!
Ugly old code:
int main(int argc, char **argv) { const char *str = "Hello, world!"; printf("%s\n", str); return 0; }
Beautiful new code:
int main( int argc, char ** argv) { const char * str = "Hello, world!"; printf("%s\n", str); return 0; }
int main( int argc, char ** argv ) { const char * str = "Hello, world!"; printf("%s\n", str); return 0; }
Now that is better, just like that! A good barber cuts few stray hairs and you look gorgeous!
Just suggest this to them as improvement and get promoted in a night:
int main( int argc, // Number of arguments in argv char ** argv // Command line arguments ) { const char * str = "Hello, world!"; printf("%s\n", str); return 0; }
-
@dse said in Beautified That For You:
int main( int argc, // Number of arguments in argc char ** argv // Command line arguments ) { const char * str = "Hello, world!"; printf("%s\n", str); return 0; }
Not enough comments.
/** @brief This is the main function of the program and will be executed first * @param argc number of command line parameters passed * @param argv list of command line arguments * @param envp list of environment variables * @return 0 */ int main( int argc, //!< Number of arguments in argc char ** argv /*!< Command line arguments */ char * envp[] /**< Environment variables */ ) { const char * str = "Hello, world!"; /* Store a pointer to the string into str */ printf("%s\n", str); // print 'hello world?' return 0; /* exit gracefully */ }
-
@PJH
No fair! You should have disclosed that you work here!
-
@clatter said in Beautified That For You:
No fair! You should have disclosed that you work here!
I don't. To me, that's parody; I get the impression that to you it's reality...
-
@PJH it's also missing any resemblance to a space invader.
-
@PJH said in Beautified That For You:
@clatter said in Beautified That For You:
No fair! You should have disclosed that you work here!
I don't. To me, that's parody; I get the impression that to you it's reality...
It's funny because it's true.
:(
-
@PJH said in Beautified That For You:
@dse said in Beautified That For You:
int main( int argc, // Number of arguments in argc char ** argv // Command line arguments ) { const char * str = "Hello, world!"; printf("%s\n", str); return 0; }
Not enough comments.
/** @brief This is the main function of the program and will be executed first * @param argc number of command line parameters passed * @param argv list of command line arguments * @param envp list of environment variables * @return 0 */ int main( int argc, //!< Number of arguments in argc char ** argv /*!< Command line arguments */ char * envp[] /**< Environment variables */ ) { const char * str = "Hello, world!"; /* Store a pointer to the string into str */ printf("%s\n", str); // print 'hello world?' return 0; /* exit gracefully */ }
Still not good enough.
/** @brief This is the main function of the program and will be executed first. * @param argc Number of command line parameters passed. * @param argv List of command line arguments. * @param envp List of environment variables. * @return 0 */ int main ( /* `const`? | type | pointer? | constp? | name | `[]`? | `=`? | default value? | comments */ int argc //!< Number of arguments in argc. , char ** argv //!< Command line arguments. , char * envp [] //!< Environment variables. ) { /* SECTION: VARIABLES */ /* `const`? | type | pointer? | constp? | name | `[]`? | `=`? | default value? | `;` | comments */ const char * str = "Hello, world!" ; // Store a pointer to the string into str. /* SECTION: FUNCTIONS AND EXPRESSIONS */ /* receiving variable? | `=`? | function or expression | `;` | comments */ printf("%s\n", str) ; // Print 'hello world?'. /* SECTION: RETURNS */ /* `return` | value | `;` | comments */ return 0 ; // Exit gracefully. }
Edit: updated, since @PJH changed it out from under me.
-
@Dreikin said in Beautified That For You:
@PJH said in Beautified That For You:
@dse said in Beautified That For You:
int main( int argc, // Number of arguments in argc char ** argv // Command line arguments ) { const char * str = "Hello, world!"; printf("%s\n", str); return 0; }
Not enough comments.
/** @brief This is the main function of the program and will be executed first * @param argc number of command line parameters passed * @param argv list of command line arguments * @param envp list of environment variables * @return 0 */ int main( int argc, //!< Number of arguments in argc char ** argv /*!< Command line arguments */ char * envp[] /**< Environment variables */ ) { const char * str = "Hello, world!"; /* Store a pointer to the string into str */ printf("%s\n", str); // print 'hello world?' return 0; /* exit gracefully */ }
Still not good enough.
/** @brief This is the main function of the program and will be executed first. * @param argc Number of command line parameters passed. * @param argv List of command line arguments. * @param envp List of environment variables. * @return 0 */ int main ( /* `const`? | type | pointer? | constp? | name | `[]`? | `=`? | default value? | comments */ int argc //!< Number of arguments in argc. , char ** argv //!< Command line arguments. , char * envp [] //!< Environment variables. ) { /* SECTION: VARIABLES */ /* `const`? | type | pointer? | constp? | name | `[]`? | `=`? | default value? | `;` | comments */ const char * str = "Hello, world!" ; // Store a pointer to the string into str. /* SECTION: FUNCTIONS AND EXPRESSIONS */ /* receiving variable? | `=`? | function or expression | `;` | comments */ printf("%s\n", str) ; // Print 'hello world?'. /* SECTION: RETURNS */ /* `return` | value | `;` | comments */ return 0 ; // Exit gracefully. }
Edit: updated, since @PJH changed it out from under me.
This is C, not just any language! You forgot
in
andout
,
Also, how about going meta:/** @brief This is the main function of the program and will be executed first. * @brief @brief a brief explanation of the function's functionality * @param [in] argc Number of command line parameters passed. * @brief @param a parameter passed to the function * @param [in] argv List of command line arguments. * @brief @param a parameter passed to the function * @param [in] envp List of environment variables. * @brief @param a parameter passed to the function * @return 0 * @brief @return function output */
-
-
@dse said in Beautified That For You:
You forgot in and out,
Maybe he just likes Five Guys better?
Yeah, I know, more or less 'd.
-
@asdf said in Beautified That For You:
@dse said in Beautified That For You:
You forgot in and out,
Maybe he just likes Five Guys better?
Yeah, I know, more or less 'd.
Not my . Try looking over .
-
@PJH said in Beautified That For You:
Not enough comments.
I want to make a programming language where this code:
template<typename I> I timesTwo(I x) { return x * 2; } int main(int argc, char *argv[]) { printf("%d\n", timesTwo(5)); // prints 10 return 0; }
is equivalent to
// prints 10
-
@clatter I fixed it for you.
-
@darth_llama Variable width font with serifs for coding? Well played, you scum!
-
@darth_llama hey, you stole @aliceif 's ide settings!
-
@ben_lubar said in Beautified That For You:
I want to make a programming language where this code:
template<typename I> I timesTwo(I x) { return x * 2; } int main(int argc, char *argv[]) { printf("%d\n", timesTwo(5)); // prints 10 return 0; }
is equivalent to
// prints 10
Here's a compliant implementation that I've called
dontgo
:#!/usr/bin/env bash
Example usage and output:
$ dontgo foo.dg $ dontgo dontgo $ dontgo /usr/bin/gcc
-
@PJH said in Beautified That For You:
/** @brief This is the main function of the program and will be executed first * ... */ ...
This is technically not correct. C executes global initialization statements before
main()
.
-
@djls45 said in Beautified That For You:
@PJH said in Beautified That For You:
/** @brief This is the main function of the program and will be executed first * ... */ ...
This is technically not correct. C executes global initialization statements before
main()
.Actually, its the CPU that executes global initialization statements before
main
.
-
@anotherusername said in Beautified That For You:
@lucas1 that doesn't say anything about parentheses not being required.
I can think of only one situation in which parentheses around an arguments list are not required in Javascript, and that is defining a fat-arrow function that has exactly 1 argument. And you do still need parentheses around the arguments list to call it:
var fn = x => x * 2; alert(fn(5)); // alerts 10
No parentheses around an empty constructor parameter list.
const foo = new Foo;
Filed under: I enforce this with an
eslint
rule because I enjoy imposing my will on lesser developers.
-
@djls45 said in Beautified That For You:
C executes global initialization statements before main()
Not really.
Global initialisers in C (not C++) have to be compile-time constants or things that can be resolved by the linker. As such, they can't be executed before
main()
; they just exist in that initial state. The value is actually created as data in the appropriate section of the program; it isn't running any code as such to make them exist. The only code that really runs beforemain()
is in the C runtime itself, and you don't usually count that.But there's an out… Shared libraries can have an initialisation function that is called when the library is loaded (it's how C++ runs global constructors) so that can be used to run code before
main()
. It's tricky as heck though, and not something that C programs are really supposed to use all that much.