Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Necc0
Jun 30, 2005

by exmarx
Broken Cake
 

Only registered members can see post attachments!

Adbot
ADBOT LOVES YOU

Shaggar
Apr 26, 2006

Necc0 posted:

BRACKET ALL IF STATEMENTS YOU loving COWBOY CODERS gently caress gently caress FHDUOFDGF

all man style, hard tabs only

Necc0
Jun 30, 2005

by exmarx
Broken Cake

Shaggar posted:

all man style, hard tabs only

hey the 80s called they want their limited hard drive capacity back

Necc0
Jun 30, 2005

by exmarx
Broken Cake
allman is good tho

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

Shaggar posted:

all man style, hard tabs only

fritz
Jul 26, 2003

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror

Necc0 posted:

BRACKET ALL IF STATEMENTS YOU loving COWBOY CODERS gently caress gently caress FHDUOFDGF

a. ITYM "braces". [] are brackets, {} are braces

b. you don't need actually need the braces if the thing inside the if is only one line. that way you can save a little bit of space and it looks nicer

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Tiny Bug Child posted:

a. ITYM "braces". [] are brackets, {} are braces

b. you don't need actually need the braces if the thing inside the if is only one line. that way you can save a little bit of space and it looks nicer

okay man, i've stood with you every time you've defended php, or at least i have loléd on the sidelines at your wicked ownages


but you've gone too far now, man.

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Necc0 posted:

BRACKET ALL IF STATEMENTS YOU loving COWBOY CODERS gently caress gently caress FHDUOFDGF

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Tiny Bug Child posted:

a. ITYM "braces". [] are brackets, {} are braces

in england they call parentheses brackets

Tiny Bug Child posted:

b. you don't need actually need the braces if the thing inside the if is only one line. that way you can save a little bit of space and it looks nicer

i used to think you were cool :(

triple sulk
Sep 17, 2014



pls come 2 the all man's hard tabs club thread if u feel that way, which is the superior one.

also i agree that if statements need braces. it is a true sign of a distinguished gentleman.

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

triple sulk posted:

pls come 2 the all man's hard tabs club thread if u feel that way, which is the superior one.

how do you make "less" show tabs as four spaces instead of eight?

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror

Wheany posted:

okay man, i've stood with you every time you've defended php, or at least i have loléd on the sidelines at your wicked ownages

so i have this new intern who's always asking me questions and trying to learn from me and stuff. also, today is our company "free tech day" where the tech crew gets to dick around with something cool as long as it has some possible business benefit or you learn something (i'm brushing up on R)

one of the PMs was like hey i'm gonna teach myself a bit of coding what should i learn. one of the dudes who was over here from the foreign office was like, oh try python, it's pretty easy for a beginner and it'll teach you good coding habits.

the new intern, without any prompting from me, immediately said "oh that's not true you can write bad code in any language and PHP is actually really good now days"

i've taught him so well

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

VikingofRock posted:

Hell yeah, this sounds awesome. Is there any chance you could post the source somewhere? I'd love to read through it.

