/dpt/ — Daily Programming Thread

Previous: What are you working on, Jow Forums?

Attached: dpt nagato.png (934x1000, 389K)

Other urls found in this thread:

gtk.org/
fltk.org/
docs.python.org/3/tutorial/datastructures.html
seriss.com/people/erco/fltk/),
dlang.org/phobos/std_experimental_allocator.html
youtu.be/4oDK91E3VKs
youtu.be/4oDK91E3VKs#t=33m50s
social.cs.uiuc.edu/projects/vcode.html
youtube.com/watch?v=Sv_OZ174wpg
anvil-software.org/
aegisub.org/)
mpv.io/
sqlite.org/
clipsrules.net/
twitter.com/NSFWRedditVideo

anyone have good F# learning resources?

Are several bytes big automatic variables bad practice for classes?

Attached: scrot.png (650x397, 35K)

What's the best way to do keybindings? Since I'm getting an int that represents the pressed key, I figured I'd use a function pointer array to map keys to functions, but I figure there has to be a smarter way to do it.

no

Personally I have a hashable struct with the key code, the modifiers (ctrl, shift, alt) and the flag (whether the combination is pressed or not).
Then I have an unordered map where a struct object is mapped to a string, for example:

// CTRL+A
map[KeyBind{Key::A, true, false, false}] = "select_all_units";

Then I have a key press & release callback, where I find the struct based on the key and the modifiers and toggle the flag accordingly.
Next is a function that iterates over the map and checks for the action (now that I think of it, I could use string index instead and find the struct based on that and check the flag instead).
Then basically when I process what's going on in the game I just do things like:

if (keybinds.is_active("select_all_units")) {
// handle the action
}

While this is somewhat specific to C++ it should be doable in C anyway, although I'm not sure if that's a good way, just something that I came up with when making a simple game framework.

is the philosophy of statically typed languages to catch as much shit as possible at compile time?

is this why you would write software for a plane in java but not javascript?

you don't have to give up on C# because of Windows; the OS department at MS may be garbage, but the .NET department has pivoted heavily away from its formerly proprietary model into an open-source, cross-platform, permissively-licensed, community-driven development model. that means (for the first time) official first-party support on the major desktop platforms (Windows, MacOS, and Linux). these projects are all now hosted on GitHub and under active development/maintenance:

.NET Core (portable .NET framework):
- CoreCLR: portable .NET runtime / JIT compiler
- Roslyn: portable C#/VB compilers / analysis APIs
- CoreFX: portable .NET standard/foundational libraries
- CoreRT: portable AOT/native .NET compiler toolchain
Visual Studio Code: portable lightweight plugin-based code editor

>java's better for beginners
they're practically the same for the kinds of applications a beginner would write. the only real difference at that level is that C# has a much nicer syntax and is a lot less verbose

Why are you iterating when you could just store the function pointer and call it immediately?

Because I don't want to handle the events when I still pump the OS/window events, I want to do that after this is dealt with but before anything is rendered. Also I don't want some actions to execute at all times but rather depending on the scene, if I was going to go with function pointers I'd have to check the game state in each callback.

So you have a huge list of if(keybinds.is_active(...))?

yes

>is the philosophy of statically typed languages to catch as much shit as possible at compile time?
kind of. it also enables you to write robust code without a million argument checks. with languages that don't enforce typing, you have the choice between "someone passed some object into this function, let's see if we can actually interact with it as planned first" aka more boilerplate than java and "just proceed without checking anything" aka house-of-cards code.

>.h
>class
wrong

What is the easiest way in python to read a text file and return a match?

Basically I have a text file on /home/test.txt
And in this text file among other text is a phrase like n=5568 I need to save the 5568 into a variable.

Any kind soul can slap it together for me?

Sounds annoying.

A bit, technically I could use function pointers as well just fire the callbacks after I'm done with the event loop. Something I'll have to reconsider once I'm done with constraint based layout system for my UI framework.

I'm working on a media annotation application that has elaborate programmable playback capabilities. After spending a few hours with GTK last night, I've decided to have a closer look at FLTK today.

gtk.org/
fltk.org/

my memory scanner/editor

The JVM is still better because it has Clojure.

why the fuck is there no cross platform gui api for pc and mobile.
Gtk can be run with android but it doesn't work and they are not even trying to support.
Literally forced to write web apps

A good filter for programming languages is whether you can write a type-safe implementation of traverse_ in them. It's definitely not sufficient for the language to be good, but I think it should be regarded as necessary.

c gui api

qt

brainlet here (python 3)
if P is a number in a list, how would I go about removing all multiples of P from said list?

You can't "remove" things from a list, you can only create a new list which doesn't contain them.

if I cant remove things, how the fuck does list.remove() work then

Lies and impurity.

