What are the most niche language features you have come across

What are the most niche language features you have come across.

C/C++ Union is up there for me. I have only had one case where it was useful for providing a weak polymorphic interface.

Attached: union.jpg (248x175, 8K)

Other urls found in this thread:

github.com/dolphin-emu/dolphin/blob/master/Source/Core/Common/IniFile.cpp
hamberg.no/erlend/posts/2013-02-18-static-array-indices.html
github.com/torvalds/linux
kernel.org/doc/html/v4.10/process/coding-style.html
barrgroup.com/Embedded-Systems/Books/Embedded-C-Coding-Standard
gotofail.com/
anyforums.com/
twitter.com/NSFWRedditImage

>union
>niche
It's pretty common. But by my standard I can't think of anything niche.
>C/C++
They're entirely different between the two. C++ doesn't allow 'type punning'. Which drastically changes the utility of this feature.

C trigraphs are way up there for me. Absolutely ass-backwards.
Unions have their place and they're really beautifully useful to aid in obfuscation, too.

JS 'with' is pretty niche. It would be nice in certain OO situations, but it's bad practice to even use it unfortunately. Something about security problems.

Creating your own datatypes in MATLAB, I still have to find any official documentation for it's existence.
At first this was some kind of oral knowledge, as the only reference I had was my professor mentioning how to do it.

>C trigraphs are way up there for me. Absolutely ass-backwards.
Didn't those exist because keyboards in some regions did not map those characters to any key.

C doesn't allow type punning either. I think it has relaxed rules regarding structs with common initial sequences but otherwise it's still illegal to dereference an int* cast to a float*.

Template template arguments in C++.

That's not the same thing as the special case of union 'type punning'.

union Float{
float num;
struct{
bool sign : 1;
int exponent : 8;
int mantissa : 23;
} parts;
};

I think you mean this.
union Float
{
float as_float;
struct { uint32_t sign : 1, exponent : 8, mantissa : 23; };
};

Here, lisbstdc++'s std::string short string optimisation. Uses unions.
namespace std _GLIBCXX_VISIBILITY(default)

