/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: tech_workers.jpg (1653x2048, 359K)

Other urls found in this thread:

en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences
en.m.wikipedia.org/wiki/Approximate_string_matching
jamesmunns.com/blog/tinyrocket/
twitter.com/NSFWRedditGif

Knitting some nice socks

Functional focused programming languages are all crap.

And Javascript is the greatest testament to that.

I'd take Haskell over Rust any day. At least it has better syntax and a consistent design.

>Javascript
I'd just like to interject

Attached: r1akksyd5ko01.png (1278x1200, 467K)

Since C and C++ do stack allocation by default -- for everything, not just primitives -- it doesn't make sense for a variable of a record type to be null, because record types are not secretly pointers to record types, they are exactly what they say they are.
Think of it this way, in Java when you do x = y you're taking x's leash off whatever dog x was walking and putting x's leash on the dog y is walking instead, but in C and C++ when you do x = y you're not working with leashes, you're working directly with dogs, so you're actually directly surgically taking apart a dog named x and reconstructing it to be exactly the same as the dog named y.
So, why would you do this, like you're suggesting?
SomeClass obj = SomeClass();
Why would you create a dog, create another dog, and surgically modify the first dog to be the same as the second dog, when you could just create one dog?
It makes more sense when you're working with the heap:
SomeClass *obj = new SomeClass();
Because then you're not creating two dogs, you're creating a leash and a dog and then saying the leash you created should be the same as the leash on the dog. I.e. creating a dog and attaching a leash to it.
But hopefully you should now understand why it makes less sense for the stack.

C. Has lasted for 46 years, and shows no signs of not lasting for another 46.

How exciting! How exciting!

Rust is amazing.

>it has to be future proof
>it also has to be "new and exciting"

Attached: 1509468820327.jpg (785x562, 76K)

Do I need to make my repo public when applying for job, or I could get away by only showing them my repo during interview?
Also will any employers reject me if my repo full of degenerate stuff such as web crawler for hentai site, tag-aware image viewer (which mostly from hentai tag), somewhat working automatic hentai tagger, and so on?

Yes. That's webshit glue code anyway so it's worthless.

Not him but C isn't future-proof, it's anything but. It was made for a time when memory and processing power were limited, and a choice had to be made between safe robust code and code that met all its desired functionality, because there wasn't enough room or power for code that did both. Things are different now.
It's a good language, I like it, I'm going to keep using it, and it's not going anywhere, but it's sure as hell not "future proof."

fclose can only fail in flushing the stream. If a file is being closed during unwinding, it's because during writing, something has already failed, so it really doesn't make a difference whether the buffer was flushed successfully or not, so it can be ignored.

If an exception raised for some reason that has nothing to do with writing a file can close a file that you're writing prematurely, your code is fucked. That's all there is to it.

Put your hentai stuff on your CV as previous experiences. You can describe it in nondescript terms, such as "crawler for image website," "tag-aware image viewer," and "automatic image tagger."

What hentai site does it crawl?

>it's not going anywhere, but it's sure as hell not "future proof."
Oxymoron.

>microcontrollers
>desktops, all the libraries and shit
>graphics, has to be high performance
>supercomputers, science stuff
It's got all the avenues covered. Won't be replaced on more than at most 1-2 of these.

You have low standards for what "future proof" means.
To me, a "future proof" language would be one that adapts well to future technology, not the other way around.

That's not "all the avenues," that's four avenues.
Those are the ONLY avenues it has covered. More modern languages are just fine for anything else.
Not that I'd use them, since I prefer C as a matter of taste, even if it is more cumbersome at times.

printf("\v");