this is python not haskell

/dpt/ isn't about giving people what they want, it's about giving them what they *should* want.

That sounds straightforward enough, what are you having trouble with?

I don't know how to do it

You can't "remove" something from a list. If you have a list [1, 2, 3], and you "remove" the middle element, then you have [1, 3] which is a different list.

>a media annotation application
wat is that mean?

Idiomatic Python would use a list comprehension.

[x for x in your_list if x % P != 0]

Go through the list, add numbers that are divisible by p to a new list, excluding p itself.

no, not at all. composing types with automatic-storage primitive/pod/trivial/standard-layout data members is actually very good for performance if you need to be able to iterate over arrays/vectors (or ranges of such) of those types and operate on that data. with arrays/vectors of such types, the data will be contiguous in memory, meaning when you operate on those arrays/vectors, a lot of the neighboring data will end up in the same cache line, and subsequent iterations/operations will be able to simply pull their respective chunks of the data from the cache (orders of magnitude faster than having to pull them from system memory). for example, looping through a vector of those Entity objects to test a given hitbox for intersection against the hitbox of each Entity would be quite cache efficient

Loop through list
If list item is a multiple of P, invoke the method to remove said item from the list.

This is really basic stuff, I'd suggest googling if you don't have a clue how to do things as simple as looping through a list.

You can in python docs.python.org/3/tutorial/datastructures.html

a = [1, 2, 3]
b = a
a.remove(1)
b
=> [2, 3]
dumb nigger, remove mutates

>I've decided to have a closer look at FLTK today.
Welcome to the easiest to understand, and the most frustrating GUI toolkit in seppels.
Their documentation is top notch, but their implementation is not so straightforward.
You can use C style OOP (using a global struct to store the pointer to object) or more superior yet bloatier C++'s inheritance method.
There are lots of website that having tons of useful example (e.g. seriss.com/people/erco/fltk/), but yet you can't ask anywhere about your problem since it's a really niche library.
Whenever you encounter a bug in the library and ask somewhere, there is almost no-one that can answer you, or all of the answers are "Use Qt" and "Use GTK"

And plenty other languages like Kotlin or Scala. MS did something wrong with .NET, the ecosystem is incredibly poor compared to the JVM. And .NET Core is at version 2.1 and so far nothing has changed in that regard.

mfw /dpt/ thinks [1, 2, 3] and [1, 3] are the same list

Attached: Ren-angry.jpg (658x370, 131K)

python lists are vectors not linked lists, its not allocating a new list or anything

my face is the same when /dpt/ thinks [1, 2, 3] and [1, 3] are the same vector

quit being a retard and confusing identity with value
a list's contents can change and it remains the same list. mutability exists.

>its not allocating a new list or anything
Even if it were the point of using a high level language such as python is to remain oblivious of such details.

>mutability exists
mutability is a lie. the real world is immutable

>2^31-1 is one of only four known Mersenne double primes
what the FUCK

null_ptr = null = NULL = void = *void
defend this C++

Anyone have a cheeky workaround for paramaterizing an array in Java? eg I want an array of lineArray = new line[size];.

Doing it without the gives a warning about unchecked conversion which shouldn't ever come up as an issue in production but I'm submitting this as part of an application and would rather not have a warning/not just suppress a warning

you can use the diamond operator in some cases

let newList p = filter (\x -> not ((x `mod` p) == 0)) oldList
If the source list is not defined then
let noPinList p oldList = filter (\x -> not ((x `mod` p) == 0)) oldList
if you use it in a source file, instead of interactively
noPInList :: (Num a) => a -> [a] -> [a]
noPInList p oldList = filter (\x -> not ((x `mod` p) == 0)) oldList

/=

Reminder that if you use Windows you're not a real programmer.

Why are MySQL Insert queries so fucking slow.
CREATE TABLE new_table SELECT Id, BookDate, TRIM(Data) AS Data From old_table[\code]
Been running for an hour. Where as the SELECT only takes 10 seconds. I don't get it. Table only has 100,000 rows.

Thank God.

1) Shouldn't that be Integral instead of Num?

why is ahk so shit. i just want my script to pause while im holding a mouse button. literally impossible.

>not using the superior autoit
baka desu senpai

Explain. Java's problems are those of the JVM. It is very limited compared to the CLR which has first class support for hardware intrinsics where you can also supply hints for the JIT (no need for setting flags on the executable), dynamic shit (DLR which enabled it to have first class support for scripting languages like python and even scheme), value types, generics, pointer arithmetic and interop.
The jvm runtime is highly focused on making a good JIT(hence GraalVM aot produced embarrassing results on benchmarks) but the CLR is focused on all aspects. In just three years .net core made very impressive progress and it is showing no signs of stopping whereas the JVM is still growing and now considering value types.