{

_GLIBCXX_BEGIN_NAMESPACE_VERSION


#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wabi-tag"

// Redefine __sso_string so that we can define and export its members

// in terms of the SSO std::string.

struct __sso_string

{

struct __str

{

const char* _M_p;

size_t _M_string_length;

char _M_local_buf[16];

};


union {

__str _M_s;

char _M_bytes[sizeof(_M_s)];

std::string _M_str;

};


__sso_string();

__sso_string(const std::string& s);

__sso_string(const char*, size_t n);

__sso_string(const __sso_string&) noexcept;

__sso_string& operator=(const __sso_string&) noexcept;

~__sso_string();

__sso_string(__sso_string&&) noexcept;

__sso_string& operator=(__sso_string&&) noexcept;

};

By the way, you should use std::variant, much safer and more verbose.

I didn't even know about that, thanks. For me it would have to be generators in JS. Higher order functions or objects are more flexible, I don't know why they were added.

We use unions all the time in embedded development to express register settings though typically it has to do with signals that are less than a byte wide.

This mess of underscores is what makes STL completely unreadable.

>less than a byte
You sure it's not bit fields?

It's not publicly interfaceable code, you're not supposed to read it.

That's necessary to avoid leaking names. Identifiers with double underscores are explicitly reserved for the implementation.
Modules will fix this.

I really have to think hard of how I could possibly use this in my program...

Then again I have memory leaks galore, so I suck.

Attached: 1544395397139s.jpg (125x70, 1K)

Both of you should fucking die with those 4 spaced indentations.

8 spaced means you wont end up with pyramids of conditionals.

Attached: 1534473716737.jpg (646x914, 144K)

Except that from time to time you need to know how it works under the hood.

no u

I used this shit in flex/bison to make a simple compiler

Unions (and variants) really have no good usecases. They're a morbid form of dynamic typing and they break the fundamentals of C/C++.
They should only be used by experienced pros.
>from time to time
The only reason to know that is if you're reimplementing the std::containers for fun/exercise. You're not supposed to know how or why they work, only how to correctly interface them.

Its only for saving memory as far as I can tell.
The java generation will obviously not give a fuck about such things, but it would be important.

To me, I could probably switch some of my enumerator oriented code... to a union, but... I dont think it would make things more readable, which is more important to me.

Attached: 1503347954077.jpg (680x684, 42K)

>variants are dynamic typing
You really have no idea what the fuck you're talking about. Algebraic types are about as far from dynamic typing as it gets.

If you don't know a type compile-time, it ain't static typing. You want some unrealistic arbitrary code, go write python.
It's like I can just tell you're a first year student. Memory is uninteresting. ISO C++ makes no mention of "cache" or "register" keywords (register exists but has null effect). Anything beyond working code is opti/pessimisation.

The type is a sum of types, just like a tuple is a product of types. You don't understand anything.

I saw a nice pattern for packing and unpacking network packets using a union of pointers recently.

>pays someone to teach him how to program
found the java fag

Attached: 1540380903946.jpg (800x723, 53K)

>sum of types
>product of types
CPUs only understand composition of types aka offsetof(). Go back to Haskell.
>reinventing the wheel over and over until it clicks
Autism.

>reinventing the wheel over and over until it clicks
wdym?

Having somebody just spill the knowledge and philosophy on you is better than gradually learning. It's all been discovered already, just pick up where others left off.

If you only care about what the CPU knows then you write assembly. We don't write assembly because dev time is more valuable than computer time. C++ exists to give us abstractions and sum types are a cheap and useful abstraction.

>C++
C++ gives you STL and the tools to extend it. That's it.

That's my point, C++ gives you efficient abstractions and the tools to write your own.

Okay so where amidst templates do unions come into play?

I'm not sure I understand your question. You can combine templates with unions to form variants, which are a cheap and useful abstraction. Isn't that the point of this conversation?

The conversation is on runtime type behaviour being evil.

No, because somebody can be anybody, and teachers dont tend to be people of virtue very often. Unless you really know that the guy is hot shit when it comes to programming, learning from Mr WindowsProgrammingEnvironment is a bad start.

If you want to learn well on your own, you do three things:
- Contribute to competent open source projects, so your code will be reviewed.
- Adopt the style and principles of the most well rounded projects, such as the Linux Kernel.
- Read the fucking manual, and read it well.

The only thing you need to be disciplined on, is finding out what you don't know.

Variants lack the inefficiency, unpredictability and lack of semantic information that actual type erasure does.
The type of a variant will inform you what its possible values are, and the interface of the variant will ensure you only perform valid operations on it. That's a far cry from actual dynamic typing.

Guaranteed any teacher with a bachelor and masters is better than any and all youtube celebrities.
>contribute
Maximum code reading, minimum code writing. I am not wasting a year or two of my life to understand Linux well enough to contribute.
>style and principles
Minimum algorithms, maximum bike shedding.
>Read the fucking manual
I guess that's good once you pass the basics of the language, else you're just memorising unnecessary info.

I see no reason learning on your own is any better than having knowledge dumped on you.

So correct me if I'm wrong but a variant can hold different types at different times. How is that safe again?

The set of types which a variant can hold is constrained. A std::variant only holds either a Foo or a Bar. With void* or std::any, you can't tell that by looking at it.

Additionally, the value inside a std::variant is typically accessed by pattern matching. That means you do something like this.
// this code can be cleaned up with templates but I want to keep it simple

std::variant my_variant;

struct
{
auto operator()(Foo foo)
{
// this function runs if the variant contains a Foo
}
auto operator()(Bar bar)
{
// this function runs if the variant contains a Bar
}
}
my_functor;

visit(my_variant, my_functor);
This way you won't accidentally call the wrong function on the wrong type. You can't - unlike dynamic typing.

>youtube
TF are you talking about? No one mentioned youtube... Although I would agree that learning programming from TheNewBoston is not the best. But on the opposite end, you can just listen to a Harvard or Princeton Class on programming, all on youtube.

>I develop in notepad++. Vim takes too long to learn
Glad I dont work with you.

>not putting curly braces on if statements never hurt anyone. You just got to code
bahumbug

>I guess reading the manual is okay...
Its really fucking important long term.

>I see no reason learning on your own is any better than having knowledge dumped on you.

Two reasons:
1) You are purchasing cognitive dissonance, making it harder for you to drop bad habits.
2) Costs tons of money.

