/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1550058275779.png (855x1026, 583K)

>she doesn't build her own software/mobile apps whenever a need arises

>mobile apps

Attached: no.jpg (700x400, 48K)

>She
Women can into programming

I have an old, almost 3kg lenovo with a failed battery that lasts 5 minutes. I need a phone with "apps" for portability.
Don't bully.

Outside of databases, what are some cases where BTrees are useful?

Solving SICP problems.

>583KB

Attached: 1552771346151.png (855x1026, 206K)

Filesystems

Working on my GUI library. Currently on sharing the scrolling logic used by my text editor widget and my table view widget. I'm moving all of it to a shared base class (GScrollableWidget).

I wanted to add some features to my table view and realized that I can save myself a bunch of trouble with inconsistency by unifying the scrolling now instead of later.

Attached: Screenshot at 2019-03-16 22-48-27.png (1920x1080, 799K)

Is it weird that I think about my compilers as my friends

Attached: 1552772749632.png (855x1026, 2.51M)

I have a question about C++ memory management and lack of garbage collection.
What if I just don't use the "new" keyword. Yeah, just like that.
Where is my lack of garbage collection and memory management now?

I mean, is there ANY downsides to that?

how do you plan to work without new tho senpai

Won’t be a problem for the most part. C++ with smart pointers is really pleasant.

Sometimes stack allocation isn't flexible enough.

>+30 years old
>looks good at programming
>can't find job

what went wrong?

Today I'm working with a mate on finding the best possible combination of technical indicators for predicting stock prices. As a simple human, I got a Strat that got 36% I know using a simple LSTM I can get 42%. We're using a much more complicated neural network today. If we break 51% I'll make messy in my shorts.

>What if I just don't use the "new" keyword. Yeah, just like that.
You mean only using smart pointers? That is the recommended way to write modern C++. You're not supposed to use the new keyword.

Or only statically allocated memory? Reasonable if you know you won't need to dynamically allocate.

>predicting stock prices
>not using insider trading

What are some common/good ways of holding data values in a file for a program to load in as opposed to having those values hardcoded? Like for example if you have a Monopoly game, holding the property names and prices in some outside file.
Obviously you can do it with just having those values in a text file that they're loaded from, but how would a game that doesn't necessarily want that file to be easily opened and edited by a user handle that? Something like storing the data in binary?

>What if I just don't use the "new" keyword. Yeah, just like that.
Try creating a data structure of 10MB on the stack.

a-anons?

one extra tidbit: 'placement new' is still useful in modern C++ for re-using previously allocated memory without doing additional allocations. For example in game engines or any real time system where you don't want to be allocating much beyond program startup.

$ ulimit -s 16384

Kek, shhh don't tell

Is Python functional or imperative and what is imperative

Attached: d3c288c8285d4f24cee5becda256050a780e30c3c6ccb57eae814252a564f342.jpg (657x882, 73K)

I've had plenty of jobs user. I'm just looking for something new, as far away from the bay area as possible. :)

If anything went wrong though, it was definitely the drugs.

python is a purely functional compiled language with dependent types, which means it doesn't have any types and everything is represented by UTF8 encoded strings.

Imperative is basically mathematics for space nerds, I fucking hate those people.

JavaScript rocks!

Attached: js-rocks.png (1000x494, 368K)

good post

Come home, white man.

Imperative. If the language can be broadly described as a description of a sequence of events then it is imperative.
Functional languages lean more toward the declarative side of of the declarative/imperative axis.

Designing and developing a simple peer-to-peer bot net in plain C with security integrated. Doing this shit to understand how it works and how can be broken/made better. I plan to publish after i'm done with that and pass to next project

>bot net ... with security
Eh
What about a fancy logo aswell?

They are classes defined by linguists who can't really into programming. And as everyone knows, the development of any language gets better the moment you fire a linguist. Because, in practice it doesn't matter shit how you classify your language, only what you do with it. And all languages are converging to the point, where you can do whatever you want however you want.

I know of several Japanese devs that just institute their own shitty XOR pads. I suppose it's effective enough in stopping the casual snooper. Realistically speaking, almost anything is enough to do that. Like most things in information security, it's a question of threat profile and how far you're willing to go.

it's functional, because it is strongly typed.
Yes, python is strongly typed despite being dynamically typed and has duck typing, those aren't exclusive. Python is in fact among the strongest typed languages, it can lift more Moan ads than haskell btw.

>C++ with smart pointers is really pleasant.
disgusing C++ as a language with a GC is fucking stupid, and inefficent
each shared pointer is an extra memory allocation

>it's functional, because it is strongly typed.
those things have nothing to do with each other

No graphics; i'm not a designer.
Security means a leader can guide the entire botnet and connect as a peer to avoid detection. Avoiding hardcoded IPs and domain names.

That's wrong though. Copying a shared_ptr incurs the cost of an atomic increment. Moving a unique_ptr has no cost.

fuck off Odersky

and your dumb

>each shared pointer is an extra memory allocation
I looked this up cuz at my internship company the boomers abuse the fuck out of std::shared_ptr and use it for everything (making std::vector is a common pattern there, cleverly obfuscated behind dozens of typedefs. They even pass those vectors by copy because none of them can even tell what the fuck is going on anymore or how copy semantics work) and actually the std::make_shared does a hint to the allocator to do a single allocation with room for both allocations.

Interesting results! I added C++ -O3 to observe the real diff. between VM and native plus .NET Core to observe the diff. between two VMs and to confirm whether it is just VM overhead or bad codegen.
From the results I obtained, it seems the JVM is not that good at optimising bitshifts and maths.

Attached: out.png (738x490, 26K)

I don't use shared_ptr, or any of the STL for that matter.

Use encryption, give the file owner the possibility to set a name for the profile to save (game name). Use the input as a key to read those datas. This is really simple and can be broken, but all depends for how much you want to keep them safe.

Language wars I can handle. Memory management wars I can't fucking stand.

Attached: 1508428588954.jpg (320x240, 26K)

It seems to me like shared_ptr should be a rarely used thing. Using unique_ptr for the original owner plus raw pointers for non-owning references has made perfect sense to me every time, and worked.

If you structure your code well then in vast majority of cases you'll be using unique_ptrs and non owning raw pointers.

look at this bad ass

Wrapping an object in a shared pointer is inefficient. the reference counts / free lists or whatever should be part of the actual object. You can do this in C++, but the way it does it by default with shared_ptr is stupid

>it is strongly typed.
There's static typing, dynamic typing and meaningless buzzwords.

Instead of full mutexes, is it safe to just use an integer "lock" variable, setting it with a busyloop around InterlockedCompareExchange?

I think I find out why I have a hard time trying to program, I find the computer and the internet too distracted and I get sidetracked easily.

It burns CPU cycles but sure, it works

try amphetamine

linear types could've prevented this

Attached: 1546435225359.png (1600x2239, 3.02M)

ok guys help a noob out
I've got a function in a C++ file that returns a few objects, I want to import this file into another one to call the function. if I just it, does that work? Can I just call that function as if it was declared in it?

this is what headers are for

>What are you working on, Jow Forums?
Thread dumper, in Rust.

Brainlet here. What exactly is a closure? I read the wiki article a few times and it really didn’t help.

>In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function[a] together with an environment.

Perhaps I’m a bit slow, but what the hell does that mean?

What languages do you know?

Do you have any prior experience in os programming?

it's a function plus some built in parameters and state (the environment)
e.g. (C++)
int x = 0;
auto incr = [&x](int y) { x += y; return x };

incr is a closure, "closing over" the variable x, and acting like a function int to int

They're essentially functions, with a different syntax, don't thing too much about it.

a closure is a reference to a variable from a runtime scope

>the reference counts / free lists or whatever should be part of the actual object

That makes no sense though.

None. I did work on an x86 emulator though, which has been quite helpful. I even used it for debugging my OS earlier, before I started programming for hardware that my emulator didn't emulate.

Other than that I'm just figuring this out as I go. It's not as difficult as I expected, although it is time consuming.

it's just a monad on a poset in some category

>Explaining closure with c++ lambdas
;^)

it's the first thing that came to mind, plus you can explicitly list what's captured

FWIW I use that technique for my own shared-ownership classes. Any class T that needs to be shared inherits from Retainable which bakes a retain counter (just a plain int member) into the object and provides retain() and release() to increment/decrement the retain count and potentially call the destructor in case the retain count goes to zero.

Then I have a smart pointer class that wraps a pointer to one of these objects and calls retain()/release() as appropriate. Nice, cheap and automagic.

Say you have a function inside another function, which is possible in many languages.
That inner function can access the variables of the outer function.

An environment is just a fancy term for a scope of binds between variable names and values.

tell me what doesnt make any sense and i'll explain it to you

In JS this is just
const getUniqueId = (i => () => i++)(0);

Attached: 1550145664073.png (916x914, 835K)

>a closure is a record storing a function together with an environment.
It's literally that. Have a Python example:
#closure
def asdf():
#environment
a = 5
b = 7
# function
def asdf2(x,y):
return a*x + b*y
return asdf2
asdf = asdf()
print(asdf(3,7))

baba is you, but is baba turing complete?

Attached: babaisyou.jpg (247x299, 10K)

Just look at this nonsense
You end up having to have a smart pointer anyway and adding unnecessary complexity to the object.

How long does it take to train

>nonsense
that's the sane way of doing it
having a RCed pointer that wraps an object means an extra memory allocation for every pointer, which is inefficient

>Today I'm working with a mate
>How long does it take to train

Attached: 1552720295490.jpg (1920x1080, 913K)

If you are that hung up on performance, there are better ways than reference counting at all. If you are working on a project where you can sacrifice some performance for safety, you might as well save yourself some typing too.

In my experience it never works as well in reality as in backtests.
Also when you build too many models you will start overfitting your test set.

I would answer but op pic is trash

The thing it it's not a performance vs programming efficiency tradeoff. One of them is just a straight up improvement over the other.

I'm building a C interpreter so I can have a nice C REPL.

It is, see:


>Any class T that needs to be shared inherits from Retainable

This also doesn't take into account that there are times when some instances of a class are shared and others aren't.

is it going well?

what are you calling it? CRaP? CRiPpLe?

>>Any class T that needs to be shared inherits from Retainable
is that a problem?
True you do lose efficency by having a reference counter on objects where you might not need them, but storing some extra memory is alot more efficient than having to look up memory in a different place

I wouldn't recommend mixing multiple ownership models for a single class.

Clojure is the best Lisp

Attached: meirl.jpg (452x600, 24K)

>is that a problem?

Depends. It's certainly a programming inefficiency.

Ownership should describe usage. You shouldn't use a shared ownership model in an instance where the object isn't actually shared, just for consistency.

>It's certainly a programming inefficiency.
no more than fucking around with C++s other smart pointer features
and if you used a real memory managed language, the language would do it for you

That would be Shen.

functional is from lambda calculus where everything is a function/expression. a functional program is a big expression made of sub expressions.
functional programming disallows statements. a functional program is __evaluated__.

imperative is from the Turing machine. an imperative program is made of statements. an imperative program is __executed__.

I'm attempting to create a program in Ruby that uses an array to store multiple instances of several values and displays all of them when prompted to. It's mostly done, but I am unsure as to how to create an array that will store a potentially infinite number of entries and then display them all on exit. So far I have pastebin.com/eN2rtceA any suggestions?

Lua?