/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: light_table.png (1440x900, 137K)

Other urls found in this thread:

infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare
godbolt.org/g/PDXmCt
godbolt.org/g/5vTXTh
twitter.com/SFWRedditVideos

I swear to fking god

Attached: fucking java.png (255x178, 5K)

Attached: pl-alignment.jpg (1000x800, 159K)

is Long a predefined class? use BigInterger or "long", retard.

Synchronization = unification

Reminder that LP is the future

Attached: prolog-tree.png (775x687, 65K)

I think you mean LP and FP combined

tfw no advanced type systems for lp languages

Followup question:

If you've done a bunch of tutorials like these and you understand (to some extent) the basic concepts, where do you go to find real examples of programming? I know what a string and an array and all that shit look like, and I can even put them together to make a program that prints something to the console, but I have no idea how it all fits together in the real world.

Tutorial programs only seem to use snippets of code, teaching you one concept at a time. The closest I've got to seeing a complete program is a flappy bird game in Java. Are there any tutorials that actually walk you through real-world coding examples, using complete programs that people would actually use?

Attached: 1278988785767.jpg (239x251, 11K)

t. Functionlet

Long is the object form of long

>real world examples
A real world example is anything that works. I work in a lab and have written a small dozen of very specific image manipulation tools and the only difference between them and some tutorial code is theres a fair bit of incredibly specific maths here and there.

Programming is taking a pile of nails and jigsaw pieces to build something new, no one individual snippet is the whole.

traverse . traverse . traverse

welp, looks like I finished it already
now I just have to wait for the emulator to turn on, so, more 30 minutes

lenslikes are the best
btw you can also traverse traverse

you're not kidding

Prelude> :t traverse traverse
traverse traverse
:: (Traversable t1, Traversable t2, Applicative f) =>
t1 (a -> f b) -> t2 a -> t1 (f (t2 b))


gonna take me a moment to get a feel for that type

Oh I thought you were using them as indeces. Why, pray tell, are you having issues putting BigInteger into an array?

I swear C# devs are the biggest brainlets. Ugh.

i think it uses (->)

I think I get it. this makes me sad that most languages you can get a job in are so inexpressive. imagine trying to do this in java or even in scala

>Can't instantiate MainActivity because null pointer exception
AAAAAAAAAAAAAAAAAAAAAAAAAAAA

meanwhile in java

>6 hours of work just so it can break itself randomly for no reason at all
fucking java

Should have done TDD

>type-driven development
I completely agree

can't you copy paste your code to another project?

Brainlets get out of my thread REEEEEEEE

lads I think universities shouldn't teach java, python, js, or c# tbqhwy, if companies want people to use those languages then they should train them

What language are you using? I could give some examples for real C and Perl code. Nothing terribly fancy. Some of the C code I'd have to describe because I didn't keep it. (also, work code...)

>lab code
A lot of higher level stuff is just number crunching, and the algorithms are figured out. Implementing an older system in newer code (turning analog hardware/old software to cross-platform or featureful software) is more interesting. If you want to do something interesting, you need to do more than just make 100 threads for 1 gigapoints which scales from 2 3 threads and 100 points. Once you start talking parallelism of multiple applications, cross-system running, data-ripping, it gets better.

>copy the entire code to another project
>same error

Attached: 1528842577941.jpg (500x500, 39K)

dumb frogposter

have you tried debugging it?

But isn't making a program just using these basic concepts if you already know them? You may also include a library but that depends on what you're working on.

You have a very stupid concept of what lab work actually is. Its not just "run lots of numbers xDD"

AHAHAHAHAHAHAHAH

IT'S ALIVE, IT'S WORKING!
FINALLY

Attached: 1510544312241.jpg (519x447, 40K)

im trying to get into electron stuff with javascript but i come from a c++ background with qt and juce. Is it possible to make UIs in a similar way? I guess something not too tied to html. what would you Jow Forumsentlemen recommend?

Attached: tumblr_lgzfhcRgtl1qa1cxxo1_500.gif (500x375, 483K)

what's better?
if(yes)
//stuff
else if(no)
//stuff

or
if(yes)
//stuff
else
//stuff

honestly, it's just shoving all the basic concept stuff together and hoping it works

use the first if the condition can be something beyond yes or no, otherwise you can use the second

infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare

I just finished this, and they asked questions at the end that. One of the notable cases in my experience is ending an array of pointers, or knowingly having a pointer which safely indicates unused memory. In each case I externally define data which is #included into an array of pointers (in this case, fonts), and if I have a font which matches what I need, I take the pointer and use it, otherwise not. However, I don't necessarily know how many pointers I could have. I do have a quantity I can define at compile time, but I would have to change this when a new font is completed. With null I can include all the pointers I may need based on the standard, and leave the unused ones empty. This is explicitly the case for a font: I have letters which are defined, and letters which are not. If I wanted to bounds check my characters, I would have to have the language collapse them into an un-empty array, and have a function which when it requests a letter return a font, it would also have to have the character correctly mapped. Not entirely difficult, but it means I need to enum every case, and properly include the enums in order in the function, or have an explicitly function which on-runtime packs my fonts properly, and then after they're packed, indicates it's packed, and stores the map. However, I can't do that at run-time, because characters are uninitialized without manually sorting every character. I would have to code in a very specific way, which would absolutely interrupt comprehensibility in the cognitive domain, and would render builds at different stages to be coded in the specific way that I can have a 1:1 presentation for unprocessed data but processed data would be different values across builds of different characters.

Pic related. I have another which demonstrates a potential issue.

This a practical argument. Cont.

Attached: 2.png (2537x1242, 173K)

sounds gay desu

Those are logically separate procedures, you can't just swap them. And if you can then the second.

if (yes && !no)
//stuff
else if (no && !yes)
//stuff

>no docs
>doesn't explain what his code does
>random ass shit

Classic Jow Forums tier code

The BDM is more of a tale of designing something dangerous at a time where everybody expected that danger, but it prolifterating into the design of everything else.

Its the programming equivalent of 0. 0 is nothing, not there, an absence of quantity, but numerically and mathematically crucial to everything. NULL pointers are the zero of programming and you cant get away from that.

Theyre just annoying.

>doesn't know how to read self-describing code
Classic Jow Forums brainlet

Malloc on the heap
Pointer math to fill data
SEGMENTATION FAULT

me again, i want to draw, drag and resize components and stuff, is there a framework used for this kind of shit? webdev is not my thing

sounds like you just suck

At compile time, I can have different sizes for fonts. In the case of the null pointer, I can always indicate no character. In the case of differing character sizes, every character would have to have additional bounds checks included at compile-time, because at run-time, these structs are pointed to, which obscures their dimension. Every single function which could use the pointer would have to check the bounds, and this behavior would be hidden away mandatorily, or intentionally indicated by language design.

An interesting case is when cross-typing pointers, should I check before that it's valid or after? Logically, before, but then if I do pointer arithmetic I would have to know from whom I inherited the pointer, and therefore know if it's valid. Consequently, can I leave a pointer in an unsafe state? In a side-effect free language, yes, because I can know from initial conditions when a pointer value can be manipulated. As soon as I have an unsafe state, *every single time* _any_ pointer is changed at run-time, I would have to check every parent structure/object for pointers. If pointers were NOT one-time-share only, I would have to check _every single pointer_ for an identical pointer, or have a storage for every single thing which does share that pointer. However, if I did pointer arithmetic, the pointer may exist beyond the ends of a valid range before /or/ after pointer changes. In fact, I have a logical case where I intentionally point out of bounds sometimes to drastically simplify logic. Included in the pointer itself is a risk of going out of bounds of the greater data I'm editing. To this for _every single_ pointer access, the performance cost would be immense, and the memory cost might be indeterminate unless the program was re-written. And this would include rewriting every single thing. Instead, I could do one bounds check when I need it. In this case it's putting a header on a fax with padding, perfect on the bit-wise level (pexels).

Its a haiku

What the fuck are you on about? Dealing with pointers is not this complex

He has no style
A lame typeface
This pointer shows
A dangling trace

Yes it is. In the case of null pointers and a set of pointers which can reference eachother, I can always check if a pointer is valid by checking if a member within the array is null. If I don't explicitly do it myself, I have to have the pointer on deletion/move check that any members included in the chain don't reference that pointer, ever, and if they do, re-align things. If the array could be circular, I have to keep track of whether or not I checked something. If I don't need the dynamic array elements anymore I can leave them, an O(0) operation. If I go to use the arrays again, I can choose to reset everything. If I trust an unsafe compiler, it would explicitly destruct everything, or at least have to reset the pointers to sorted data - but it will run into conflict because I'm not destroying data, just moving it. In the case of movement, I have no means to indicate that the values are NOT what I want, because I only have valid pointers and invalid pointers, I don't have a pointer that can indicate something to be unused. The complexity goes through the roof, and a dynamic language would come to a screeching halt anytime data is moved or deleted, because I can't be certain if those data will be manipulated again or not, therefore the only safe way to do it is every single time or program in a very obtuse way.

I want to write an interface that connects MPV via its JSON IPC to my server.
The server is supposed to be connected with a web interface via WebSockets.
And I'm thinking about also adding IRC support.