Attached: 1508997862012.png (632x852, 47K)

>8 spaced means you wont end up with pyramids of conditionals.
Or you could, you know, have some self-control. Also, just because they type code into the Jow Forums reply box with 4-space indenation doesn't mean that's how they normally write code.

That honestly looks like something you do under dev time constraints, a hack to outsmart the C++ type system.
>cognitive dissonance
?? You get to talk to young and energetic people and learn together. There's no equivalent on the internet, just anonymous buffoons recommending C for everything.
>tons of money
Ohhh you're American.

You wot m8? Yeah, you might not see them much in typical desktop application programming, but they're extremely common in any kind of embedded development and pretty much anything else sufficiently low level.

Compiler attributes.

You have not been programming for very long.

It forces self control. People who rely on willpower always fail, and only faggots like you pretend that it can be otherwise.

Indentation is meant for one thing: To clearly deliniate where blocks of code begins and ends. If you are running out of columns, reconsider your life as a programmer.

Thats it. Why anyone would use 4, or 2, or 1 can only be summed up as being seriously brain damaged.

Who in their right mind would for example want to contribute to code written like this:

github.com/dolphin-emu/dolphin/blob/master/Source/Core/Common/IniFile.cpp

Attached: 1512875106620.jpg (960x960, 73K)

I genuinely do not see a problem with that code, it's very nicely indented.
>same column == same thing
That's it, stop being autistic.

I disagree. If I'm working with a variant, I know more about what value it contains than if I used e.g. a pointer to a base class. I also get cheaper polymorphism (one cmp vs a stable lookup) and easy value semantics.

Okay listen here Harbinder.

What happens when you or pajeet decide to comment out line 257?

Attached: 591de7c884835aa33e9adbd5cf045bd986f6dd477cf2835249685b8340324f64.jpg (855x534, 733K)

>People who rely on willpower always fail
I bet you're fat.

>Why anyone would use 4, or 2, or 1
Maybe because they are typing it into the Jow Forums reply box where they'd have to press space a billion times instead of pressing tab twice?

>posting code with 2-space indentation as an argument against 4-space indentation
Nice strawman. Also, what is %s/ / /g?

I add an extra semicolon to show that the if body intentionally does nothing and that I did not comment out the line on accident?
Who comments out lines arbitrarily anyway? Sheesh

>I bet you're fat.
You wish you were as white as me.

>uses quick reply to write code
Not my fault people are gay.

>%s
recurring replace applied to a whole file.
Too bad it doesnt work in a web browser you stupid fuck.

Code indentation preferences were solved by tabs.
Like 4 width? no problem
Like 8 width? no problem
etc.
How anyone can justify using hard whitespace for code is beyond me.
Want it for ascii art? Fine.
Comment alignment? Whatever.
Code? Stop this.
Waste of time, strokes, and bytes.

Now that union is the accepted way to override strict aliasing, it's not exactly niche any more. Something like this though: hamberg.no/erlend/posts/2013-02-18-static-array-indices.html

I dislike this feature, I find "array" parameters in C to be misleading.

>You wish you were as white as me.
So you're fat. Also,
> being a white western male
> implying that's anything of a privilege
You'll be bullied to death just because you exist.

