/dpt/ - Daily Programming Thread

What are you working on, /g?

Last thread:

Attached: dpt taocp.jpg (934x1000, 119K)

Other urls found in this thread:

webkit.org/code-style-guidelines/
google.github.io/styleguide/cppguide.html
twitter.com/NSFWRedditGif

First for profunctor optics

Attached: 1554592493814.jpg (612x816, 211K)

First for fuck anime.

I want a language that looks and feels like C, but has support for functional programming (e.g. map, currying). It should also have support for assume, like in Clang.
Is there such a language?

Rust, but the extra baggage may make it not worth it.

By "looks and feels like C" how far are you willing to deviate? Do you care about semantics or implementation more?

How do I prepare for an interview where I don't even know what programming language I'll be using?

Our company has junior positions for college students, and my coworker knows someone from the dev team (I'm not working as a programmer), so I asked him to ask him about it
So he came back from lunch with him and told me "Oh yeah, he said tomorrow at 8 you can go to his office for an interview" but he did not ask any details about the position.

So I landed an internship in a company writing C++ and have been trying
to use it as much as possible to really learn the language. However it
turns out they don't seem to care at all about writing things properly:
>long if else ... if else ... if else ... chains of comparing substrings
>passing std::string, std::vector and so on by copy
>spinning up dozens of threads for even simple functionality

I told them that they are basically doings things wrong, hoping to have
an intellecutal debate but the response has basically been
>whatever nerd get a life nothing is really performance critical lmao once you get a gf you stop caring
It has been very demotivating desu.

Trying to read from a random access file correctly.

Attached: 1543605844122.jpg (1274x1844, 269K)

No, that doesn't look and feel like C at all. It's C++ as envisioned by a Python developer.
Both. I want a low-level language that doesn't have lots of extra cruft. It could have a slightly more advanced type system than C, but only slightly - no object-orientation or similar crap where things don't act as expected. There should be a rough correspondence between a variable and a register.

>It should also have support for assume, like in Clang.
That is a very specific requirement. How comes?

that's kind of how it is, if it works nobody cares

Yeah, what can you do.
Do your own half right, and only care about the code of others if you are in the management or you are one of those code-review interns

Welcome to the industry.

Made a little thing that shows the window geometry during move/resize. It’s been a bit hard to find peace to hack at my new place, but I’ll get used to it.

Attached: 98F057C7-5CB6-48C4-AC98-73BB558E8B23.png (1920x1080, 1.06M)

They are paid by their employer to do one thing and one thing only: Deliver functionality.

Whether you pass a string by copy or reference literally does not matter unless you want to do it millions of times in a second.
By far the most important thing is to write code that is simple to understand and modify, because that's what will let you deliver more functionality quicker. Number of WTFs per minute is the only metric worth caring about.
Welcome to the real world kiddo.

Please, when you make a post like this, mention where you work, so it's easier to write a witty reply like "Typical Californians, or should I say, Cuckfornians, haha"

Thank you

make your own

Because I want to write efficient code. Asserts are nice as documentation, but they don't allow you to give the compiler any useful information.
#include
#include

#define ASSUME(...) __builtin_assume(__VA_ARGS__)

int f(x)
{
ASSUME(!(x & 1));
if (x & 1)
return x*2;
else
return x;
}

int main(void)
{
volatile int tmp = 0;
tmp = time(NULL);
tmp |= 1;
tmp --;
printf("%d\n", f(tmp));
return 0;
}

Here's an example of what I mean.

Why C++? What are you developing? Sounds like your company could be using an easier language.

>C++
>not an easy language
Come on now

>he hasn't read the standard

It's probably the hardest mainstream language.

This is accurate. It’s a phase that everyone goes through in their junior years though. “why doesn’t anyone care about performance and efficiency everyone is fucking retarded ffs”
It literally doesn’t matter

>stupidoverflow survey results
C O N D E S C E N D I N G

Attached: lmao.png (648x666, 25K)

You don't have to, unless you writing a compiler

I find it easier than Java's word-salad. The only thing I found more complicated in C++ was splitting string, everything else had shorter and cleaner syntax

So to have a working benchmark try this:

#include
#include
#include

volatile int useVar;

inline void test2Ref(const int& x, int* p){
useVar = x;
*p = 200;
useVar = x;
}

inline void test1Ref(const int& x, int* p){
test2Ref(x,p);
test2Ref(x,p);
useVar = x;
*p = 100;
useVar = x;
}

inline void test2Val(const int x, int* p){
useVar = x;
*p = 200;
useVar = x;
}

inline void test1Val(const int x, int* p){
test2Val(x,p);
test2Val(x,p);
useVar = x;
*p = 100;
useVar = x;
}

int main(int argc, const char * argv[]) {

{
auto start = std::chrono::steady_clock::now();
volatile int chooser = 0;
int y;
int x;
srand(time(0));
for(int i = 0; i

Oh, and the code now DOES the exact same thing in both cases - just the compiler does not know for sure if it does.

Javascript basically and unironically.

source

Attached: bonedrewfd.png (374x374, 91K)

women in tech are a joke
>javascript
>low-level

Attached: 1553214749353.png (800x600, 47K)

Why do you prefer to put your brace not on a new line?

>where things don't act as expected
Just because you don't know how they work, doesn't mean their bad.

LOOKS
and
FEELS LIKE

How do you tell genders apart?

When I compile these two versions, I get the exact same assembly output on both versions. Your time measurement is a fluke.

No, but I'm talking about for instance C++ objects and their myriad complexity and overhead. Or JavaScript's lazy/promise whatever.
Yes, JavaScript doesn't fulfill the requisite of feeling like C.

I imagine it's self-reported as part of the survey, or part of SO profile information.

if (male) { ... }

Please stop talking about subjects you aren't knowledgeable on.

Thank g-d this transphobic post got deleted

I don't want some high-level language, I thought this was apparent from the phrasing of the question.

>men actually answer questions
>females only engage in meta bickering

>relative use from women compared to men
use women/men for what? this chart makes no sense

Go is a "slightly higher level" C. It doesn't have much in the way of a type system though.

Dumb fucking sjw.
It's female if and only if vagina. Otherwise male.
Gutting your dick and turning it inside out doesn't make it a vagina btw.

This would not be difficult to do yourself, except for implementing all the optimizations that make C useful.

>I thought this was apparent from the phrasing of the question.
It is but it's pretty apparent that you're also clueless.

Alright my noogies, I request your wisdom in 2 matters.

First, which library/module/whatever should I use for wrangling PostgreSQL. Ease-of-use is my priority here, as I only intend to use it for tiny tasks, like storing browser extension data.

Second, I have searched several times, but I never did find a practical comparison between the various categories of database, i.e. what are the differences in terms of speed, difficulty of management, scale and so on, as opposed to the difference in the logic behind them like relational or document or whatever else.

Attached: c9a3b2b19fa8197fb098852d04c425f1ef62584874a342fe4de71de6c607350e.jpg (960x960, 133K)

>Alright my noogies, I request your wisdom in 2 matters.
If your first sentence is this cancerous then I'm going to save myself from reading the rest of your post and stop reading right here.

Go has garbage collection and bloated binaries, don't want.
I don't need a higher type system, it's just a nice bonus.
When I say higher type system, I mean something like hardtypedef float velocity that disables automatic casting float velocity, not some extremely advanced beast where a variable read might actually trigger a function call behind the scenes, etc.
Well, yes, GNU C has almost everything I want, but I'd want a more serious way to indicate pure functions and such. Probably, the only thing that'd be hard to optimize would be currying. But not impossible. Either you'd just pass in the curried argument behind the scenes and accept that you can't use it as an immediate anymore, or you'd have to start poking around in the code and the representation of immediates. Yuck.
Probably best is to generate a new function if the curried parameter is constant, and else just add a layer of indirection (e.g. you're just doing #define my_f(a,b,c,d,e) f(EXTRA, a, b, c, d, e))
Oh, I'd also like better macro support. Something like C++'s constexpr would be really cool.

Probably depends on how the compiler handles volatile...

Try this:
#include
#include
#include

volatile int useVar;

inline void test2Ref(const int& x, volatile int* p){
useVar = x;
*p = 200;
useVar = x;
}

inline void test1Ref(const int& x, volatile int* p){
test2Ref(x,p);
test2Ref(x,p);
useVar = x;
*p = 100;
useVar = x;
}

inline void test2Val(const int x, volatile int* p){
useVar = x;
*p = 200;
useVar = x;
}

inline void test1Val(const int x, volatile int* p){
test2Val(x,p);
test2Val(x,p);
useVar = x;
*p = 100;
useVar = x;
}

int main(int argc, const char * argv[]) {

{
auto start = std::chrono::steady_clock::now();
int y;
int x;
volatile int chooser = 0;
int* ptr = (int*)(((uint64_t)(&x) * chooser) + ((uint64_t)(&y) * (1-chooser)));
srand(time(0));
for(int i = 0; i

Look at the funny image he posted though.

>Alright my noogies, I request your wisdom in 2 matters.
stopped reading right here

Jai?

Also, just tested, remove the volatile keyword from the function arguments if you want. It does not change the results.

This one once again does something different for the two versions. In the testref functions, if &x == p (which it may be), then x changes value between assignments, which it doesn't for the testval functions.

No. &x != p because chooser is always 0.

Just the compiler does not know this. It's a volatile pointer. Imagine you had an array and you got some results from some threads and they very well might theoretically land on the same values - but they don't. And you know it.
Then the compiler still wouldn't know it.

Sounds cool, but no macros or strong typedefs.
I really like the C preprocessor.

JavaScript simply just rocks!

Attached: 1458066998812.gif (500x470, 1015K)

this gif is fantastic but it feels totally unrelated to the usual js rocks post

someone please post that haskell tiddie monster

just like any animepost

Ah, you're right.

>It is indeed faster in the test,
Which one? For me on x86_64, the val version is the faster one, as it should be.

Perhaps to make it more clear, you get the same results with this:

#include
#include
#include

volatile int useVar;

inline void test2Ref(const int& x, int* p){
useVar = x;
*p = 200;
useVar = x;
}

inline void test1Ref(const int& x, int* p){
test2Ref(x,p);
test2Ref(x,p);
useVar = x;
*p = 100;
useVar = x;
}

inline void test2Val(const int x, int* p){
useVar = x;
*p = 200;
useVar = x;
}

inline void test1Val(const int x, int* p){
test2Val(x,p);
test2Val(x,p);
useVar = x;
*p = 100;
useVar = x;
}

int main(int argc, const char * argv[]) {

{
auto start = std::chrono::steady_clock::now();
int x[2];
volatile int chooser = 0;
int* ptr = &x[chooser];
srand(time(0));
for(int i = 0; i

any animepost is unrelated to other animeposts?

Your best bet is to start a compiler project. Support c11 and add in constructs for whatever functional paradigms you're looking for. You'd probably want to Mapping, Currying, Function composition, and tail recursion.

Optimization and efficiency will be a bitch though.. Expect performance to be lower and a lot more framework will be required to run it at bare metal (Sorta like C++ but instead of object oriented you're functional).

>tfw no low level C with profunctor optics

Attached: 1542523277131.png (850x1200, 938K)

Got it sorta

first: what language are you using? idk what a noogle is
second: i guess this is between sql and nosql, the differences only really come into play when you're working at scale, for small apps just stick to sql because the db will have ACID properties which facilitate transactions, meaning you should never end up in an inconsistent state.
the problem with sql databases is they don't really cluster and therefore scale so you end up with a single database server with a terabyte of RAM and the fastest CPUs on the market when you need scale
nosql databases on the other hand like cassandra, mongodb, run on commodity hardware and you can (relatively) easily add nodes and scale to meet your demand, the trade off is they don't have ACID properties so transactions have to be managed at the application layer, that means coordinating your services and taking into account inconsistencies in that data since writing to one node (of the database cluster) will not always be immediately visible on another node

God I fucking love this haskell tiddie monster

This tittie monster sucks and anyone who likes her has shit taste.

samefag

samefag

in java how do i get the file path of a text file that is in the same directory as my class?

Sounds like something that you could google and find on PajeetOverflow.

they told me to ask here

new File("./mytextfile.txt").getCanonicalPath()?
something along those lines

if it's inside a jar file you need to use the resources apis (on the classloaders i think)

I thought a bit about it. I don't see why it'd be so hard.
>mapping
Trivial, but it'd have to overwrite the old values. A shame. memcpy them if you care about them.
You can do this in C with a macro already:
// i is an undeclared identifier, n can be anything
#define MAP(a, n, f, i) for (int (i) = 0; (i) < n; (i)++) (a)[(i)] = (f)((a)[(i)])
//n is a non-const integer lvalue whose evaluation confers no side effects
#define MAP(a, n, f) while (--(n)) (a)[(n)] = (f)((a)[(n)])

Obviously, don't, but implementation would be trivial.

On that note, I think you'd want some built-in struct (probably in a header) that carries a pointer and a size_t that can be passed around, and new string functions (as similar as possible) added to accommodate them. Ideally some construct that allows you to do it dynamically for each pointer type, although it might just be bloat.

>currying
I explained it. If the curryend is known at compile time, no problem (you'll get big binary size with heavy abuse, but just don't do that - it's like anything else), and if not, you can make it like a macro, meaning it can't be used as an immediate, but if it wasn't known at compile time that wouldn't have been possible anyway.

>function composition
Same exact thing as currying. If f and g are known at compile time, then you're just concatenating f and g's machine code and removing
mov eax, ...
ret
xor eax, eax

And then running some optimization. This is trivial, and again might lead to binary size bloat. But no big deal for a compiler.

And if not, we're just doing syntactic sugar.
#define h(x) f(g((x))

>tail recursion
This is the only one that gets hard. It becomes trivial if we add one of two constraints, though:
1) a function can only tail recurse itself
2) a function that intends to not deepen the stack yet still return f(x) must have a special attribute, like volatile or static
(this can't be automated, because sometimes we'd...

Attached: 1528384013881.jpg (3721x2470, 1.42M)

like to return a function result without needing the extra effort to keep the stack depth the same.
Then, the caller of such a function would get a function pointer passed as part of the return stack, and call that. This assumes it can't be optimized out, though.

I think 1) would be cleaner, but it could cause some trouble with function composition.

Another feature is dropping names. So you could do this:
#define identifier k912ujio12093
int identifier = 12;
#undef identifier

But the name k912ujio12093 still is there. If you could make it like an anonymous struct, that would mean you could make amalgamation builds vastly more pleasant by just dropping all internal identifiers. Perhaps what I'm thinking of would be better implemented as anonymous namespaces though.
Not too keen on namespaces, although it fulfills my requisite of "easy enough to implement at zero cost in the preprocessor". Possibly a kind of automatic name mangling, so you do this:
namespace name_
{
static int func(int x)
{
// ...
}
static int func2(int x)
{
// ...
}
}

Then you can invoke my_func and func2.

Man, I'm feeling hyped. On the other hand, making your own language is righer up there with rolling your own crypto.

Attached: 1538279408298.png (1200x1800, 1.3M)

The current location isn't the class location, is it?

what isn't? you said the text file and the class are in the same directory

Oops, forgot to backlink

oh wait, my bad, you're right, that's the working directory

Why do Jow Forums hates Java and C# so much if these are the languages the market is asking for?

You are actually right. It is faster. I had shitty optimization options enabled.

Well, it honestly does not matter anymore if I find a case where const int& is faster. Because I found this:

volatile int useVar;

inline void test1Ref(const int& x, int* p){
*p = 100;
useVar = x;
}

inline void test1Val(const int x, int* p){
*p = 100;
useVar = x;
}

int main(int argc, const char * argv[]) {

{
auto start = std::chrono::steady_clock::now();
int x[2];
x[0] = 50;
volatile int chooser = 1;
int* ptr = &x[chooser];
srand(time(0));
for(long long i = 0; i

Those languages suck to use. Just try them yourself.

Why are you excluding Jow Forums from "the market"?

How the fuck did you jump to that conclusion?

>Jow Forums
>market for anything but logo designers

Hmm, I like being able to fit more code on screen, I guess :)

what about Horstmann?
if (1 == 1)
{ asd();
asd();
}

I like WebKit style with snake_case instead of camelCase, personally
webkit.org/code-style-guidelines/

...

ok fags is luajit deprecated? what should i use?

Which codestyle do you prefer the most?
For me, it's google styled code.

google.github.io/styleguide/cppguide.html

4ch is almost entirely comprised of retards

Well-typed programs in my language will be invulnerable to side-channel attacks.

awful

nice