>the only real difference at that level is that C# has a much nicer syntax and is a lot less verbose


C# as a language is a lot more bloated. Java has a few keywords and you are good to go. Java also performs better and intelij crushes vs code. C# is a meme for MS cucks.

huh

Threadly reminder that dlang-chan is not dead; she's going to have her GC tumor removed (eventually); and she's super duper cute and easy to prototype in! Say something nice about her, /dpt/!

Attached: 1501665523402.png (470x545, 336K)

you can't just take some anime character and start using it as mascot for shitty language.

D is dead

>Any nonvoid function has to have a return statement in it. If you do not put one in, the compiler will tell you that it is missing.
>mfw don't put one in and the compiler says it's fine.

Attached: 1412432337111.png (528x498, 186K)

based compiler bro

I have been programming for a while but only in C and C++. What's a good book for me to learn Javascript?

>she's going to have her GC tumor removed (eventually);
source or i'll call it fake news

It's a thing now, it's been posted a lot. I'm fine with it.
>still having GC removed
Has it been two years now?

When is dlang.org/phobos/std_experimental_allocator.html gonna integrate with builtin operators?
It's genuinely something I love the prospect of.

youtu.be/4oDK91E3VKs
I think he leads with 'the garbage has to go'. Or something.

dumb frogposter

Attached: dlang chan.png (470x545, 319K)

i won't consider this a source unless you give me the exact timestamp where he says it

In C, variables that go out of scope are deallocated automatically or do you need to autistically call free() everywhere?

You have to free them manually. C doesn't have RAII

You'd have to be a dense person to not be able to search auto-generated transcripts.
youtu.be/4oDK91E3VKs#t=33m50s

the stack pointer is decremented and incremented automatically when you declare local variables, but any pointers you get from heap through malloc or other means you gotta free yourself.

>autistically
If you want to have a piece of memory allocate and deallocate in the same scope you're probably doing something wrong. Or using the wrong level of language.
But yes you need to call free on heap allocated memory.

unreliable, especially considered Andrei's English and the technical language involved

Where do I start with basic web dev? I haven't made a website since the 90's (Geoshities), but need to do one for a side project and another one for a company I am starting later on down the road.

No fucking clue where to start.

The transcripts?
Or are you claiming his clear English is unintelligible?

I see, thanks.
I specifically said "out of scope".

we need to compile a list of actually cool programming projects

1: a motion detection security camera that uploads video clips to a remote web server

local variables yes

but anything that gets malloc'd also needs to be free'd exactly once or you get a memory leak

2: a neural network that automatically generates porn tags, title, description for a video

Anything that involves procuring actual physical hardware is too much effort.

how common are big endian cpus nowaday?
>need to patch some 3d model file format stuff for a popular widely used game engine
>their format doesn't account for endianness
>"nah must have missed something"
>test it
>engine explodes on big endian cpus
made by chinks, of course

everyone has a webcam, that's not something you procure

I think they're only used on mainframes nowadays.

If you try to read outside an array's bounds will it always segfault or is it implementation/OS-dependent?

Attached: 1509676997467.jpg (270x400, 104K)

yes, transcripts. i'm not questioning what he was talking about

Not everyone, and specially not tech-savvy people if they can help it.

the boring project list is for them, then

"Implementation-defined" has a specific meaning in the standard. It describes the behavior that, although implementation specific, has to be valid and clearly documented by said implementation. Access outside array bounds isn't that, it's "undefined behavior", meaning anything could happen and the implementation is not obliged to tell you what. And in practice, it doesn't always segfault. Sometimes it will allow you to read past the buffer, and there may be anything out there. Heartbleed exploited that to read sensitive data.

Depends on the language first of all but if we're talking C it's UB if you read outside allocated memory. And that's OS/platform dependent.
You certainly don't always segfault. Usually you segfault when you hit a page boundary but if unfortunate you'll just hit another valid page.

So be careful. Don't be afraid to write an indexing abstraction.

Well OK, thanks. Yes it's C.

social.cs.uiuc.edu/projects/vcode.html
youtube.com/watch?v=Sv_OZ174wpg

anvil-software.org/
...etc.

Imagine something like a subtitle editor (aegisub.org/) but arranged such that a more elaborate variety of description can reference frames of time of the video (or audio) track. The architecture I have in mind will use libmpv as the media player with annotations stored in an SQLite database. Also, what I have in mind is quite a bit more elaborate in its capabilities than the other systems linked above - I am seriously considering an embedded rules engine (CLIPS) for the scripting interface.

mpv.io/
sqlite.org/
clipsrules.net/

>And plenty other languages like Kotlin or Scala
Those only came to exist because Java is an unparalleled shit to program in.

Use PostgreSQL or MariaDB. MySQL is shit slow.