>criticizes people for typing 5 lines of code meant to be posted online straight into the web browser instead of firing up a text editor
>uses a web browser to inspect hundreds of lines of code

Yeah who Pajeet?

>Clearly, people who take preventative measures to avoid bugs are just undisciplined.
Please, go back to phone scamming. You were far more useful there.

Attached: pajeet-code.jpg (1038x576, 87K)

>You wish you were as white as me.
You're not white, you're pale. You look and probably are sick from staying at home all day.
Go out to restore your natural skin colour.
I'm not the one working with people who arbitrarily comment out lines of code. Fucking retard.

memory

There is also the question, why would I want to program under someone who is braindamaged enough to indent in two spaces so he can addequetely nest loops and conditionals within themselves?

Based.
You should rarely ever go beyond 3 levels of indentation, maybe 4 at most.
Staying true to this rule has led to cleaner code than any meme pattern or other dumb advice I've ever heard.

Attached: 1526236073731.jpg (975x1357, 522K)

Agreed. The code you linked looks cleaner than it actually is because of the very small indentation.
Indentation should be nice and large.
8-character wide tab indentations leave no excuse and don't hide anything.
Good code looks good with them, shit code looks shit with them.

Almost that attitude alone would make me hire you.
Even in the worst case scenario, your code would still be readable and easy to correct.

Attached: 1541555145039.jpg (500x390, 129K)

True, the way that if it decays to a pointer if you pass an '''array''', but doesn't if you pass a pointer to an array is especially retarded. However, none of that is particularly niche; tons of real world C code relies on this behavior. This is about using static in them like int myfunc(char anarray[static 5]);, which is something I've never seen in the wild.

I used to think o too, and I mostly do this too (especially by negating ifs), but sometimes manually inlining your code works wonders.

You dont get it. Its not about commenting out lines

Its about not bracing if statements.

You are so crazy, that rather than adding

if (foo){}

you would rather

if (foo);

That is insane.

Attached: 1539639928842.jpg (1011x1000, 153K)

Can you send me a demo of what the fuck you're talking about?
>if (foo);
correction,
if (foo)
;
It sticks out like a sore thumb, nice and noticeable. I mean, you can add an assembly block with NOOP in it or something if you want.

>Can you send me a demo of what the fuck you're talking about?
What the hell don't you understand?
Some people think it's better to not have too many levels of indentation in the code.

if (foo)
;

Did you ever stop to consider that the tool used for merging code might not see things the way you do?

if (foo) {
// bar();
}


is safe from both user error, and from merge confusion.

The fact that you do not understand that, and completely missed the apple ssl reference, shows that you simply do not have what it takes to be a good programmer.

Aren't you the user claiming to be white?
Bracing single line if's is only necessary if you're working with people who don't understand the language.
Disallowing features of the language is stupid. If you can't trust a group of humans to deal with this detail then you shouldn't be trusting them with C at all.

I don't watch apple ssl or any other conferences than cppcon.
>confusion
Hmm. No, having commented out lines is confusion.
>a good programmer
A programmer good if and only if he has a vast knowledge of algorithms and how to apply them. Beautiful code is not fast code.
Actually, beautiful code has to run slowly.

If you're going to move the goalpost from human to tool then your argument falls apart. We have tools to test functionality and automated review for a reason.

