/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

doc.rust-lang.org/src/std/collections/hash/map.rs.html#547
twitter.com/AnonBabble

First for Rust.

AS3 is best language
1, 1: true
2, 1: false
2, 2: true
1, 2: false

Working on a list like interpreter

W-why?

Because this is a thing:
(12 == 12) == true

sometimes outputs
false

Hey /dpt/
I've got an internship at a software engineering company, and they've assigned me to write the bootloader for an embedded device, running on a Kinetis ARM processor. I've never done any real embedded work before, although I have written a fair amount of toy programs and games in C.
Does anyone know how to make the GNU linker put a certain static library (i.e. a .a file) between two addresses? I've been reading the linker manual and a lot of it's really fucking complicated. I need the .a file to be our main application code, where the bootloader can overwrite it (from an external source) while running. Am I going about this the wrong way? Any resources on the subject would be appreciated.

Hey, that looks pretty good! What's next for it? Maybe defining symbols, or lambda expressions?

Is there a better way to do this?

pub fn find(&self, name: &str) -> Option {
// ...
}

// Don't want to duplicate code, do an unsafe cast to &mut T
pub fn find_mut(&mut self, name: &str) -> Option {
if let Some(entry) = self.find(name) {
unsafe {
return Some(&mut *(entry as *const Entry as *mut Entry));
}
}

None
}

>list like interpreter
Nice, but it's really a trivial thing to write, there are more lisp interpreters on GitHub than lisp programmers in the world. Try writing an interpreter for a language with a syntax next time, it's more interesting.
AS is a variant of JS, isn't it? It means it doesn't have integers and every number is a double, meaning all you have to do is to use some epsilon to compare two numbers, there's no need for all these horrors you've written.

Not that guy, but I like writing LISP interpreters, you can spend time adding language features, rather than wrestling with a parser generator

It does have ints, its an ECMA dialect, yet its made especially for games and shit, so types and type safety is pretty good.

Its just that the bytecode sometimes fucks up, those checks fix that issue

Its hardly useful 99% of the time, but for shit i really need to get right, its a lifesaver

Even better, see pic related
On a more serious note I'll probably do more symbols, environments and lambda
It's the first time I write something like that in C, it's better than the retards posting fizzbuzz

>Don't want to duplicate code, do an unsafe cast to &mut T
Why the fuck would you do that? Do you use const_cast too?

Holy shit shit language is disgusting

Why? because I don't want to fucking duplicate my searching code maybe?
If you know how I can do that without doing unsafe stuff, I'd love to hear it.
Try properly reading the posts you respond to before you respond to them.

I'm sick of people just skimming posts and responding with something retarded and making an ass of themself, it happens way too often here.

I've read your post and you being lazy isn't an excuse for writing unnecessary unsafe code. I can't give you a concrete advice without knowing the context, but Maps in the standard library don't use unsafe for this: doc.rust-lang.org/src/std/collections/hash/map.rs.html#547 .

Is there an image editor that is somewhat ignorant of it's frontend? Like xi-editor modular structure. Or is it impossible for image editor to be efficient and not rely on specific frontend shenanigans? I am gonna look into aseprite later, at least it supports allegro and skia

>but Maps in the standard library don't use unsafe for this: doc.rust-lang.org/src/std/collections/hash/map.rs.html#547 .
And Maps are very different to what I'm doing.

I just have a simple find method that returns a reference, and I want a mutable version of that to return an mutable reference.
You're basically saying I should implement the same logic twice, every time I want a mutable version of a method. Fuck off.

No, what you did was ignore my original question and offer bullshit. My six ITS certs give me a comfy understanding of hardware and firmware. I know some assembly stuff as well.

I was asking for programming projects in some relation to my current skill-base.

Your solution read like: "Hey, I know you're an active programmer using some of the industries top-used languages, and your question was asking for projects possibly related to said languages, but instead I'm going to offer the idea that you should ditch those interests and pursue an entirely different language that you have already worked with in college, but maybe this time you should really go deep with it. Otherwise, give up on being a real programmer."

Man, I was just looking for more serious side-projects to work on. My job has me developing software for a medical information system, which is cool and all, but I wanted to see if you guys had any ideas of what I could write, at home, as a more involved project. Instead, I got shit.

Oh well, back to the Stack Exchange / Reddit. At least the levels of glorified smart-ass are a bit lower on those sites.

>what you did was ignore my original question
Your "original" question was irrelevant. No I don't fucking const_cast

>and offer bullshit
Huh?

>Your solution read like: "Hey, I know you're an active programmer using some of the industries top-used languages, and your question was asking for projects possibly related to said languages, but instead I'm going to offer the idea that you should ditch those interests and pursue an entirely different language that you have already worked with in college, but maybe this time you should really go deep with it. Otherwise, give up on being a real programmer."
What the FUCK are you talking about? Are you even responding to the right fucking post?

it's a pasta, user

oh

Well, you could start with explaining what it is you're trying to do besides two empty methods.
>You're basically saying I should implement the same logic twice, every time I want a mutable version of a method. Fuck off.
No? I'm saying you should look at the standard library does it without unsafe, before being a dumb C-toddler and casting constness away.

>I'm saying you should look at the standard library does it without unsafe
The standard library also does some pretty fucking stupid things too, like wrapping what should just be a simple return into some hackish wrapper object just to abstract around the mutability vs immutability. Your map link is a good example.
I refuse that level of complexity. Keep It Simple, Stupid.

How do I start with Haskell?

> wrapping what should just be a simple return into some hackish wrapper object just to abstract around the mutability vs immutability
It's not stupid as long as it increases safety without producing any run-time overheads.
>some pretty fucking stupid things
>hackish
Said she, silently casting constness away.
>I refuse that level of complexity.
Why do you even bother with Rust then? There are plenty of languages for ones like you.

what are some good resources for learning APL?

pac-man for ants?

hey guys, guess the game i am working on

(fixed ≧◡≦ )

>Why do you even bother with Rust then?
Because C is extremely unproductive for userspace.
C++ is terribly designed and shit to use.
I've used both of the above for years btw, wrote a kernel in the latter.
I really like Rust and it's ideas but the safety can really get in the way some times.

Honestly I think the immutable by default thing is pretty unnecessary, and not a source of bugs.

I'd like a language that has traits, pattern matching, enums as tagged unions, a good toolchain, not garbage collected, RAII, rivals C in performance, modules, and can write a kernel in it, but doesn't care about safety.
Ada is completely out of the question since it has trash syntax and is ancient and unused.

>mfw i found out knuth was from my hometown
based

> I'd like a language that [...] doesn't care about safety.
Stop being a whining pussy and start using modern C++.

Looks like Galaga.

>mfw smooth brain

>No traits
>No pattern matching
>No enums as tagged unions
>No good toolchain
>Slower than Rust in benchmarks
>No modules

No thanks.
I mean, they seem to be stepping in the right direction with adding std::optional and std::variant in C++17, but they're still lacking a lot of things. Maybe C++ will be good in 203X or something when they've copied most of Rusts good features like they're doing now.

They don't even have concepts in yet. LMAO.

>he doesn't recognize Donkey Kong
>being this newfriend

Well, it looks like you have no choice but to get used to immutability by default and the proper ways to deal with it while hating Rust for forcing you to write slightly more correct programs.

unsafe code != incorrect code.
My code is correct because it upholds Rusts assumptions about the semantics of mutable and immutable references, therefore it's correct.
The unsafe code is just an implementation detail, it's self contained.

There's plenty of unsafe code in the standard library.

>Galaga
galaga? for real? ( ̄ω ̄;)

it's pac man ᗧ · · ·

Best XML parser for C? Preferably a single-file library,

libxml
it's most likely already in your computer (if you use linux)

Sorry, user, I am more into, you know, programming and shit than videogames

Yeah I've got it, but it just seemed like a huge thing when I took a look at the repository. I just wanted something like rapidxml (which is C++) which you can just compile as part of your project since it has such few files and link statically without thinking.

The wikibook
Install stack

yeah but if you target is a linux system it'll most likely be installed

>XML