I'll spare you, honestly. it's pre-C++11 code and I didn't make it fully generic, like T can't be a reference type for example (this reminds me I started writing a specialization for Optional<void> but realized that's just an overengineered bool). also I didn't bother with the trick where instead of operator bool you implement operator <member pointer>, which converts explicitly to bool but not implicitly (in C++11 you'd just use explicit operator bool). it's just not publishable material

I'll share one of its building blocks, Lazy<T>, to give you an idea of how terrible pre-C++11 is that it is even necessary. I originally wrote it to statically allocate singletons without running their constructors until first use (... in C++11 you'd just use a local static variable :sigh:), but then it proved useful to implement Optional<T> and discriminated unions (because in pre-C++11 - :sigh: - you can't have union members with non-trivial constructors, ever), which are the basis of ValueOrError<T>

C++ code:
// Lazy<T>, yospos edition, rewritten from memory

#include <new> // for placement new

template<class T>
class Lazy {
public:
	typedef T element_type; // not in the original code but I'm feeling fancy for the 'pos

private: // yeah I put the data members at the top, bite me stroustrup
	// can do aligned/alignof natively in C++11 without compiler extensions
	char m_data[sizeof(element_type)] __attribute__((__aligned__(__alignof__(element_type))));

public:
	// note no constructors so we can use the class as a union member

	element_type *construct() {
		return new(m_data) element_type();
	}

	// imperfect forwarding, arguments are passed by value. of course C++ has perfect forwarding. of course
	template<class Arg1>
	element_type *construct(Arg1 a1) {
		return new(m_data) element_type(a1);
	}

	// ... 3 more overloads of construct, because no variadic templates. I keep adding more as I need them

	void destroy() {
		// unconditional because we have no state, because we have no constructors. use Optional<T> if you want safety
		get()->~element_type();
	}

	element_type *get() {
		void *const addr = m_data; // if I cast without this intermediate step, compiler moans about aliasing violation
		return static_cast<element_type *>(addr);
	}

	const element_type *get() const {
		const void *const addr = m_data;
		return static_cast<const element_type *>(addr);
	}

	// some operators to use Lazy<T> as a pseudo-pointer

	element_type *operator->() {
		return get();
	}

	const element_type *operator->() const {
		return get();
	}

	element_type& operator*() {
		return *get();
	}

	const element_type& operator*() const {
		return *get();
	}
};
so, not only C++11 makes it basically useless, but without C++11 we can't even implement it properly. it doesn't mean it isn't useful

VikingofRock posted:

Jesus, why do they need so many header files?

because old C++ compilers, old C++ versions, etc.

VikingofRock posted:

Personally I think the worst part about boost::optional is its implicit conversion to bool, which makes optional<anything_that_is_also_convertible_to_bool> a bad idea.

my Optional<T> has implicit conversion to bool too, because you can then use a handle-like pattern like this:

C++ code:
if (const Optional<Turd>& turd = stealTurd()) {
	eat(turd);
}
else {
	std::cout << "out of turds!" << std::endl;
}
I used to have implicit conversion to T too but that proved to be a bad idea :classiclol:

VikingofRock posted:

In the past it has caused me some bugs like this.

or maybe the worst is that int has a conversion to bool, hmmm!

Slurps Mad Rips posted:

The implicit bool conversion is super stupid and I'm glad we have explicit operator bool which is only implicit in a boolean context :v:

boost::optional is actually explicitly convertible to bool, because its operator bool actually is operator somepointertomember, which doesn't implicitly convert to anything, not just bool

Necc0
Jun 30, 2005

by exmarx
Broken Cake

Tiny Bug Child posted:

b. you don't need actually need the braces if the thing inside the if is only one line. that way you can save a little bit of space and it looks nicer

:vd:

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Tiny Bug Child posted:

so i have this new intern who's always asking me questions and trying to learn from me and stuff. also, today is our company "free tech day" where the tech crew gets to dick around with something cool as long as it has some possible business benefit or you learn something (i'm brushing up on R)

one of the PMs was like hey i'm gonna teach myself a bit of coding what should i learn. one of the dudes who was over here from the foreign office was like, oh try python, it's pretty easy for a beginner and it'll teach you good coding habits.

the new intern, without any prompting from me, immediately said "oh that's not true you can write bad code in any language and PHP is actually really good now days"

i've taught him so well

securing the tbc dynasty

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

as I mentioned, this doesn't work if T is a reference. it completely breaks because you can't make a pointer to a reference (reference to reference collapses to just reference though). so we can cheat and store a pointer instead. let's specialize for Lazy<T&> then:

C++ code:
template<typename T>
class Lazy<T&> {
public:
	typedef T& element_type;
	typedef T *pointer_type;

private:
	// see, no need to use an untyped buffer
	pointer_type m_data;

public:
	// no need to overload construct either, you can only initialize a reference with another reference
	template<typename U>
	pointer_type construct(U& a) {
		m_data = &a;
		return m_data;
	}

	// don't bother destroying the pointer
	void destroy() {}

	// can't return a pointer to a reference, return a pointer to the object instead
	pointer_type get() const {
		return m_data;
	}

	// const everything because references are constant by definition
	element_type operator*() const {
		return *get();
	}
	
	pointer_type operator->() const {
		return get();
	}
};
yeah I don't know if this works, really. the semantics are subtly different from the generic Lazy<T> and you could get caught in traps. not terribly useful, either, you can just use a naked pointer instead, can't you? but as a C++ programmer you have a moral obligation to orthogonality, even if it means drowning in a sewer of tag dispatch, trait classes and template specializations

e: oh yeah, I should use SFINAE to make construct<U> disappear if U* isn't implicitly convertible to pointer_type, but :effort:

e: whoopsie, copy-paste embarrassment

hackbunny fucked around with this message at 21:28 on Oct 2, 2015

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
If you aren't forced to work with legacy tools, you can use std::experimental::optional

I think there's a standard variant type on the way too.

compuserved
Mar 20, 2006

Nap Ghost

prefect posted:

how do you make "less" show tabs as four spaces instead of eight?

i think it's "less -x4"

hth, my friend. god bless

VikingofRock
Aug 24, 2008




hackbunny posted:

Optional code

This is pretty neat. Now I'm tempted to go write my own Result/Either type for use in error handling...

Soricidus
Oct 21, 2010
freedom-hating statist shill

compuserved posted:

i think it's "less -x4"

hth, my friend. god bless

oh my god i never even thought to look for this

i think i love you

VikingofRock
Aug 24, 2008




The hardest part about learning the command line is figuring out that the tools/options you want already exist instead of constantly reinventing the wheel with grep/awk/sed. I've been using the command line fairly heavily for ~6 years now (maybe more) and somehow I only recently found out about column and comm. My next goal is to figure out how to print all the lines in one file that are not present in another file, which I'm sure is similarly easy but I haven't had time to look into it yet.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Ralith posted:

I think there's a standard variant type on the way too.
the latest mailing had three different proposals with different unpleasant tradeoffs

compuserved
Mar 20, 2006

Nap Ghost

VikingofRock posted:

My next goal is to figure out how to print all the lines in one file that are not present in another file, which I'm sure is similarly easy but I haven't had time to look into it yet.

snack exchange: Is there a tool to get the lines in one file that are not in another?

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

holy poo poo @ those people writing awk scripts and crazy poo poo

just use comm you morons

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

:stonk:

Sapozhnik
Jan 2, 2005

Nap Ghost

Sweeper posted:

holy poo poo @ those people writing awk scripts and crazy poo poo

just use comm you morons

even after like 15 years of being a linux nerd there's weird poo poo in coreutils that i've never heard of before today

Bloody
Mar 3, 2013

https://en.m.wikipedia.org/wiki/GNU_Core_Utilities

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Shaggar posted:

all man style, hard tabs only

idgaf about tabs vs spaces but woe betide you if you don't use allman style

comedyblissoption
Mar 15, 2006

have you tried using a linter program to enforce bracing

allowing programmers to choose their own indentation and block formatting has only caused the worst form of bikeshedding

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

comedyblissoption posted:

have you tried using a linter program to enforce bracing

allowing programmers to choose their own indentation and block formatting has only caused the worst form of bikeshedding

how do you enforce using a linter for bracing without a really long bikeshedding discussion about bracing

VikingofRock
Aug 24, 2008




Sweeper posted:

holy poo poo @ those people writing awk scripts and crazy poo poo

just use comm you morons

Yeah that's exactly what I was talking about! All these people are trying to use complicated awk scripts / uncommon grep options, but the answer is apparently just comm -23. My guess is that most of these people don't know that comm exists (or like me they never bothered to read the comm man page), hence the workarounds.

Workaday Wizard
Oct 23, 2009

by Pragmatica

VikingofRock posted:

Yeah that's exactly what I was talking about! All these people are trying to use complicated awk scripts / uncommon grep options, but the answer is apparently just comm -23. My guess is that most of these people don't know that comm exists (or like me they never bothered to read the comm man page), hence the workarounds.

i didnt know about comm before this thread. the name sounds totally like a networkign thing.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



if{ check$ !

Brain Candy
May 18, 2006

MALE SHOEGAZE posted:

how do you enforce using a linter for bracing without a really long bikeshedding discussion about bracing

"i have picked this, does anybody have a super strong objection? <some people whine, but most people don't give a poo poo> looks like we've got a quorum. okay, now let's talk about commit hooks"

- a thing a good lead does

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



i will fire anybody who fucks up the indentation or brace style

no warning, out the door.

Brain Candy
May 18, 2006

same, except those commits get rejected by the linter

Soricidus
Oct 21, 2010
freedom-hating statist shill

Snapchat A Titty posted:

i will fire anybody who fucks up the indentation or brace style

no warning, out the door.

im glad i live in a civilised country where this kind of thing would be illegal as gently caress

sarehu
Apr 20, 2007

(call/cc call/cc)
I'm glad I live in a civilized country without mass youth unemployment.

Adbot
ADBOT LOVES YOU

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Soricidus posted:

im glad i live in a civilised country where this kind of thing would be illegal as gently caress

you get 3+ months pay as per the law but youre done. you didnt abide by the terms, literally the only terms.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply