/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

developer.apple.com/documentation/uikit/uitableview/1614891-dequeuereusablecell
en.wikipedia.org/wiki/SMART_criteria
twitter.com/NSFWRedditVideo

First for anime

:(

Second for fuck anime

How do I do reverse hostname lookups in a non-blocking way (with epoll)?*

>I use C

Kernel module for mapping userspace buffers and setting up IOMMU domains

Made this little status page for my Raspberry Pi

Still have some functionality I want to add such as hot reloading of the text values and some new fields

didn't see the new thread

Right now I'm focusing on Swift since there seem to be a lot of small startup companies in big cities that will hire someone like me if I can get the job done and will take a "modest" salary. I have a lot of ground to cover still but at the very least I have a few apps in the pipeline and I can churn them out without much trouble. My main issue right now is that I've learned everything I know from tutorial projects and I don't actually understand the process of going from reading docs to truly learning and implementing something on my own without a separate example—I learn almost entirely by doing and by example. I'm actually really fearful that I'm not cut out for this because of that.

>pic is me

I think that current versioning approach sucks.
We have fat modules that export dozens or even hundreds of functions. Each library update can add/improve some function and break others at the same time, so upgrades become dangerous.
It is a bad and painful approach. Instead, it is possible to split modules into completely independent functions. One module = one function. This way dependencies could be updated independently.
Of course, it requires very strict and reliable compiler/type-checker, but we have these type-checkers nowadays. And the evergrowing tower of functions is not a problem — we already have it, just look at github. Functions are there, every version of each function, we just need to split them.
Why don't we use this approach?

>Ayy that sounds pretty cool.
Ideally, yes. I was originally writing an IDE from scratch in C++ using the Qt toolkit, but I'm not comfortable enough with C++/Qt to be confident with things like paint events, custom widgets, etc. I mean, I could technically create a custom widget, but I'm not sure how reliable it would be, and I figure that using HTML+JavaScript+node.js would save a lot of time, though I would have to run the map and sprite editors in separate windows. The official IDE is Windows only, written in C#/.NET and doesn't play nicely with WINE/Mono, I guess this is better than nothing.

would you please consider writing an open-source alternative to IDA instead

>open source IDA
radare?

Here's a screenshot of the C++/Qt IDE in its current state. It has tabs, but you don't see any because there aren't any files currently open when I took the screenshot.

What is that?

>why don't we use this approach?
Ignoring legacy reasons there's standardization issues. Like how almost any vector math related framework defines their own vector/matrix types. If you have modules at function granularity you run into those problems. It can be dealt with of course but you'd have to implement all the modules at a level of abstraction that'd let the user define things like access. Think object programming where your functions will do all their work through overloaded functions. Or equivalent.
Ignoring how algorithms guide datastructure choice and vice versa. It's a bit messy and puts a lot work in the hands of the programmer. I don't mind that at all personally but frameworks have this trend of doing the opposite. Forming your code to their solutions rather than the other way around.

I'm not saying it's a bad idea though. Just not fit for some things.

And if you're gonna rely on this very well developed type system you can alleviate a lot of that work.

...

man I could never get into IDA
it's so different from my years of experience with ollydbg

A stack-based VM for embeddable scripting languages. It can be programmed directly in a (somewhat) Forth-like language, but it provides a C JIT compilation API to be used by user ESLs. The core idea is to enable easy interop between multiple domain-specific scripting languages within the same host application through the shared argument stack. It provides native support for an object system that is lightweight but highly customizable and extensible (through the use of meta-objects), so objects can be directly shared between different ESLs with potentially different object systems.

Here's the definition of the basic operators of the stack language in terms of itself.
defun # >> compile-call end
>>
# get setmac

defun peek >> dup >
defmacro get setmac

defmacro ' >> compile-literal end

defmacro !call call end

defmacro ! >> get # !call end

defmacro !>> >> end

defmacro ## >> compile-literal ' compile compile-call end

defmacro if
## not
# ?jump
end

defmacro endif
# resolve:
end

defmacro else
# jump
swap
# resolve:
end

defmacro while
# label:
end

defmacro do
## not # ?jump
end

defmacro repeat
swap
# jump # to-label
# resolve:
end

defmacro /*
while
>> ' */ = not
do repeat
end

/* now we can add C-style comments! */

defmacro {
## {}
## dup
>> compile-literal >> drop
## swap
end

defmacro ;
## swap
## setf
## dup
>> compile-literal >> drop
## swap
end

defmacro }
## swap
## setf
end

So I found csc.exe on my computer, which is a built in C# compiler. I didn't realize one comes essentially pre-installed on the computer. I was wondering if anyone else knows what other compilers come by default on windows (i.e. without having to download one). Any C++ or C compilers?

>I was wondering if anyone else knows what other compilers come by default on windows
Your installation may include MASM32 if it's 32-bit windows.

>Any C++ or C compilers?
no

It is 32bit. Will look into this. Do I need a linker though as well?

Damn, that sucks, but thanks for the info user

Anyone here familiar with Elisp?
I'm getting some data from a url with url-retrieve-synchronously and storing it in a variable, when I get a description of that variable it says it's a #, how would I go about accessing/using that data/buffer?

Any advice?

dick in fan perhaps?

Never mind, got it.

1. Avoid retarded OOP taxonomies. Sooner or later you will find objects that don't fit neatly on any branch, and the you will find yourself either duplicating functionality, or moving it up the hierarchy (thereby imbuing healing potions with the ability to shoot fiery arrows).

2. "Attack" and "use" methods are pretty useless. Good luck having a common interface for every possible kind of "use" and "attack" without passing them the entire world.

What, that's not how it works you dumb faggot. Switch cases are literally the easiest shit ever to implement as a jump table, and show me a compiler that doesn't. It even perfectly implements fall-through behavior, and a "break" literally becomes a jump instruction if it exists.

There is *NO* reason why what you're saying would be true. Even uncomplicated if-else chains are usually optimised to jump tables.

reposted:
That's exactly what I can/am doing, my point is that I'm not able to do the original research myself. It's very easy to do what you're describing, but reading the original docs and figuring it all out for myself seems so complicated. Sometimes the use cases for any given part of a library seem so abstract but when I see it used in a program I grasp it almost immediately.

I guess what I'm getting at is that the people who wrote the tut were able to synthesize the docs and put it into practice whereas that task for me seems daunting. When I look at e.g. info for a class in Apple's official docs, it's this giant smattering of info, whereas when I look at an example it takes a few seconds to get it and that's it.

Example:
developer.apple.com/documentation/uikit/uitableview/1614891-dequeuereusablecell

Looking at this I can get the gist of what this does but coding something with this info is impossible for me. Taking a cursory glance at an example and I immediately understand and retain the info. But I wouldn't have been able to get there without some other guy having written a tutorial for me.

>jump table
Nice made-up terminology, faggot. Even if it's real, no compiler implements it. Prove me wrong. Protip: you literally can't.

Wouldn't it still iterate through the table? I don't know how hashmaps work, but I think evan they use some form of iteration.

Do you hate your eyes user?

>2. "Attack" and "use" methods are pretty useless. Good luck having a common interface for every possible kind of "use" and "attack" without passing them the entire world.
...you'd obviously just be passing them the entity info or whatever, why would you have to pass them the world

this is a silly response, sir, and you are quite silly

...

IS IT JUST ME OR CPPREFERENCE IS ALWAYS BROKEN?

what are some prerequisites to get into reverse engineering

Pic related.

No, it just hashes the input number into either absolute or relative addresses, then jumps to it.

That's fine. No one is expected to learn how to use a massive library by reading through the class/function reference. The function reference only becomes useful when you have some background and general understanding of what's going on and need to verify some small details. You wouldn't read the C standard to learn how to program in C.

Does any actual compiler generate hashed jump tables? I know they generate array-like jump tables for sequential values, but having a hash function in there seems like it complicates the performance story a bit

>Do you hate your eyes user?
No, but that code is supposed to be hairy. It literally defines stuff like "if", "while" and comments using more basic primitives. More normal programming isn't too bad when you get used to it, but the stack programming language isn't the point of the project anyway. You can ignore it entirely and just use the JIT API to implement your own language.

I think he was talking about your theme for emacs

>That's fine. No one is expected to learn how to use a massive library by reading through the class/function reference. The function reference only becomes useful when you have some background and general understanding of what's going on and need to verify some small details. You wouldn't read the C standard to learn how to program in C.
I appreciate the response—that totally makes sense—but what follows from that? I mean, if that's true, then how does one learn about (as in my example) dequeueReusableCell in the first place? I personally learned about it by looking at someone else's example, so where'd that guy learn about it?

You're right in that this class reference is great once I already have a general understanding of something, but how do I get that general understanding in the first place?

That depends on the complexity of the input (e.g. if you have a 200 case long switch statement with massive spaces between the cases then probably not). Array-like jump tables are the easiest, but it might also just do something like input % 10 if the compiler finds that there's 10 inputs and all of them would differ if a modulo was used. It would then add, multiply or something to translate it into a usable address.

That's the gist of it anyway, as we all know compiler programmers are wizards and the compiler can do more complicated hashing than that.

>you'd obviously just be passing them the entity info or whatever, why would you have to pass them the world
Try reading before you respond. I didn't say every "use" or "attack" method needs the entire world. I said it's difficult to implement a sensible common interface for every possible use case. Sooner or later you run into something that needs more than just "the entity info" and then you either have to refactor or to use some vile hacks to pass it into the method indirectly. If you really want to do this, at least use a struct to pass arguments so you don't have to change 100 method calls when this one method of this one object needs an additional argument.

Assembly, understanding low-level Windows internals, and C probably. What specifically do you/would you reverse engineer?

My apologies

Can we be friends? Do you use IRC?

>I mean, if that's true, then how does one learn about (as in my example) dequeueReusableCell in the first place? I personally learned about it by looking at someone else's example, so where'd that guy learn about it?
I don't know about Apple's GUI library, but those things are often so big that entire books are written about them. That's probably how the people writing the examples and tutorials learn.

Oh, and a hash function is likely more performant than evaluating several conditional statements, especially if memory access is needed to evaluate a conditional. Remember that with a hash function you can do everything on the CPU using the registers, and when the hash function has run it can just instantly jump to an address.

What you're basically doing is comparing O(1) to O(n). It has a higher computational cost for the "iterations" it does, but it also has just one iteration and will beat *any* O(n) as n increases.

>I don't know about Apple's GUI library, but those things are often so big that entire books are written about them. That's probably how the people writing the examples and tutorials learn.
Alright, so, to be more specific, I'm following this neat tutorial series at hackingwithswift.com. The guy seems to have tuts ready the day that Apple releases a new language feature or library.

Example: they came out with those bluetooth node things that some stores use to interact with their app, and he had a whole app ready for it immediately

I'm just wondering if in general the language authors put out some kind of materials that devs usually use, something standard/common practice, etc.

Again, I'm a noob, so any general info is pretty helpful

A linux-based image processing application? Could you elaborate on what you're building there?

That's great and all, but it sounds like you don't know of any actual compiler that generates hashed jump tables

So use a strategy pattern?

Looks more like a component-based design than a traditional class hierarchy.

Photoshop destroyer

>I'm just wondering if in general the language authors put out some kind of materials that devs usually use, something standard/common practice, etc.
That's usually the case. API authors will release docs with an architectural overview and usage examples in addition to plain class reference. Sometimes it's somewhat lacking, so people will figure things out by experimentation and then share this information, building up a knowledge base that experts compile (along with their experience) into more easily-digestible books. If you're just staring at an API reference and it tells you almost nothing, there's nothing wrong with you.

en.wikipedia.org/wiki/SMART_criteria

>melee_weapon inherits from weapon inherits from item
>Looks more like a component-based design

It's basically a kind of tkinter frontend to PIL and Scipy ndimage. I tried to emulate microscopy image processing software like Zeiss KS400 and Leica QWin but make it portable and free (python based) but still retain the macro functionality so it generates the code as you run it.

Sorry, I meant that looks more like what he wants

>So use a strategy pattern?
To do what? How does it solve the problem?

>If you're just staring at an API reference and it tells you almost nothing, there's nothing wrong with you
good to know, thank you! I was worried that I was too stupid for this

>Try reading before you respond. I didn't say every "use" or "attack" method needs the entire world.

To be fair it did sound like you were implying that. I get your point, but it didn't come across as well as you would think.

His point is that at some point you have to pass more than the entity information, and eventually, "the world".

>His point is that at some point you have to pass more than the entity information, and eventually, "the world".
Would you mind explaining why? Thanks.

>To be fair it did sound like you were implying that
I said:
>Good luck having a common interface for every possible kind of "use" and "attack" without passing them the entire world.
The implication being that the only sure-fire way to implement a common interface for every possible situation that might come up is to just pass everything just in case. It's a little hyperbolic, but I don't see how you can ignore the first half of the sentence and then act baffled about the second half.

??

It's just you

>Any advice?
Burn the paper. Write your bullshit. Apply critical thinking. Learn something. Repeat.

>Burn the paper. Write your bullshit

How am i going to write of i burned the paper?

Because at some point the definition of "attack" expands. At first it's just swinging a sword, but then later you find that someone needs to fire an arrow and suddenly solving the previously simple problem of "attack" in a single function is far more complicated. You are forced either to abandon your idea of a single function call to attack, rewrite it to become just a dispatcher depending on the weapon type or abandon implementing ranged weapons completely.

>It's a little hyperbolic, but I don't see how you can ignore the first half of the sentence and then act baffled about the second half.

I had no problem interpreting your point, I was just saying that with a different mindset I may not have (e.g. pass the literal game world into the function).

The brainlet is trying to say that planning is bad, and that you should write bad code, learn from that, and write bad code differently next time.

...

I've been working on webm related for a few months now. The idea is that you get programmable brushes, these become ridiculously expressive as symmetry, color and orchestration are fully programmable.

It's quite interesting to explore what you can make with this weird software.

You do it without the paper. The less you remember the better. Looking at something like that for guidance is a mistake.
You have no user code right now. You have no idea how this system will actually be used or what your actual requirements are. If you instead let your system develop naturally you end up with a better solution. If you write something like that you're much more likely to stick to it. As if it was a good idea. But fact is that future you will write a much better plan for you.
Don't get me wrong, there's planning in software. But you're at a granularity and an uncertainty level where you will simply not be able to productively plan for yourself.
That's the best way to learn is it not?

draw me user!

I'm not a drawfag tho :|

The fuck do you look like?

>You have no idea how this system will actually be used or what your actual requirements are.
> But you're at a granularity and an uncertainty level where you will simply not be able to productively plan for yourself.
What frustrates me about your post is that it's not completely wrong. You almost seem to get it, but somehow you miss the fact that what you're saying constitutes prior knowledge in and of itself, and this knowledge can be used to plan ahead, and should shape your design requirements.

Also, the suggestion I have for you is to start writing your program without a detailed specification of what function does what just yet. You can have a general overview of what the program should be doing, for example you should probably have a loose idea of what the game loop does and what the game rules are, although they should be up for modification later.

It is much easier to write a program and see where you're actually duplicating code, then write a generic function for *that* than it is to try to fit a square brick into a round hole by determining before you even wrote a single #include statement what should be generic and what shouldn't. What you're doing is comparable to premature optimisation, except it's premature generics. It's exactly how a lot of OOP projects turn into a spaghetti hellhole.

>You almost seem to get it, but somehow you miss the fact that what you're saying constitutes prior knowledge in and of itself, and this knowledge can be used to plan ahead, and should shape your design requirements.

But the design requirements aren't what you think they are. The design requirements are roughly how the game loop should behave, the rules of the universe and partially the physics. They are not which function should be generic or not, and an "attack" function should be considered part of the game rules, not a pre-specified function.

>But the design requirements aren't what you think they are
>an "attack" function should be considered part of the game rules, not a pre-specified function
If you scroll up, you will find a post of mine specifically cautioning him against "use" and "attack", and you'll also find a band-aid fix that doesn't address the core of the problem, but does illustrate a basic point about acknowledging the possibility of change and planning ahead for it. The answer isn't daunting eternal refactoring. The answer is flexible design.

I agree with you, I think we've been saying the same thing all along.

I guess that's a fair point. This isn't perfectly general advice and does rely on user making choices himself that will influence the end result. But I don't think that throwing a dart at a map as he has done here is a good way to navigate when exploring a design. It's wiser to at least try to sense if you're getting closer. Even if you're not good at it.
I'm not sure why you phrased your post in such a patronizing manner though.
>and should shape your design requirements
No. That's a terrible idea. Don't shape your design after ability like that. Especially not in api design. There's areas where you should perhaps take a step back but that's in the higher level goals. Like how user should probably not make the fanciest looking MMORPG as his first video game. I don't think there's much user could arrive at as solutions to his problems that'd be out of his reach really.
>eternal refactoring
People are way too afraid of rewriting code. As long as you're understanding the problems that made you rewrite you're fine.

Soon

Well, here's your left eye (albeit a tad green)

>No. That's a terrible idea. Don't shape your design after ability like that. Especially not in api design.
The point is not to create a full-proof API that plans ahead for every possible change. The trick is to always keep a clear separation between core functionality and "plumbing", and to make the "plumbing" as flexible as possible. Duck typing, late binding, first-class messages, avoiding direct communication between entities and using broadcast channels where possible, separating state from functionality, building up both state and functionality from small and independent components, prototype-based inheritance - these are all conscious decisions design choices you can make on the basis of your observations that will save you a lot of refactoring.

We have entirely different attitudes to software and I don't think it's productive for us to talk anymore.

cute!!!!

cool!
there's a krita tool that has similar functionality called "multibrush", doesn't do exactly what you're doing though

>different attitudes to software
>I don't think it's productive for us to talk anymore
Given that your "attitude" is to refactor code ad nauseam, and that you don't seem to have any interest in trying to avoid this, you're probably right.

Does /dpt/ write up their resume in LaTeX?

One last thing I want to note: when you give advice to newbies, give them a heads-up that your advice entails continually rewriting code (and see if they still want to follow it).

no, I write it in a custom dsl I programed

Ah yeah, I'd expected Krita would have something like what I'm building. Though, symmetry is not really my point with this thing.

I'm really aiming at getting the most expressiveness out of a single stroke.

Yes

Hey /dpt/. I have a big struct (C) in main containing shared information. All functions declared in main use it. Should I pass a pointer everywhere and clutter the signatures, or should I make an evil global?

...

I got some reference books for learning C++14 from a friend. I know C++17 just came out, and I was wondering if the books are still good or if too much has changed.

std::gcd
if (auto x = someVal(); x < checkVal){}
auto fn (auto x, auto y) {}

>I got some reference books for learning C++14
Be a good goy and buy a C++17 book. Our new version of the language has some new and exciting features. Don't mind the fact that they've been available in every other language for the past 30 years.