I'm targeting both Linux and Windows, and in any case I don't like relying on stuff being installed on the user's PC, I would rather link statically.

I didn't make this choice.

>a kernel developer
>giving his opinion on text serialization formats
Why should anyone care?

Want my opinion instead then?
XML is complete and utter trash.

Use TOML or JSON.

>not reinventing the wheel
your brainlet genes are showing

>>a kernel developer
not only, he also made git

>What are you working on, Sup Forums?
A weird mixture between text adventure and roguelike. Instead of tiles, you have connected rooms containing items, npc and (possible fragile) objects you can use to take cover.
It probably helps that there are guns.

It's actually reason enough to disregard his opinion, t b h.

>Nice, but it's really a trivial thing to write, there are more lisp interpreters on GitHub than lisp programmers in the world. Try writing an interpreter for a language with a syntax next time, it's more interesting.
this
but also
>, it's better than the retards posting fizzbuzz

lel, sure, and you, what have you have done?

can someone post the /dpt/ programming challenges/exercises plz

this, it's not as terrible as cvs, but it's sure a guts-outside system

How do we know how many entries in the array of char*?
char* t = { "/lit/", "Sup Forums", "Sup Forums", "/op/", "/is/", "Sup Forums", "/faggot/" };
sz = sizeof(t); // returns 28


Just make a division on 4?

You should maybe learn how to program first

>char* t = { "/lit/", "Sup Forums", "Sup Forums", "/op/", "/is/", "Sup Forums", "/faggot/" };
That's not a valid initialisation.
char *t[] = { /* ... */ } would be the valid way to do that.

wtf that's not how this works

or char **t = { ... }

what exactly is the use of stacks and queues? lists are fucking amazing

sizeof(t) / sizeof(char *)

No, that's wrong.

Lists tend to be destructive to cache performace, because nothing guarantees entries are close to each other in memory.

Beg my pardon, that was a typo, I slept for two hours and missing things like that.

>what exactly is the use of stacks and queues?
undo/redo and job lists, if you need a high-level example

but aren't stacks and queues basically lists with sets of rules to add/remove?

Stacks and queues are abstract data types, and don't say anything about how they're actually implemented.
For example, it's extremely common for a stack to be implemented using an array.

No, that's entirely dependeng on the implementation. Both could have a linked list used internally, but it could just as well be an array.
Anyway, they're not really comparable. At least I don't think of queues or stacks as "containers" in the same sense I would think a linked list was - you build and use them sometimes to get a specific job done (inserting or deleting in a specific order), not really to just store stuff.

in the C++ standard library you can specify a container for the queue/list/vector/whatever
you can even use your own if you need to

...

thanks for the answers, i had no idea you could make a stack using an array

No rolls please, use this
shuf -i 1-228 -n 3

gl with your snake game
don't forget to post it here!

>rolling
winfags will defend this

Any OpenGL people here?

If I want to write a 2D renderer that can render thousands of sprites and is portable to older machines (so OpenGL 2.0 or something close), should I be
a) Building a software-side buffer of sprite vertices every frame, then calling glBufferSubData() to buffer it up or
b) Use glMapBufferRange() somehow?

I have used the first approach before but it seems like its a lot of redundant memcopying. Or is it?

Do you guys like to write documentation for your programs?

My code is self-documenting.

how is it that v3.0 has more exercises than 4.0?
fix your versioning system /dpt/

Higher version number != more features you idiot.

look at the file names "idiot".
3.0 is later than 4.0

...? You're using the file names as your measure of time?

pokeymanz gho

Reminder to never use offensive or inappropriate language in your code, not even ironically, not even for your pet projects.

I actually did this it but I used Rust+glium so I don't think I can be helpful that much, still tho.
I used uniform buffers to store parameter for each sprite type (offset in texture, size in texture, size on screen), and I used vertex buffer to store data for each individual sprite (position, transformation matrix, scale, ID of sprite and # of frame in the sprite), then in the geometry shader I created a quad for each sprite on screen based on this data. I think this is the most efficient way of doing it, but I'm not sure if my uniform buffers are being memcpy'd to the GPU every time, they certainly don't have to be.

touch CoC.md
KISS tarballs

GTFO

/dpt/ should i write a computer worm that checks browsing history to detect if you're one of the many kinds of people who are deficient of character in a way that offends good conservative values (e.g. niggers, faggots, jews, spics, mudslimes, trannies, sluts, landwhales, commies, etc) and if you are then it writes boot code that will wipe your hard drive and try to find flaws in your hardware design that will let it physically damage the hardware through code to as great an extent as possible?

but user
videogames are programming

That's an interesting approach, though I don't know if it's going to work for older machine due to the use of a geometry shader.

What kind of an interface did your renderer have, then? The ones I've made, and the one I'm making, look something like this in pseudocode:
while (1)
{
sb_begin(&batch);
sb_sprite(&texture_a, 20, 302);
sb_sprite(&texture_b, 26, 90);
sb_sprite(&texture_b, 40, 35);
sb_end();
}


Each sb_sprite() call would write four vertices to a buffer on the software side. Then when sb_end() would be called, this buffer would be sent to the GPU via a call to glBufferSubData().

But with glMapBuffer you could directly write the sprite vertices to the buffer's memory, though apparently it has some drawbacks and I'm not sure how reliable it is on older drivers. So I'm wondering, which one's faster.

Oh, and I don't think uniform buffer objects work in something like GL2.0 either.

...

A programmer want to impress a girl

He has heard that a particular species of trout give smooth abs

He think oh I will go to catch trout

Why he not go to catch trout??????????

BECAUSE!!!:


a fish in sea is more important than abs traction

Level of comfyness : meh
This shit simplifies fractions from a dat file :
0000000004 0000000008
0000001536 0000078360
0000051478 0000005536
0000046410 0000119340
0000007673 0000004729
0000004096 0000001024


IDENTIFICATION DIVISION.
PROGRAM-ID. FRAC-SIMP.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FRAC-FILE ASSIGN TO "FRACTIONS.DAT"
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD FRAC-FILE.
01 FD-FRAC.
88 END-OF-FRACS VALUE IS HIGH-VALUES.
02 FD-NUM PIC 9(10).
02 FD-DEN PIC 9(10).

WORKING-STORAGE SECTION.
01 WS-GCD PIC 9(10).
01 NUM-RED PIC 9(10).
01 DEN-RED PIC 9(10).

PROCEDURE DIVISION.
BEGIN.
OPEN INPUT FRAC-FILE
READ FRAC-FILE
AT END SET END-OF-FRACS TO TRUE
END-READ

PERFORM UNTIL END-OF-FRACS
CALL "GCD"
USING BY CONTENT FD-NUM, FD-DEN
RETURNING WS-GCD
END-CALL

DIVIDE FD-NUM BY WS-GCD GIVING NUM-RED
DIVIDE FD-DEN BY WS-GCD GIVING DEN-RED
DISPLAY NUM-RED SPACE DEN-RED

READ FRAC-FILE
AT END SET END-OF-FRACS TO TRUE
END-READ
END-PERFORM
CLOSE FRAC-FILE

STOP RUN.

IDENTIFICATION DIVISION.
PROGRAM-ID. GCD.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 TMP PIC 9(10).

LINKAGE SECTION.
01 NUM PIC 9(10).
01 DEN PIC 9(10).

PROCEDURE DIVISION USING NUM, DEN.
BEGIN.
IF NUM < DEN THEN
MOVE DEN TO TMP
MOVE NUM TO DEN
MOVE TMP TO DEN
END-IF

PERFORM UNTIL DEN = ZERO
MOVE NUM TO TMP
MOVE DEN TO NUM
DIVIDE TMP BY DEN GIVING TMP REMAINDER DEN
END-PERFORM

EXIT PROGRAM GIVING NUM.

END PROGRAM GCD.


rate it Sup Forumsee

leave

COBOL?

>A programmer want to impress a girl

he can't, because all programmers are pathetic beta males.

yes,
this is the output :
0000000001 0000000002
0000000064 0000003265
0000025739 0000002768
0000000007 0000000018
0000007673 0000004729
0000000004 0000000001