Just started with it a few hours ago though, but this time I really want to do it

Attached: eyhtqkvyhs311.jpg (750x1188, 107K)

...

Oh I forgot to add, it's supposed to be a music player

>Just found out about this now
FUCK. I used libmpv hooked to an HTTP server to make my own janky web wrapper around a player instance. Oh well, hope it turns out well.

Would you rather have a high paying job with zero to no free time or a worse job with plenty of time for programming on your own projects?

You are WAY over thinking shit. Literally everything you just said is a hyper overcomplex explanation of handling a collection of pointers and absolutely none of it is as insane as youre making it out to be.

This is the most insane description of a statically sized linked list ive ever read

I thought about doing it with libmpv, but I remember SVP (Smooth Video Project) hooking into mpv using IPC so I wanted to try that out

Attached: oddroll.jpg (1500x1500, 417K)

>Visual Studio Code supporting a million text encodings but no ASCII
lolwut

On top of just pointers, every included code would have to be open or have some means of indicating side-effect free versus side-effect prone functions. Literally you could not include code from any language which supported unsafety without proving the program safe. Even in the case where something was indicated safe, without analyzing it (code OR a program) you couldn't demonstrate safety. A single unsafe operation would require analyzing every single aspect of the program, because anything which used the unsafe operation may not be safe. Since all forms of safety can have different representations, you'd have to check if every code provided sufficient safety.

Limiting safety sounds great, until you realize you're doing the same cognitive load as the language (knowing whether an operation should be safe or unsafe) and coding in unbalanced loads for practical reasons (which should be easier, coding safely or not?)

As soon as you say "I want the compiler to make analysis easier than I program" your computational requirements and coding requirements go up many, many times, and in some cases, would easily be O(N!) on runtime and multiple times programmer load, the limiting factor in getting shit done.

...

I HAVE HAD TO WORK THIS WAY BECAUSE OF SYSTEMS WITH NO DYNAMIC MEMORY ALLOCATION REEEEEEEEEEEEEEEEEEEEEEEEE

Attached: faxheader.png (2275x1074, 104K)

Trying to learn Ruby and Curses at the same time.

I'm having a small problem:
I want to display some introductory text, as well as receive user input, but for some reason, the text only appears after I've pressed a key.

require 'curses'

def init_curses()
Curses::init_screen
win = Curses::Window.new( Curses.lines, Curses.cols, #Set window to be as large as terminal window
0, 0) #Start window on top-left corner
win.clear
win.addstr("Type a few lines of text, or press '~' to quit!\n")
win.refresh
return win
end

$window = init_curses
input_ch = nil
while (input_ch != "~")
$window.addstr("Type a few lines of text, or press '~' to quit!\n")
$window.refresh
input_ch = Curses::getch
$window.clear
end

Holy shit dude. Format your code.

svp is cool

Also, that code is pexel precise. If I only operated on the byte level, it would be less accurate on the page and I'd have weird issues with rounding in the logic. Do it right once.

Unicode is a superset containing ASCII, though... What are you trying to do?

what is this?

I just find it odd.

It's formatted consistently except the first curly could be on the next line, and there could be a space after the function+argument

Have you never worked professionally?

Look for playlists on youtube of people coding whole projects.
Try and follow along.

Also do coding challenges like Project Euler.

What is the blackpill of programming?

I do code professionally, but I don't really know what company/style guide allows there to be columns THAT wide.

I'm just saying. Accidentally sent my post early, so I couldn't congratulate you for the cool shit you're doing. But as a favor to a friend,

The more time you put into developing a piece of software, the worse it gets.

I started out looking at C years and years ago, but Java is the language I'm most comfortable with these days.

thanks. Do you have any youtube series in particular that you'd recommend?

Sorry mate I've only used Curses in C and have no Ruby experience but I want to throw out the idea I'd have
What if you try starting the Y on 1?
It might be that the first string is printed just above the first line you actually see?

>be incredibly new
>using extremely basic html
>able to link outside links to pages just fine
>Trying to link 2 pages in the same folder together using Your file was not found
It may have been moved or deleted.
ERR_FILE_NOT_FOUND

I've been trying to figure this out for an hour now, but every site I visits tells me I'm doing everything correctly.

Attached: retarded.jpg (640x480, 22K)

Ah. I was indicated to have code less than 1280/1366 pixels wide (basically fit in a single window).

This code likely was in bad form of width, but it also was code that should never be touched again, for any reason, in the context of our work. There were quite a few improper sections, so having one out of all my work wasn't a big deal.

// in our code is comments only we internally can see, if the code is exported for custom-use scenarios, those comments are stripped. Basically you'd hope no moron who saw code this dense and horrible would think it's a good idea to fuck with it.

