/dpt/ - Daily Programming Thread

What are you working on, user?

Previous thread:

Attached: programming_dog.jpg (2000x1500, 375K)

Other urls found in this thread:

godbolt.org/g/xdJxXH
pastebin.com/RCbdU8Pt
twitter.com/SFWRedditImages

thanks OP for the Qt pic.

Attached: Qt_logo_2016.png (1200x880, 33K)

Currently learning Python, it's a nice language.

Making web frontend for my file indexer daemon so i can just log to a site and know which hard drive has what.

Damn, I should have put my PyQt project code on the monitor. Not that anyone would be able to tell, but what can you do.

the only reason why a man would have a dog like is because it could evolve into a bigger good boye.
since that is not the case in this world, you're a fag!

roll

Attached: 1465123568519.png (3840x2160, 1.07M)

Anyone have recommendations for a database for a server backend written in Go?
I want something more serious than Redis but less serious than Postgres. Preferably fast and simple.

Attached: gopherhelmet.jpg (1009x1393, 100K)

Good idea. Let's invent a type
>Proc t
representing imperative procedures that compute values of type t. You'd need a
>callFunc :: Proc t -> (t -> u) -> Proc u
for calling functions after your procedures, but that's not quite enough. It'd be nice to be able to compose procedures in the same way:
>callProc :: Proc t -> (t -> Proc u) -> Proc u
But in order to compose with built-in procedures sometimes you'll find yourself needing blank "do-nothing" procedures that just give some pure value:
>blankProc :: t -> Proc t
This all works fine and stays pure so long as there's no way to call procedures from functions, so we just have to not provide any function that looks like this:
>runProc :: Proc t -> t

Whoops you just invented monadic IO. Don't worry, lots of people do it. It's a pretty natural construction, after all.

type Proc = IO
callFunc x f = fmap f x
callProc x k = x >>= k
blankProc y = return y

Whats wrong with mysql db?

SQLite

Forgot to mention: no SQL. Don't like it. I'm not having that great of a time using Postgres right now, so I'm hopeful for alternatives in the NoSQL realm.

I.. i wrote a tip calculator in python on code academy.

That's dumb. You're dumb. Use SQLite.

well done

>What's the point of using monads for side effects anyway?
They can be manipulated as first class objects and they're composable with other monads
>They allegedly allow Haskell to maintain its "purity," but any code that uses them becomes, in practice, imperative
Not necessarily, see FRP and reflex in particular. The latter allows you to interact with the real world in a completely declarative manner, even when side effects are involved
>Why not simply allow the programmer to define pure "functions" and impure "procedures" and allow calling functions from procedures, but not vice-versa?
IO already forces this separation, but having side effects as first class objects is very useful

Attached: matsuri haskell.jpg (1920x1080, 128K)

why doesnt this general have useful links or a pastebin like /wdg/?

Attached: Screenshot_1.png (1300x411, 183K)

It's all in the sticky.

I am going for C++ internship at Fortune 500 company (protip: I am fucking retarded). Ask me answers as if you were an interviewer.

What should I refresh?

Attached: 1525724159826.png (1360x2765, 3.05M)

Currently working on a compiler for my compiler construction elective. It is mostly finished, I just need to test fringe cases. The target language is a hybrid of C and Pascal. It currently generates ARM assembly.

Give me a fizzbuzz on the double.

SQLite is honestly the worst possible option in my case.
It has all the drawbacks of a file-based DB with no added benefits (and it's SQL). There is a file-based DB that I'm considering right now, but only because it actually has benefits that outweigh the drawback.

I'll do some basic read/write benchmarks of them and report back my findings.

Anyone have experience with using Lua as a data storage language? How does it compare with others like XML amd json?

If I do

struct a b;

At the top of my C file for a global variable, will everything inside the struct be allocated even if I never use it?

jesus what the fuck are you planning on doing with that, user?
either present your reasoning or stop immediately.

yes

brainlet here, what's wrong with my vigenere cipher

// Print ciphertext string
printf("ciphertext: ");
for (int i = 0; i < strlen(plaintext); i++) {
if (isalpha(plaintext[i])) {
if (isupper(plaintext[i])) {
printf("%c", ((plaintext[i] - 65) + (key[i] % (strlen(key)))) + 65);
} else {
printf("%c", ((plaintext[i] - 97) + (key[i] % (strlen(key)))) + 97);
}
} else {
printf("%c", plaintext[i]);
}
}

>i < strlen(plaintext)

Attached: 1527187523587.jpg (450x720, 48K)

What's wrong with postgres? I use postgres for random side projects, how can it be too much for an actual server? If you use nosql you'll end up with an unnormalized messy "database" where every "document" has different entries.

>tfw kind of understand this :: -> bullshit now
feels comfy man

What problems are you having with Postgres? It's a pretty advanced database with features you'll love for real projects, but it can be a bit daunting to learn on.

A sorting weight is just so you can query "SELECT … ORDER BY weight" to get them in the right order. Usually this would be some kind of numeric column that you can update when items are re-ordered.
I need an updatable sorted lists of relationships in a database where rows can't be deleted or updated. In this specific case it's product images; new ones can be added, old ones "deleted" (not actually deleted), and rearranged.
One way of doing this would be to "mark as deleted" all the records after the one whose position changed and then re-insert them with new weights, but that leads to a lot of unnecessary garbage in the database. Another approach would be to use a float type and just split the difference when moving an entry, but eventually you'd either run out of floating point precision or decimal places. This takes advantage of how strings are sorted to always allow a sorting key to be generated that is sortable before any and/or after any other existing key.

ty

I don't think it's particularly meaningful with how general this thread is. Most materials aren't that broadly applicable and we fight a lot over languages. Making the op another point of contention is not a good idea. It'd easily break the 2k char limit if we were being balanced and we'd still have people complaining their new eso-lang or the latest reddit fad not being there.

It's fine. Any modern compiler can see that the array isn't being modified.

Though it's dangerous practice i guess.

Why is the Danish gnomes book there but not SICP?
Why is the Bible in there? Are you some kind of fundamentalist?

Besides recomputing strlens a million times, shouldn't
>key[i] % (strlen(key))
be
>key[i % keylen]
?

What's wrong with that?

You are wrong.
godbolt.org/g/xdJxXH

Lua started as a language for writing config files so I don't see what's so far fetched about using it to store data

i'm a brainlet after all

why is it bad?

It is implementation defined and a good way to lose performance.

Implementation defined optimization*
Don't trust the compiler.

strlen is O(n) and you're recomputing that for each iteration

Which brand of programming socks is recommended?

thanks.

...

>What's wrong with postgres?
>What problems are you having with Postgres?

>how can it be too much for an actual server
>pretty advanced database with features you'll love for real projects
Exactly. SQL by itself is overkill for me, so whatever Postgres offers in addition to that doesn't help me. I just want to store and retrieve data in a fast and safe way. I don't even need queries beyond just looking up stuff by ID.

>you'll end up with an unnormalized messy "database" where every "document" has different entries.
not if you migrate properly :^)

What, so the code might end up recalculating strlen every loop in case it might change?

Huh. Well I'm disappointed. Never using the standard library ever again I guess.

>might
Does. That's how it's written.

>if (isupper(plaintext[i])) {
> printf("%c", ((plaintext[i] - 65) + (key[i] % (strlen(key)))) + 65);
> } else {
> printf("%c", ((plaintext[i] - 97) + (key[i] % (strlen(key)))) + 97);
> }
What the fugg??? :DDDD

You're a disgrace. Replace that whole fucking thing with
printf("%c", plaintext[i] + key[i % keylen]);

Why does Microsoft change their reference documentation site address every fucking year? I'm tired of running into dead links!

Attached: 3533636572.png (574x516, 484K)

thanks

And why are you printing characters in a loop? Mutate the string and print it once. Code would be far simpler.

I've started studying CalcI for the summer but want to dip into Discrete Math as well, can anyone point me to a good resource?

Attached: ineverhadachoice.jpg (667x659, 77K)

Does anyone here have advice for dealing with 60 hour work weeks? I found out this morning that we're going to be working those hours until at the latest April of 2019, and can't lose my jorb since I've only been out of school and working for like a year and a half. What can I do to make it kinda better.

Pls help.

wew, weird cat. what happened to it, car run over?

welcome to the adult world, user-kun.

Attached: Salaryman_asleep_on_the_Tokyo_Subway.jpg (800x600, 144K)

>60 hour work week
You're like a baby.

Attached: 87077682999.jpg (399x464, 52K)

because i'm a brainlet who's still learning

(For educational purposes only of course)
Here is my project:
pastebin.com/RCbdU8Pt

Working on a mitm crypto miner written in Go. I hope to make it so that the attacker can just drop it on a network with a raspi and it run recon and do mitm attacks continuously. Just finished the recon phase and going to start implementing the mitm portion. This is my first project in Go. Any critique?

Attached: cylberdelia.jpg (720x336, 27K)

can I somehow tell clang-tidy to not bother me about shit that's Qt's fault?
or should I just drop cppcoreguidelines?
what are the preferred settings for someone who desperately needs hand-holding because they barely know sepples?