prints vertical tab. After printing it i want to go back to same position in terminal stdout.
would this work?
printf(("\v\b");

b for backspace

>microcontrollers
Only because of compiler support.
>desktops, all the libraries and shit
There's nothing in particular here that favours C over, say, C++ or Rust (Redox exists).
>graphics, has to be high performance
GPUs aren't programmed with C.
>supercomputers, science stuff
Same as the "desktops" part.

In all of these, you're basically ignoring other low level, high performance languages that already exist or will eventually exist.

Just tried it. Nope, doesn't work.
What you probably want for this is something called CSI sequences. Here's the wikipedia for it: en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences
(or you could literally just use ncurses)

No. Also, what is virtual tab?
Try ANSI codes instead

C is also woefully unsuited to a whole other area of low level, high performance development - programming FPGAs, DSPs, and circuit synthesis for ASICs or brand new chips. In this space, it's all about data flow, which is declarative. And data flow works very well for parallel software (graphics, simulations) on top of that.

> If a file is being closed during unwinding, it's because during writing, something has already failed,
And what if the file isn't being closed during unwinding? If you're using an RAII file handler and you return from the function normally, the destructor will close your file and you'll never be informed about the error that does occur.

Return values and procedures compose together in a way that exceptions and implicit destructors don't.

>Could NOT find LuaJIT (missing: LUA_LIBRARIES)
>(found version "2.0.5")
what's up with cmake

>Return values and procedures compose together in a way that exceptions and implicit destructors don't.
sounds more like exceptions and implicit destructors don't compose at all

I had a question for /wdg/ a week ago.
Just wanted to say thank you to you /dpt/. You're always so helpful.

Question for c++ devs: Say you have a class that has a vector of pointers to some type of object, and you want to add new instances to that vector.
The class wants to own the object and control the lifetime.

Do you prefer allocating in client code and passing the pointer in for the class to then own, asking the class to allocate an instance and hand back the pointer to be initialised by the client code, or some other method?

I can never decide the best way of doing it.

Install LuaJIT.

what's a good programing project,
I'm learning common lisp, but I haven't really had any ideas to apply my knowledge

That's a good point, although I can be pedantic here and say that RAII isn't necessary for unexceptional destruction and a decent file API shouldn't expose the leaky abstraction that is automatic flushing on file close, instead requiring the programmer to flush explicitly. It would be nice to be able to distinguish between destructors called normally (although in this case there's not much that separates them from regular methods) and destructors called during unwinding for this reason.

I don't want to defend C++ too much. I suppose I went into the argument thinking about RAII in general and not how RAII works specifically in C++.

Microcontrollers and C isn't just because of compiler support. Most languages can compile to GCC IR, and GCC supports many microcontrollers. We don't see people using Rust or C++ for those, do we?
C gives a direct control over the hardware that other languages fail to match.

No, other than that C is easier to work with (for Unix) and yields superior results (smaller, faster binaries)

>what is openGL, vulkan

>what is cuda, openCL

I don't trust these "other low level, high performance languages that already exist or will eventually exist" for a second. They've tried to kill C many times, but failed.
That's not programming, that's chip design.

>RAII
It's fine to use the constructor/destructor pairs for getting predictable state. It helps programmers avoid mistakes sometimes.

But don't have that in your language without a defer statement. And as a general principle RAII is problematic because it doesn't respect all program circumstances.

Zero initialization is more generally applicable.

What's the best way to check how closely some piece of data resembles another piece of data?

Attached: 1526687078572.jpg (1124x1024, 129K)

I do have it installed, and it even detects its version (2.0.5) but says that it's not installed even though it was able to properly parse the version from the header it found?

I would stack-allocate in client code, pass by const pointer or const reference, and allocate a copy in the class instead of adding in the same pointer passed.

hamming distance? edit distance?
What type of data?

What system are you using? Do you have the libraries installed? The package name should begin with libluajit or something similar.

I want to do the following in java library:
user can add an annotation to a function. the library finds the function by reflection. with bytecode manipulation I add a callback to the constructor of object and gather all instances of objects containing the function.
all that is easy.
however, how do I check if an object is still alive (as in used by the user) and the only reference is held by the library?

Attached: 1526913976501.png (734x788, 491K)

you can emulate defer with destructors and first class functions

en.m.wikipedia.org/wiki/Approximate_string_matching
Read this. There's many methods that imply different things. I like Levenshtein distance.
You're obviously being very vague when you say 'resemble'.

obligatory pic related

chip design is programming, you're just compiling to circuits instead of asm

Attached: 1509606198744.png (3840x2160, 1.61M)

What would you guys use for a small sqlite database admin for a single user?

First thing I thought about was node.js with express + web UI but that sounds and probably is incredibly stupid for this use case.

DB Browser / vendor trash is out of the question.

>C gives a direct control over the hardware that other languages fail to match.
If a language has unrestricted access through pointers, it can do whatever C can do.

>what is openGL, vulkan
>what is cuda, openCL
Libraries with C APIs that can be used in most languages. It doesn't make a big difference which language is used on the host to produce commands for the GPU, the API itself was the biggest CPU bottleneck before Vulkan and company existed. And I know that at least the AMDGPU Vulkan driver is written in C++, not C.

>They've tried to kill C many times, but failed.
That's at least in part because of people like you who can't let go of C, not because of the languages themselves. Try judging languages by their merits and not who uses them.