Also it was (and still may be) un-included code (see the ifdef? We have those EVERYWHERE because there's literally like 300 versions of the codebase, all having some subtle differences in features, to being full-on platform-different application-different sections. The code re-use was off the walls for C + some preprocessor tools in Perl. (one example is data is statically allocated by design, and if there's no use of it in the code, it's commented out in a second preprocessed header file).

Then that error makes perfect sense to have. Not that I'd ever actually care to use this feature.

>href="/page2.html>Page2"
Do you mean href="./page2.html>Page2"?

Notice the dot. Relative positioning, otherwise you're accessing the "root" folder (which may not even be defined?)

.htaccess files can also be ass, our internal server had disabled features like regex-ing folders to urls to present as different urls for accessibility (which normally prevent issues... surprise).

Sounds odd to put a heavily opinionated language as neutral.

Thanks for the suggestion... Unfortunately, it didn't seem to change much.
To test this, I put a "setpos" in the init function and one in the loop at different points, and as far as I can tell, nothing seems to be working. Might ask SO or something.
# TO RUN: >>
# ruby typewriter.rb

require 'curses'
def init_curses()
Curses::init_screen
win = Curses::Window.new( Curses.lines, Curses.cols, #Set window to be as large as terminal window
0, 0) #Start window on top-left corner
win.clear
win.setpos(30, 0)
win.addstr("Type a few lines of text, or press '~' to quit!\n")
win.refresh
return win
end

$window = init_curses
input_ch = nil
while (input_ch != "~")
$window.setpos(10, 0)
$window.addstr("Type a few lines of text, or press '~' to quit!\n")
$window.refresh
input_ch = Curses::getch
$window.clear
end

How would you use bit flags without binary operators?

Try this:
Page2
or
Page2
Been a while since I did html. Your problem seems to be a very small one of misplaced symbols.

Alright, well if the comments and the width of the code are only gonna be seen by you guys, I guess there's nothing wrong with doing that.

And all those macros you have to deal with sound horrendously painful. You have my sympathy. Good luck with everything!

This will sound dumb

When do you put the character anywhere? If it's after the window refresh, that may be why.

>refresh
>put character
>clear screen

If you are preserving previous text then I don't see why it's not redrawing everything (it would refresh before getch), but if clear resets where characters are drawn then you have a logical error.

Holy shit thanks m8. You were right. The website I'm using to teach myself has been pretty good so far, but totally omitted the period.

I said I was going to go code some lines today, but I didn't. Instead I wasted my day watching anime memes on Youtube :(

Attached: 2017-08-24 21_47_09.png (468x354, 267K)

If the bitflags are one-per-digit, then you can use equality to check. i.e. bitflagvar == THISFLAG (128).

They're not macros, they're ifdefs. We do use a lot of macros, but most of them are constants. I'm one of the only bastards who macros functions.
#define round_nearest_uint(x,n) ((((x) + ((n)/2)) / (n)) * (n))
#define round_up_to_multiple(x,n) \
(((((x) + (n) - 1)) / (n)) * (n))

What do you mean? It's like asking how would you use arrays without pointer operations. It's just different abstractions or concepts that might be mutually implementable.

Glad it worked out. I think your quotation marks were also outside of the link, so the whole time it was redirecting to "/page2.html>Page2" as well, instead of just the file itself.
This user was also on the ball.

Attached: 1533159736505.jpg (735x730, 93K)

Not one per digit. Mutually exclusive.

Is it okay for me to subject my work of having the burden of my Common Lisp programs or should I just be nice and write it in Java or C++ so people in the future won't think it's gibberish?

> ifdefs everywhere to run as a secondary pre-processing step
Does that improve build time as well as file size or is it just some horrid shit that is nearing insupportable?

Why can't C++ compilers optimize exceptions?
Consider this simple example with an extremely obvious optimization opportunity: godbolt.org/g/PDXmCt
Clearly this function always returns 2 and it's not possible for any other exception to occur in the try block, yet neither GCC nor Clang optimizes it accordingly. It does the whole throw and catch only to end up just returning 2 every single time. It doesn't even optimize the catch by returning 2 directly, it grabs the value (which is always 2) from the exception object and returns it.
What is it about C++ exceptions that make them unoptimizable?
The only optimization I've seen it do is omit the whole catch if the try block is provably noexcept: godbolt.org/g/5vTXTh

Yeah, maybe the first potential optimization seems dumb, but even the dumbest optimizations have value in generic code.

What are you on about?
Common lisp is standardized. Anyone Competent can easily pick up the language to read your code in the future.

"what is the halting problem"