/dpt/ - Daily Programming Thread

Old thread: What are you working on, Sup Forums?

Not anything object oriented, it's garbage.

-Sup Forums

Employed Haskell programmer reporting in

I hate C with a fiery passion. Besides Rust and Go what language should I learn?

self-employed with no revenue does not count

Definitely C.

If you hate C then you'll loathe C++

C stands for cancer

C stands for communism

Made rock paper scissors in c#. What are some other interesting and small programming projects I can do?

Unemployed Haskell programmer reporting in

Are you me?

He literally just said that

C# is comfy

How is taking the microcock "comfy"?

sure, if by "comfy" you mean "trash"

C# is comfy like a horse-drawn carriage.

i'm trying to get into algorithms and data structures so i'm reading Grokking Algorithms

i don't want to be that guy who got invited to a google interview and couldn't traverse a binary tree

vb.net

Why do you define yourself as a programmer if you aren't even employed?

Take your shitty """languages""" to plebbit

Because I program. which means I am a programmer aka one who programs.

I'm the one who programs

"Programming" is not a profession.
To be called a programmer, all you need to do is program.

Rust or Bust

So my mum is a programmer too, because she programs the oven sometimes?

A programmer is someone who programs

A programmer, computer programmer, developer, dev, coder, or software engineer is a person who writes computer software.

Not programming

>dev, coder,
cringed pretty hard.

Modern C++ is quite comfy desu. It lets you enjoy the benefits of C (proximity to the metal and mainstreamness/number of jobs) while avoiding many of the rough edges that make C so annoying to get anything done in.

I would love to see Rust become more mainstream though.

>programs the oven
Who the hell would say "program the oven"?

>proximity to the metal
>quite comfy desu

>>>/9gag/

Gas chamber operators.

Should I use Visual Studio or a text editor for C++?

You should no be writing C++ at all.

not*

C++ is meant to be done on UNIX lad