>use shitty language that requires manual cleanup code all over the place
>have no support for running block-level cleanup code automatically like all merely 30 year old languages do
>result is awful if() ladders everywhere
>claim that deeply nested indentation is a sign of poor programmers rather than the obvious language problem it is
>almost definitely a Cnile brainlet who thinks he's being '''smart''' by using gotos instead
What's not to understand?

I'm a C++ programmer and am literally above and beyond those issues.

here's a use i like

Attached: file.png (247x310, 9K)

>Can you send me a demo of what the fuck you're talking about?
What do you mean? You want an example of code that consistently follows this rule?

In that case, you have to look no further than Linux. The GitHub mirror page is correctly formatted and uses the right size for tabs: github.com/torvalds/linux . Big ass 8-character wide tab indentations, and rarely over 3-4 levels of indentation.

It's even in the kernel style guidelines themselves: kernel.org/doc/html/v4.10/process/coding-style.html

Of course, that's fairly easy to achieve in C, which doesn't have a lot of features, but it's perfectly doable in other languages such as C++, Java, JavaScript and Python as well, in my experience, if you're disciplined (you can allow an extra level if you're in a try-catch block).

Limiting your indentation is highly beneficial to code quality. I dare say it's the single most beneficial thing you can do for your code. And by using large indentations, you are forcing yourself to use less indentation levels.
It's like Ulysses tying himself to the ship to hear the sirens.

It's crazy that such fundamental advice is missing from the book """Clean""" Code. Instead, we have meme advice repeated over and over.
Keep it flat, keep it simple.

expound

>tfw don't have mental breakdowns over syntax

Attached: 1505308645525.png (400x400, 143K)

Okay now THIS is epic

Attached: Untitled.png (1059x1043, 80K)

>claim that deeply nested indentation is a sign of poor programmers rather than the obvious language problem it is
>claim that deeply nested indentation is a sign of poor programmers rather than the obvious language problem it is
Deeply nested indentation more often than not *is* a sign of bad programmer skill, but it's also true that some languages encourage more nesting than others.

I'm not a fan of C, but it's not nearly among the languages which need the most indentation.
Have you seen fucking Scala? The official style guides literally encourage TWO character indentations due to how deep it gets even for simple programs.
Scala is a mess.

In fact, it's easier to write less indented code in C due to not having classes, try-catch blocks and the like. Deeply nested C code is even shitter in comparison to most other languages.

>Hmm. No, having commented out lines is confusion.
Sometimes, but it is generally fine if you have descriptive code. But in principle you are right, commenting should be placed in places to clear up what obtuse code is performing... However, something like this:
if (foo) {
doBar(); // This does bar.
}

is unneccessary. Also, commenting should be avoided if possible because the only thing worse than no commenting, is commenting that is no longer accurate:

>shouldnt be trusting people
who do not practice good style. I dont care if you are stephen hawkins or linus torvalds; code clearly, and put fucking braces on all your conditionals.

That's fine and you sound like you're getting ready for your first internship with this bike shedding. Keep up the good spirit.

barrgroup.com/Embedded-Systems/Books/Embedded-C-Coding-Standard
>Rule 1.3.a
>Braces shall always surround the blocks of code (a.k.a., compound statements), following if, else, switch, while, do, and for statements; single statements and empty statements following these keywords shall also always be surrounded by braces.

If apple followed this, then this site:

gotofail.com/

would not exist, you greasy knob.

Meh it quickly got fixed and no real damage was done.

For me it's pointers in c because I'm a Web dev and I'm too brainlete to do it someone help

I don't see how you can fail to understand pointers, reference semantics with mutability like python is harder to grok

>In my world, easily preventable bugs that cause massive disturbance on critical platforms, wasting tens of thousands of hours of programmers world wide, are okay if they are fixed "quickly", you know, no more than a year at most.

Attached: 1540168794643.png (800x668, 135K)

Yeah, give or take. The time they spent not sperging over syntax, they spent fixing other bugs that never came to be.

Yeah you eventually get to the point where you suprise yourself and say,

>Oh damn! Thank god pointers exist, or else this would be really fucking hard.

>Thank god pointers exist, or else this would be really fucking hard.
Where by this I mean crashing this app with no survivors.

Right, because this code takes no time at all to read:

void foo()
{
forever
{
if (reddit)
continue;

while(bar)
{
if(opIsGay)
;
pooInStreet(true);
}
for (int i=0; i

Attached: 1537410441573.png (629x454, 448K)

Attached: 1512119352916.png (440x430, 381K)

Yes

80 column, 8 space fags should be shot.