Attached: ss-2018-05-25-17-58-09.png (1121x59, 9K)

Okay I think it works, now to simplify the code & remove magic numbers & stuff.

That's fair. Personally for that I'd use Redis because it's so lightweight & just store JSON or YAML blobs or something.

Attached: Screen Shot 2018-05-25 at 12.07.05 PM.png (2880x1750, 865K)

I started with Redis, then got a buncha people telling me I should use something more serious for persistent data. So I tried out Postgres and started hating my life.

>just store JSON or YAML blobs or something.
Thankfully I could get by with just Redis hashes and sorted sets. They are quite comfy.

just use a text file

>I should use something more serious for persistent data
I mean, I don't really see why. Redis isn't just a chache although it is memcached-compatible; it does flush to disk periodically (every second by default iirc) so it can act as persistent data store. In fact that makes it really useful for data queues you need to preserve if your systems go down and don't want the technological overhead of separate caching & queuing software.

How do I properly integrate a clang-tidy check with my CMake project?

I'll just disable cppcoreguidelines then

also picrel, and somehow sepplesfags complain about electron being ram hungry

Attached: ss-2018-05-25-18-39-13.png (1107x41, 8K)

>use a third party C library in my C++ project
>new GCC comes out
>new diagnostics detect a lot of wrong shit with the library and my project no longer compiles with -Werror
thanks C tards

Working on python and reading sicp. It's kinda a hard read for a logical math brainlet like me but I'm trying..

Attached: 1527216499582.jpg (750x1000, 687K)

What's the difference between css HTML and python and all of that?

Refactored
float tickOpGetLaserPlatRayLen(const Tick *t, int i);

into
float tickOpGetLaserPlatRayLen(
float untouchedLength,
int laserPlatIndex,
float platVel,
long tick,
const TickLineArray *line,
const TickPulsatorArray *pulsator,
int pulsatorMultiplierCount,
const float *pulsatorMultipliers,
const TickShrinkerArray *shrinker,
int shrinkerShrinkingTickCount,
int lockCount,
const TickLockArray *lock,
int lockShrinkingTickCount,
const TickPlatArray *plat,
const TickEjectorPlatArray *ejectorPlat,
const TickLaserArray *laser,
float ls,
const TickLaserPlatArray *laserPlat
);

This is good, right?
A function should take as little data as possible and not depend on any external scope variables or constants, right?

Question: I come from the poseur-enhanced retardview of /mkg/ - who of you wannabee hackers is using a 40% keyboard?

What in the fuck. Pack everything in a structure and pass a pointer to it as an argument if you really need all that shit, Jesus Christ.

passing a pointer to a context struct is perfectly all right

But Tick is a superset of all that shit that is in the arguments.

I am using godot as my main IDE to make non games.

Attached: apu.jpg (636x515, 38K)

Shouldn't a function take only as many parameters as it needs?

(checked numbers)

I once wanted to build a Planck. Even got the plates cut. Then I realized how much of retard I'd be having to relearn from regular keyboards.
Now I know that 75% (84 key) layout is the best. 60% a shit, sacrifices too much.
Real hackers don't compromise vital keys for portability.

Attached: keycool_84.png (880x338, 32K)

I have so much tech skills to learn...

I have the CompTIA...figuring out command line and python practicing...I should write my goals down or something to make it easier for me.

Attached: 1526847883542.gif (320x224, 1.92M)

As a rule of thumb, but nothing more. Something is only "evil" if its alternatives are worse.

Then take that list and find a way to make some kind of project out of it. "I know X" is far less interesting than "I used X to make Y".

Only when it's like, a couple. When you have a long list of parameters like that you pack them in a structure to make both passing it around and reading the code less painful. And you're only taking a pointer to a struct as a parameter in place of all those, so it's more resource efficient as well.

>Real hackers

Not sure who told you that. Functions are for abstracting functionality; a function with too many arguments is as useful as not using a function at all. In this case there are so many individual arguments I can't tell what is related to what or what it's used for, but can't recommend anything either. I doubt a single state struct is what you need, but I don't know how many make sense for your program. Part of the problem is you're using C, which doesn't have a nice library of containers that would help you cut down on the argument count, but if you're using C instead of C++ you probably have a good reason to.

yes, i am a hacker.
do you have a problem?

Attached: 1408727826956.jpg (513x488, 44K)

Then each function would have its own argument structure.
Tick is a megastructure, and all tickOp* functions operate on parts of that megastructure.