whats the easiest way of writing a parser for stuff like JSON? (i.e. many tokens wrapped around each other

>Should I use Visual Studio
That's never a right answer.

C++ is literally the polar opposite of the Unix philosophy.
>>Do one thing and do it well
>Do everything extremely poorly

Write a recursive decent parser. Writing a lexical analyser will make the parser easier/cleaner to write as well.
Just google the terms I brought up if you don't know anything about parsing.

>decent
descent*

>implying
UNIX is best for learning C++.

You're just saying that because C++ follows the same steps as the C compilation process.
C++ is certainly not a "Unix language", and is just fucking terrible.

So, what is your argument? Are you saying he should learn C++ on Visual Studio? Again with the
>implying
my man.

No, my actual argument is that you shouldn't be using C++ at all.

thanks dude

It's one of the most common programming languages used outside of NEET basements. There is literally no reason why one shouldn't know it other than
>stop liking what i dont like!1!!1

it's shit

Just because something is popular, it doesn't mean that it isn't fucking awful.
C++ really is one of the most poorly designed languages in modern use.

>stop liking what i dont like
It doesn't matter if it is shit, if you want a job you should know C++. None of your hipster languages come close to the market share that C++ has. It's just a fact of life desu.

If you're really so fucking concerned about employment, why the fuck aren't you learning Javascript, Java, C#, or other codemonkey languages?

>implying i haven't
It's like you nerds just want to continue jerking yourselves over doing fizzbuzz's in meme languages.

>a language can be a "meme"
Opinion discarded. back to your subreddit

Why
>Do one thing and do it well
when you can
>Do everything extremely poorly

Someone needs to make an O'Reilly cover with that as the tagline for sepples.

Rate my seeples guys.

enum class binop {replace, plus, minus, times, div};

struct CalculatorState
{
double value;
binop currentOperator;

CalculatorState()
{
value = 0;
currentOperator = binop::replace;
}

double operate(double val)
{
switch (currentOperator) {
case binop::plus:
value += val;
break;
case binop::minus:
value -= val;
break;
case binop::times:
value *= val;
break;
case binop::div:
value /= val;
break;
case binop::replace:
value = val;
}
currentOperator = binop::replace;
return value;
}

};


Is it readable?

Fucking kingdom of nouns.

does anyone have a decent explanation of design patterns?
not an explanation of what they are or how they work, rather an explanation of why they aren't fucking retarded?

they ARE fucking retarded

"""Design Patterns""" are fucking retarded, though.

>an explanation of why they aren't fucking retarded?
This question is unanswerable

rate my haskell
data BinOp = Replace | Plus | Minus | Times | Div

op Replace = flip const
op Plus = (+)
op Minus = (-)
op Times = (*)
op Div = (/)

operate i (v:values) (o:operations)
= operate (op o i v) values operations
operate i _ _ = i

-- test = operate 0 [1,2,3] [Replace, Plus, Times]
-- 0 -> replace 1
-- 1 -> plus 2
-- 3 -> times 3
-- 9

yeah ofc it's readable. Personally I'm not a great fan of switch case though. Now it's pretty straightforward but if those operations where just a little longer it might be useful to just equip the struct with private functions for these?

But the calculator needs to store the last operator button that the user pressed, and use that when the = button is pressed.

I don't really want to store arbitrary two-argument lambdas in the state.

like in but fully applied

double operate(binop, double, double);

no reason for that to be tied to your state
then you can use
value = operate(op, value, val);

Use a local variable, you fucking idiot.

>not a great fan of switch case

There are places with elseif chains make sense, and places where switches make sense.

Switches aren't a subset, they suit different scenarios.

well, in that post I call it "op", i don't mean the one i call "operate"

this fucking sepples-tard

you are right and is wrong. Readability is important and by replacing "times" by "tm" or some shit you gain literally nothing. You can always minify/uglify the code before release so it's a smaller file.

You seem to be getting close to implementing a concatenative language. Try using foldl'.

Alternatively, trying using continuations.

Rate my seeples guys.

int vfs_open(const char *path, Inode *&file, int flags)
{
Inode *inode;
DirEnt dent;
FsInstance *fsi;

int mnt = pathToMnt(path);

if (mnt == -1)
{
return EINVAL;
}

LockGuard guard(lock);

fsi = mounts[mnt];

if (fsi == nullptr)
{
return ENOENT;
}

inode = fsi->root;
assert(inode != nullptr);

PathLexer lexer(path);
char buf[4096];

while (lexer.next(buf, 4096))
{
if (inode->type != FT_DIR)
{
releaseInode(inode);
return ENOENT;
}

bool ret = inode->lookup(buf, dent);

if (!ret)
{
if (flags & O_CREATE && lexer.next(nullptr, 0) == false)
{
assert(!"O_CREATE not yet supported");
}

releaseInode(inode);
return ENOENT;
}

inode = getInode(fsi, dent.ino);
assert(inode != nullptr);
}

int err = inode->open(flags);

if (err)
{
releaseInode(inode);
return err;
}

file = inode;
return 0;
}

operate = foldl' (flip (.)) id

operate [const 1, (+2), (*3)] 0

alternatively
(>>) = flip (.)

(do { const 1; (+2); (*3) }) 0

This is a fucking abomination of C code.
You just sprinkled on some C++ crap for no reason.

There's four kinds of developers:
>pajeets that avoid all abstraction
>those that err on the side of less abstraction when unsure
>those that err on the side of more abstraction when unsure
>haskell fags that abstract for every duplication

Which kind are you?

Oh God, you were RebindableSyntax user all along?

I salute your insanity, sir.

>trying to get into algorithms

>don't want to be that guy who got invited to a google interview

Don't worry about that buddy

rebindable syntax is the greatest invention of all time

It's sane C++.

By definition, no C++ code is sane.

You may be right, but C++ still offers me some features that manage to keep me on it rather than running back to good old C again.

>You may be right
No. He is right beyond any doubt.
>features that manage to keep me on it rather than running back to good old C again.
Your kind should be shot though.

Abstract when the duplication would reasonably be assumed to crop up as the platform grows. I'm not unsure, I makes a logical judgement based on previous patterns.

Which one is that?

why do you space your posts like that, plebbitor? fuck off.

spacing kind of cleans things up a bit.

problem?

>problem?
yes. we don't need you reddit animals nearby. fuck off already

is there any java library that is actually oop or any language where oop actually works?
The java standard library seems like utter trash desu.

Why does C++ trigger you so much?

Classes, templates, not needing to spam the "struct" keyword, the standard library, and not having to write your own slow and buggy fucking list implementation every time are all good reasons to use C++ over C.

Posts like this serve to convince me that a lot of people don't know what 'abstraction' means.

>pajeets that avoid all abstraction
Protip: Any language that isn't binary is an abstraction.

name one thing in C++ that is a bad practice, something you wouldn't do in C.

OOP does not work by definition. Which means what you're asking for is literally impossible.

It's #3 because you aren't yet completly sure whether you'll need the abstraction as the use case for the abstraction hasn't appeared yet but you expect it to appear.
Of course this also depends on how likely the abstraction is to be necessary - the bigger the chance, the closer you move to #2.

>Protip: Any language that isn't binary is an abstraction.
That post is about creating abstraction, not using abstraction, friend!

>Why does C++ trigger you so much?
Because it's absolute garbage and anyone who uses it should be killed by the state.
Pretty much everything that shitty "language" does.

>calling machine code """""binary"""""
Back to your subreddit

So basically you know absolutely nothing about the language, and you're just spouting memes.

nty