>That's not programming, that's chip design.
Chip design is done with programming languages. There's no real reason to exclude it just because it doesn't produce 100% software. There's little difference between a specialized piece of software running on generic hardware and a specialized piece of hardware, except that the latter is more efficient.

Yes, the library file is present in the lib folder and the include files are present in the include folder.

Yeah sure. But you can emulate [feature] using [other features] almost always.
I'm asking for a nice interface and preferably a customizable ordering.

Depends on type. Also depends greatly on use case, so it's difficult to give a general prescription.
Numbers: absolute difference, or higher order analogs (e.g max(x/y, y/x) or max(log_x(y), log_y(x))) depending on the numbers' units and roles in whatever formulas you use them in.
Arrays: Levenshtein distance.
Strings: Levenshtein distance usually. But if you care about the words, not how they're spelled, you should first convert the string to an array of words.
Pointers: Absolute difference.
Record types: Memberwise difference using the above methods per type or whichever you prefer for your use case.
Data in general, for use cases in which the specific content or semantics of that data is irrelevant: Levenshtein distance of byte representations.

Yeah, I sometimes do it like that, maybe it is the best way.

t. fatty

you mean small belly

Attached: 1527876999295.jpg (1081x1021, 148K)

Well, not AMDGPU, but whatever it's actually called. I've seen bits and pieces of the open source AMD Vulkan implementation, and it's C++ with an extern "C" API.

t. very fat and morbidly obese

superior version

Is highway design programming too? You're just compiling to a map instead?

C? Quick and easy.

Yes, and if you need a language with unrestricted pointer access C is what you want. What would you replace it with? Rust, which doesn't have unrestricted pointer access?

Rust and C++ are both unsuitable for microcontrollers for a host of reasons.

>Libraries with C APIs that can be used in most languages. It doesn't make a big difference which language is used on the host to produce commands for the GPU, the API itself was the biggest CPU bottleneck before Vulkan and company existed. And I know that at least the AMDGPU Vulkan driver is written in C++, not C.
It's still a fact that most graphics-intensive programming is done in C. Take the id Tech * family, for instance.

>That's at least in part because of people like you who can't let go of C, not because of the languages themselves. Try judging languages by their merits and not who uses them.
If it's future proof to learn it's future proof to learn. Doesn't matter why. There's no need to let go of C anyway since all the alternatives are worse, so clearly the people who can't let go have the right idea.

>There's little difference between a specialized piece of software running on generic hardware and a specialized piece of hardware, except that the latter is more efficient.
There's the difference that only one of them is software. If what you're producing isn't software, it isn't programming you're doing.

Attached: 1512194588025.png (5198x2124, 2.46M)

In C, if I wanted to have some functions that should only by used by other functions inside of a source file, do I just omit its prototype from the header file?

whatever, hater

Attached: 1525446121973.png (1464x903, 1.77M)

Use static keyword and omit from header.

>C
Noice. Any libraries you would rec for such a project?

Sorry if I'm being a faggot but years of .NET and basic webdev have fried my brain and I'm trying to get it back on track.

Yep. Also, as a further precaution you can take in case you anticipate having multiple "private" functions with the same name across different files, you should declare those functions with "static" in the source file. That way the linker knows not to leak them to other files.

>Rust, which doesn't have unrestricted pointer access?
unsafe

>It's still a fact that most graphics-intensive programming is done in C. Take the id Tech * family, for instance.
idTech has been majority C++ since Doom 3.

>There's the difference that only one of them is software. If what you're producing isn't software, it isn't programming you're doing.
Looks like programming to me.

Attached: 1200px-Vhdl_signed_adder_source.svg[1].png (1200x1286, 128K)

I don't even know why I'm bothering with this argument when I know from years on this site that Jow Forums has an autistic fetish for C.

No dude, I have nothing against fats, I just think they should be aware how huge and gross they are so they know to get that checked out and treated e.g with intake reduction. I mean if you posted a picture with a lead pipe sticking out of your head it would be pretty irresponsible of me NOT to respond with "dude why is there a pipe halfway through your skull, do you realize it's in there."

you dont understand: he is very fat but very fit too

Attached: 1527971740514.jpg (460x460, 23K)

What functionality do you need? Just a GUI to poke around in databases?
If so, look at libui or nuklear. sqlite3 for reading the database. Maybe some string library if you're doing a lot of string stuff.

Fitness isn't ability to exert strength, it's ability to not die. This man is not fit. Strong perhaps but not fit. He is woefully close to death and needs to put down the fork.