>Part of the problem is you're using C, which doesn't have a nice library of containers that would help you cut down on the argument count
Heavens forbid he has to write a structure declaration. It's like, two whole words and a pair of brackets! Oh if only he had a library of containers to make that easier.

I was specifically referring to the arrays being passed as pointer+length, no need to get defensive.

That's only two arguments instead of one.

>tickOpGetLaserPlatRayLen
Wtd is this? At least sort your struct members by type to have less padding

I assume you're talking about "lockCount" and "lock", which is the only part it shows up.

get a really good chair. get some dumbbells.
try to exercise any moment you have some downtime. it'll help significantly with fatigue.
i work 10-12 hour days on the regular from home.
the key to pulling long hours is to take enough breaks that you aren't beat to all fuck.
also drink water, eat right, and get good sleep.
i let myself fall into a hole of despair for 6 months with these hours.
>eating pizza 3-4 times a week
>not exercising
>drinking to much caffeine and not taking breaks.
you'll burn out hard and fast. your weekends will just become recovery periods where you sleep the whole time and do nothing because you can't bring yourself to exert effort.
Don't forget to look on the bright side with it.
>learning at a rate of 1.5x~ compared to those your age/skill level
>other employers will respect your work ethic and new knowledge
>better pay depending on contract, more bargaining for a higher salary no matter what.
>it's satisfying as fuck to get shitloads of stuff done and "feel" like a x10.
good luck user.

It's a little hard to tell due to how user's named his arguments, but it looks like there's 5 arrays being passed there, so it would be replacing 10 arguments with 5. But I might be reading the signature wrong as he hasn't shared any code.

godot has an ide? since when?

Attached: confused_by_your_bullshit.gif (275x200, 1.57M)

Why? Just pass Tick and call whatever elements of Tick the function needs within the body, it doesn't get any simpler than that. If the problem is that the structure Tick is too big then that's an organizational problem, there's nothing keeping you from having multiple smaller structures instead of one megastructure, and if a function needs to access way too many elements from way too many different structures at once then it's probably too big for its own good and should be subdivided into smaller functions.

Attached: 2018-05-24-190929_1440x900_scrot.png (1440x900, 179K)

I don't get what's the problem with them being arrays or not.

No, I'm saying when you're using containers you can store & pass them as a single variable that contains its own size rather two separate variables only connected by name. You can do this in C it's just easier in some other languages.

>tickOp
This function belongs to the tickOp function group. These functions operate on the Tick megastructure, but without modifying the megastructure (they're read only).
>GetLaserPlat
Laser platforms are lasers which are moving in the air.
There are simple platforms, which are just moving walls.
Then there are lasers, which just stand there still all the time.
We are talking about lasers moving in the air.
>RayLen
The laser platform shoots a ray (beam).
The beam travels until it finds an obstacle.
There are many obstacles:
1) Lines that never move.
2) Pulsators, walls that contract into nothing, wait a little, then expand into full size, wait a little and the cycle continues. In order to know what size currently the pulsator is you have to know how long is the multiplier table (multiplierCount), have the multiplier table (multipliers), and which (nth) logical tick it is. Then multiplier = multipliers[(tick % multiplierCount)] and pulsatorSize = originalSize * multiplier.
3) Shrinkers. They shrink when you touch them, so initially they're full size but when hero touches them they contract into nothing.
4) Locks. They shrink when they key is collected.
5) Platforms: moving walls.
6) Ejector platforms: moving walls that eject hero into air.
7) Lasers: static (non-moving lasers).
8) Other laser platforms.
When we perform the collision test against all these obstacles, we get the length of the ray.

reminder that cniles will look at a name like this and still think namespaces are useless

To expand on that, Tick megastructure contains a lot of other stuff this function doesn't need (commented out):
struct Tick {
// int winW, winH;
// TickLvl lvl;
// TickHero hero;
// TickPickableArray coin, graviton, jumpPill;
// TickEjectorArray ejector;
TickPulsatorArray pulsator;
// TickFirePulsatorArray firePulsator;
TickShrinkerArray shrinker;
TickLockArray lock[4];
// TickPortal portal[5];
TickPlatArray plat; //, fire;
TickEjectorPlatArray ejectorPlat;
// TickCamera camera;
TickLaserArray laser;
TickLaserPlatArray laserPlat;
TickRectArray /*minigunHorizontal, minigunVertical,*/
speedRailLeft, speedRailRight, speedRailUp, speedRailDown;
TickLineArray line;
// double lastTime;
long tick;
};

You can just name your variables namespace_variablename or something similar if you want to organize that way.

That eliminates the entire purpose, which is contextual name lookup.