/dpt/ - Daily Programming Thread

old thread: What are you working on Sup Forums?

Also, we should compile a "beginner's list" like /wdg/ has

Other urls found in this thread:

lxr.free-electrons.com/source/
software.intel.com/en-us/articles/intel-sdm
wiki.osdev.org/Main_Page
en.cppreference.com/w/cpp/string/basic_string/to_string
en.cppreference.com/w/cpp/string/byte/strtol
libgen.me/view.php?id=1412347
libgen.io/
twitter.com/SFWRedditImages

I'll just repost this here so we call laugh at this faggot
also first for C

creating gifs of how to use various tools and initiate build pipelines for a client because they're a 'visual learner' aka fucking too thick to read.

I'm gonna start using emacs TODAY

how bout dat

>2017
>start using emacs TODAY
I myself have decided to adopt the old medical philosophy that the body was comprised of humours

Daily programming challenge: find the sum of all palindromes under the nth prime
Give proof that it works with n=10000

who is this little hooded anime lady and why am I so taken by her lifestyle?

umaru-chan

thats cute AF i'm gonna have to watch this

What textbooks do you guys suggest?

going to make linked list in order in memory using brk and sbrk. Doesn't have to be in a specific order but it does need to be able to expand and contract and remove individual members if need be.

SICP

Applied Cryptography 2e

Programming in Lua

I wouldn't suggest any of those given the prices yikes. Do you have access to any private trackers for academic material? maybe somebody in /ptg/ knows a good one

Those books are also available at Library Genesis

oh nice, that is good to know. I tried to fine Lisp In Small Pieces on there but had no luck :(

Search for the author instead of the title, I could find it that way

Sounds like you're writing a malloc function.

Yes, but my my malloc doesn't abstract anything

>brk and sbrk
>malloc

malloc will use mmap for anything the first few pages desu senpai. But yes, malloc will use brk for small things.

So Sup Forums tell me how to really learn AND master C.

For learning C:
Start out with K&R and do the exercises. I know it gets a lot of hate on Sup Forums because it's old and isn't up to date when it comes to the standard, but it really is a great book in terms of pedagogy. At least this was true 8 years ago, maybe there's a better book out.

Also, I found that learning assembly, and calling C code from assembly (or wise-versa) helped me a great deal to understand how C synthesises. I recommend implementing a sprintf like function in assembly at some point.

Once you advance and gain experience, you'd probably should start using the C standard as reference for a lot of things.

Master C:
No one masters C, but practice makes perfect.

Is there a non-cancerous source to learn ASP.NET from? I just need the basics. How to serve static and dynamic content, how to execute server-side code, etc.

redpill me on mmap vs brk

Pascal in uni, simple shit like arrays with numbers

>Can't master C
>Can be perfect in C
Really getting me thinking

brk and sbrk are archaic functions that predate virtual memory management. They are used by malloc for the first couple of pages because when the loader loads your executable, there's free space left in various segments that are loaded (your executable is wrapped into a ELF file, with headers describing different memory segments and their start addresses + sizes).

mmap is a low-level syscall for controlling memory, and is extremely flexible and powerful.

Thank you. Do you have any tips on Python too?

Not in the same way, sorry. I learned Python in a university class that was structured like a intensity course, where we did a bunch of assignments.

How do I redefine let to 137 in Scheme or Lisp

Want my code to look more dank to impress girls

>They are used by malloc for the first couple of pages
Could "mmap" be used in the same context?
Also, I thought "mmap" let's you map files into memory. Does it do other things that would make it useful for allocating memory?

>Could "mmap" be used in the same context?
Yes

>Also, I thought "mmap" let's you map files into memory
Among other things. If you look at mmap's signature, it gives you an idea.

>Does it do other things that would make it useful for allocating memory?
Yes, it allocates pages and set proper page attributes, such as whether or not the page is pinned/swappable, the protection level, which process-specific virtual address you want it to have etc.

This is really interesting, thanks. I'm looking at the mmap man page in detail right now.

Would you be able to recommend me any resources for learning about this stuff and the linux kernel "under the hood"?

>any resources for learning about this stuff and the linux kernel "under the hood"?
Go directly to the source, is my recommendation.

I use this webtool frequently: lxr.free-electrons.com/source/

If that's too overwhelming, you could always start with making some small hello-world-ish kernel module that for example traverses the user process' page table and prints out addresses or something like that.

Also, to learn about virtual paging in general, refer to the Intel manuals. They're free and available for download online.

software.intel.com/en-us/articles/intel-sdm

There's also a lot that can be learned from this wiki, but I'm not sure how active it is any longer:

wiki.osdev.org/Main_Page

What was your first programming language?

Random question that I'm sure has a simple answer
Using Visual Studio, ran a debug piece of code on another program and spat out an enumerator value

What's the simple way to search through the declared entries in said enum to get the one that corresponds to the number value?
Said enum has several thousand entries and I'm drawing a blank how to do this

QuickBASIC

M-Mathematica.

PHP or mIRC script

Haha, same here..

>Programming in Lua
Why?

I was genuinely retarded though. I didn't understand functions and subs/procedures at all, and I struggled with for loops. But then again, I was 8 years old.

Turbo C++ (as in Borland's weird fucker version of C++).

Or it might have been RPG Maker 2000 events.

I forget the order that these things happened.

mirc script for me as well lol, good times

Visual Basic and Pascal also

VB6

Are you me? Did you also use DarkBASIC?

>Did you also use DarkBASIC?
Nope, 100% confirmed not your clone.

I have never touched a BASIC.

I want Github to have an achievements system because I am Pavlov's Dog.

>add -pedantic to my compiler flags
>10,000 warnings
>ISO C90 forbids mixed declarations and code
>initializer element is not computable at load time
Why do people like C89 again?

An enum is just a special kind of int, in a way of speaking.

We don't. C99 or C11 for userspace, C90 for Linux kernel stuff

Think of it as an int that pollutes the namespace of whatever scope it's in.
It's useful if you wanna pass error codes and don't feel like explicitly defining every error code number, just write the error labels.

An enum is what modern languages have because they don't support #define.

DarkBASIC was the tits for games back in the day. You missed out.

I don't know if that's a fair assertion.

Enums have various uses when there is a specific set of possible categories for an item, and using bitflags can give you some interesting options for classifying things.

A classic example is using enum bitflags to describe the state of something, such as in an RPG with status ailments. You can bitwise OR things to show that something is "Poisoned", "Paralyzed", and "Confused", by setting the appropriate bits. In light of this, the programmer can use friendly names to flip these bits, rather than keeping track of an arbitrary order of bits.

I know this, but the program I'm tying into uses a "type" enum for every single class defined, and the debugger spat out "151006328" and I wanted to get the name of the corresponding enum entry
I have the specific enum in the object browser, but search doesn't work because of course it's not that simple

>the debugger spat out "151006328"
Where did it do this? What did you call?

Pic related; you might be dealing with a series of bitflags here, as described in Need to see more code to diagnose.

Maybe the enum it returned is a packed bitfield of the form 1001000000000010110001111000

>try to code simple discord bot in python that can print stuff to the chat
>keep getting inconsistent indent error

It's not used that way in this case, all of these are visible in the object browser as:
"Public Const kEnumEntryName As ObjectTypeEnum = ########"
I have the number, I was trying to grab the kEnumEntryName to decipher what object I found

I have this chat program I wrote in flask. What would be the best way to store the messages?
Right now I have a single dictionary that stores it as id:message(s).
I don't feel like that will scale well.

What language are you using? Just convert from int to the enum type. Literally just do var enumValue = (MuhEnum)151006328; in the Interactive window or something.

Don't store the messages.

Implement caching in memory for recent messages, and stale messages get saved to storage.

Good fucking luck.

if you're looking for something lightweight you could offload them into sqlite

Quick! In Rust, does a&&&b parse as a & (&&b) or as a && (&b) ?

a && (&b)

I'm not glad Rust is dead, but I'm glad its gone.

I'm going to guess the former?
Last I checked, rust doesn't even have ternary operators.

C and C++ have the same syntactic ambiguity, but they won't give you a type error if you mess up.

VB.NET, I just got it by doing that but then I had to actually compile and get the debugger started so it'd tell me what name it corresponds to
Surely there's a better way since this would be useful but having to compile+run just to see the debugger spit out a name is silly and take too long

fn main() {
println!("{}", stringify!(a&&&b)); // prints "a && &b"
}

...

This is the kind of shit that keeps me from writing language parsers.

>ternary operators

>C and C++ have the same syntactic ambiguity
I don't care. It's still ugly as fuck.

On Wednesdays we kode!!!

Being marginally better than C is a pretty low bar, desu senpai

The logical operators have higher operator precedence than the bitwise ones, for this exact reason.
If you want to explictly bitwise and something, put it in parentheses.

msgbin[i+j] = str((int(msgbin[i+j]) ^ int(GENERATOR[j])))

How do I translate this python snippet into C++?

Already declared msgbin and generator as bitsets, only asking about the "str" and "int" part

I have no idea what is doing.

en.cppreference.com/w/cpp/string/basic_string/to_string
en.cppreference.com/w/cpp/string/byte/strtol

Why were monads called like that? Is it because you can do computations inside the monad itself so that it is separated from outer world?

Well, that's the fault of the stupid developer that's using a magic number in place of naming the enum value.

You can right click you project and do "Initialize in Interactive" to run one-liners against the types you're working with.

Doesn't eliminate ambiguity due to unary operators though. Afaik this depends both on the behaviour of the lexer and the parser.

I know my C++, I'm asking what those "str" and "int" do in python

It's part of a CRC check and correct algorythm.

>I'm asking what those "str" and "int" do in python
They create a string and an integer type.

Think of it as casting.

Monads are called like that in mathematics because they look like monoids if you squint. Mathematicians have had a bunch of names for the concept though, "triad" was the more popular term for most of its history and is arguably more descriptive (just the triad of map, pure, join) but it ended up falling out of favour to eliminate ambiguity.

Ayy lmao so I just had to xor my shit up.
Thanks familia.

Why must cross compiling to android be so miserable?

Ok one more and I'm done lol:
x = ''.join(bin[-24:])

''.join() does what exactly?

What a shitty etimology, dare I say

It makes a string.

', '.join(['a', 'b', 'c']) # prints "a, b, c"

I know there are code problems, it's major software that's been worked on by god knows how many people for years. These fuckers aren't even consistent with 0 or 1 indexing lists

Could not find an "Initialize in Interactive" though, could it be either me being in .NET and not C#, or because this project isn't actually a self-contained program, it's a class library that compiles to a .dll that hooks into the program's API

Python makes my tinkle sprinkle desu :^D

I wish D had won the war to replace C++ for rapid development of desktop applications instead of Java/C#.

To the user asking for Python book recommendations, this guy is pretty good:
libgen.me/view.php?id=1412347

That site doesn't load for me

Does this one?
libgen.io/

(defmacro redefine (a to b)
(declare (ignore to))
)

(redefine let to 137)

Could you rephrase?