Go back to JavaScript, onions programmer.

>Is highway design programming too?
there's probably some orthogonal aspects, dunno enough about the area though

>There's the difference that only one of them is software. If what you're producing isn't software, it isn't programming you're doing.
what is a cpu if not a circuit implementation of a program to emulate asm

goddamnit I used the word orthogonal wrong

Writing code that is consumed by a compiler to produce files that perform a task when executed - programming
Writing code that is consumed by a fabrication plant to produce dies that perform a task when powered - not programming

>, onions programmer.

Attached: KmBwcAg.jpg (594x334, 32K)

Wrong.
Writing code that is consumed by X to produce Y that perform Z when executed is programming.
More generally, writing code to perform X when executed, no matter how directly or indirectly, is programming.
I believe what you mean, is that writing code that is consumed by a fabrication plant to produce dies that perform a task when powered, is not COMPUTER programming.

entirely arbitrary distinction, a program just needs to be something that performs a task

If you're using unsafe everywhere, you might as well write C. For microcontrollers, it's not like it matters, if it breaks it breaks anyway. Also, Rust is more high level than C, it's closer to C++.
For example look here - jamesmunns.com/blog/tinyrocket/ - 816K, vs "several hundred" for C. That's not suitable.

>since doom 3
But idTech isn't graphically groundbreaking anymore. Back when it was and optimization was their killer feature, it was all C. For example, fast inverse square root hack.

>Looks like programming to me.
TAOCP doesn't agree.
Most Jow Forums boards' dominant opinions on their specialty tend to be right, in accordance with the law of large numbers.

How big is your wage to shill programming language on /dpt/?

>writing code to perform X when executed, no matter how directly or indirectly, is programming
So a chef that writes recipe is programming?

>It was made for a time when memory and processing power were limited
Yeah. Like right now.

At first just simple DB management admin heavy on text, that can run in a single device by loading a sqlite db. No auth or network bullshit just a man working on his DB.

Nuklear seems to fit the bill for my UI reqs; as I understand it just draws primitives so it'd be completely OS agnostic.

Most of my experience is in object-oriented programming, how hard do you think I'll crash and burn before gettin gud?

you are just jealous of his alabaster body

Attached: 1524595326972.jpg (1515x1443, 212K)

As long as you can reliably expect the same output given the same input.

Yes. A chef that writes recipes is programming a meal.
You wouldn't usually say it like that though.

If that's all, it seems like a simple project to begin with. Start by sketching out the UI in paint, then figure out which DB queries could be applicable, then put it all together. Will probably do fine, object-oriented programming is somewhat applicable. After all, C has structs.

not him but yes

>/drt/ - Daily Recipe Thread

>C++ [is] unsuitable for microcontrollers
Proceed to give no fucking reasons asshole.

The point is you don't use unsafe everywhere.

>For example, fast inverse square root hack.
Which would work in C++ or Rust or anything with bitwise manipulation.

>Most Jow Forums boards' dominant opinions on their specialty tend to be right, in accordance with the law of large numbers.
By your logic, normies' opinions on shit tend to be correct.

I think it would be more accurate to say "programming a cook" in the sense that you are giving explicit instructions to a person. I don't say "I'm programming a program," I say "I'm programming a computer"

Your argument is invalid: This is the technology board. It's implied that the technology in question is consumer technology, since Jow Forums retards are NEETs i.e brainless consumers. Programmable consumer technology is called a computer. Ergo, context would imply this is the COMPUTER programming thread.

>food analogy
IMAGINE

Can a loop that has both integer and floating point operatipns be pipelined by the cpu?

Yes, it should be able to execute the integer operations simultaneously with the FP operations as long as there isn't a data dependency.

Yes, and if you have to ask that question it sounds like there's some things you misunderstand about pipelining.

I suppose so, that's technically correct. But that's a bit rude to the cook, it dehumanizes him a little by implying he is being directly controlled by the chef and has no free will to disobey the program given to him as input. It would be more polite, and probably make more sense out of context, to say a chef who writes recipes is creating a program for cooks to follow.

According to dictionary.com, programming is the act of creating a plan of action to complete a specific end, so yes.

on a modern cpu it'll pipeline nicely because they'll be dispatched to distinct functional units

C will probably remain. At most a revision that adds bounds checked arrays and strings might happen.

Chuckled.

Yeah it will probably remain, but it's not future proof.

I guess so, I thought the fpu was quite distinct within the cpu.