/dpt/ - Daily Programming Thread

Previous thread: What are you working on, Sup Forums?

Other urls found in this thread:

pastebin.com/y3BaRBb7
stackoverflow.com/questions/9941502/c-reference-to-out-of-scope-object
stackoverflow.com/questions/49103874/looping-through-multiple-lists-in-parallel-and-temporarily-looping-through-only
github.com/Arefu/Wolf
twitter.com/NSFWRedditVideo

...

why do people think high resolution timers don't exist? System.nanoTime() and CLOCK_MONOTONIC always seem to have precision on the order of microseconds, not milliseconds or worse

Windows api has the most accurate timer I have ever seen. It is really really amazing.

RUST CONFIRMED OUR LANG

my god, reddit is cancerous
one of the comments: "He should work with Elon."

>-310 points
there's still hope of defeating the sjws

writing APIs is the most enjoyable part of programming

which is worse, python or golang?

what for, user? don't you know every programming language is suited for different tasks?

what means is that they're both shit

Ok wtf is going on here

int main()
{
init();
std::cout

why aren't you storing the return value of
init();
in a variable? This will behave just like if you wrote:
int
main()
{
return 0;
std::cout

Was a typo, sorry. It's actually

auto wallet = init()

And then there's lots more code later on which uses wallet and does other stuff, which was all working fine before this.

le hardcore Sup Forums cool kid uses C for everything.

Also I should have clarified, it just hangs here. Program doesn't exit, doesn't respond to input, it's not using any cpu.

It stopped working after you added the line printing 2?

I should probably just post a big snippet of my code because that's over simplified.

pastebin.com/y3BaRBb7

My previous version, I wasn't using std::unique_ptr nor using a function, but it was the exact same code just not returning it in a std::unique_ptr wrapper, wanted to make my main function less messy.

In this version it prints "1" then "2" then hangs.

Interestingly, Carmack said that C would probably have been a better choice than C++.

I don't really know, and don't know enough about smart pointers to tell, but I guess WalletGreen contains a reference or something to its one of its construction arguments, which causes something fucky to happen when you exit the function scope.

Ok, that's probably it. I'm a fucking brainlet in regards to references, WalletGreen takes some parameters by reference so I suppose they are no longer valid when it exits the scope. Thanks senpai.

Does WalletGreen contain a reference member variable?

Yep, from the constructor:
WalletGreen(System::Dispatcher& dispatcher, const Currency& currency, INode& node, Logging::ILogger& logger, uint32_t transactionSoftLockTime = 1);

is python a good language to learn after c and java/c# or should i learn functional programming?

what other langs do you know?
if none, learn python
if a few, or you're smart, go functional

No, that's not enough. But yea, as it's not const qualified WalletGreen probably contains an actual reference, and doesn't just copy the argument.

This seems related:
>stackoverflow.com/questions/9941502/c-reference-to-out-of-scope-object
Apparently it causes undefined behaviour

python is the stupidest fucking language you will ever see.

i know c, java and a bit of c#

Ah, I see what you mean. Yes, it does contain references as member variables which it assigns. Thanks. Not sure how I can split this into functions then?

t. golang user

i'm the quotted and i have to admit i hated the structure of pretty much all python codes ive seen, but i everyone i know talks its a great language so idk

You you have to define the referenced arguments in main() probably, but you can send them to init() as arguments and do the rest of the stuff in there

Funny, I was thinking about adding a reference member to a class I was writing earlier today. I'm glad I didn't.

Blegh. I wanted to not have a giant main function. thanks again.

What's a good "blog" platform for programming stuff that respects your freedoms?

html over https

is there a book with real life python homework? from simple to more complex?

I started learning python because I wanted to build a subtitle downloader. Now that I've achieved it I want to continue learning it but I'M having trouble with learning things for no reason. it's boring and I lose motivation easily.

Automate the boring stuff with python & Python crash course.

thanks, bud. Downloading the book right now. I have learned a lot from that fat guy from boston but I've hit a wall because I don't know what else to code.

anyone has advices for learning haskell? i've done the sicp and looking for a new challenge thanks.

Yo, you guys know how to go about iterating through two lists in parallel in Python, but then pausing the parallel iteration to iterate through one of the lists, and then coming back to the parallel iteration but continuing from where the individual iteration left off? Is that even possible in Python?

I'm trying to build a FIFO calculator for financial assets in Python but I'm just starting to learn the language and can't figure out how to proceed.

Asked on stackoverflow too but didn't get a real answer. The example I gave over there might be easier to understand though. ---> stackoverflow.com/questions/49103874/looping-through-multiple-lists-in-parallel-and-temporarily-looping-through-only

If someone could point me in the right direction, I'd really appreciate it. Feel like I'm going insane.

Keep two pointers, i, and j, and advance them accordingly inside a while loop... You can probably figure out the rest.

theres like three haskell books and then the 99 problems thing.

It bothers me when I see shit like
$res = ...

when
$result = ...

could have been used instead. It is really that horrible to type out those three extra characters? This isn't 1968 anymore. Am I wrong? If so, tell me why I'm wrong.

haskell wikibook

you know what res means in the context.
why type out the extra characters?
in an actual program, obviously you'd have proper var names.

ur autistic m8.

Lol. Ya... motherfucker never explained what he meant. Using two pointers and zip() allows you to keep track of the current lines in each list in parallel (thus, the current buy or sell order) but I don't know how you could advance through one list but not the other in the way that I require. You'd have to break the parallel iteration, iterate through one list, and then eventually resume the parallel iteration, but have it start on the line where it left off (concerning the list which didn't get iterated through) as well as start where it left off on the line which did get iterated through.
I have no idea how to do that. Maybe with tuples and updating the keys on every iteration? Plus, that's just for associating sell orders with buy orders in the FIFO fashion. I need to also test for date discrepancies during the line comparison, which is easy, but the logic of it is hard to remember when you're writing it all out and using nested conditions.

I just started teaching myself Python for the first time last week, so I'm still learning the syntax. If someone could help me out... I'll blow you.

learn lisp

Probably will... eventually.

I've spent quite some time looking over the unofficial quake specs, and I have made something to let me open the PAK file, and the files within it. Now I am trying to load the BSP file and get all the contents set, this is one of my functions:

void BSP_loadvertexes ( bspfile_t *BSP, void *data, dheader_t *header )
{
vertex_t *vertices = (vertex_t*)(&data[header->vertices.offset]);

DWORD size = header->vertices.size / sizeof(vertex_t);

DWORD i;
for ( i=0; iQ_vertex[i].x = vertices[i].x;
BSP->Q_vertex[i].y = vertices[i].y;
BSP->Q_vertex[i].z = vertices[i].z;
}

vertices = NULL;
}


I'm still learning programming, I decided to jump in to something that may be more than I can chew, but I have learned some stuff doing so.

It's not necessarily an error, but a warning in my compiler
warning: dereferencing 'void *' pointer

Do you know what I can do to fix that?

How much can you accomplish in Scheme without using any bindings?
That means things like these are off limits:
(define id ...)
(define-values (id ...) expr)
(let ((id expr) ...) expr ...)
(let* ((id expr) ...) expr ...)
(letrec ((id expr) ...) expr ...)
(let/cc id expr ...)
(lambda (id ...) expr ...)
(lambda id expr ...)
etc

How much you wanna know? Very generally, casting void * is considered dangerous by the compiler, since your really just 'pretending' some raw memory space is the type you expect it to be, so it can't really check what your doing isn't stupid.

>how much can you do in ASM without using op codes

you can still do any computation, it's just going to be stupidly verbose

what the fuck am i doing wrong here? It's probably something retarded but I just can't figure it
final ArrayList deviceTypeList = new ArrayList();
deviceTypeList.add(new Pair(
new DeviceTypeFullRequest("Android"),
new ArrayList().add(new PropertyRequest("devicetype.testproperty1.txt", "testValueAndroid"))
));

S (ap) and K (const) is enough

i'm considering getting a really shitty laptop with linux on it just so i can stop being distracted while learning programming

has anyone here done this?

you're still gonna get browser_of_choice and """""""accidentally""""""" open Sup Forums.
just have some self-control you dweeb.

browser_of_choice will easily eat up all the ram and make browsing insufferable

...

>browser_of_choice will easily eat up all the ram
why would you even buy a laptop this shitty.
your hello worlds alone will take half a minute.

Just start a project even if it exists or dissemble a big library written in the PL you are learning.

half a minute is a record

golang is worse than any other programming langauge ever

okay guys, this problem is legit pssing me off because I can't get the correct output. Here's the problem:
Display all lines that end in 0 or 1, and have a 1 in the 3rd from the last column.
The text file has like 6 columns and around 40 ish lines, the output should be 1 line only that matches this criteria.
I use grep in order to output the lines containing 0 or 1 at the end, but how do I search column 3 as well? I tried piping a sort, but I'm having no luck. Any help?

Sorry I'm dumb, Please help me with this
/*C Premier Plus exercise 6-2*/
/*Use nested loops to produce the following pattern
$
$$
$$$
$$$$
$$$$$*/
#include

int main (void)
{
char Dollar[4];
int Limit, Control;

Dollar[0] = '$';
Limit = 36; //msy need to adjust this to the ascii code for whatever comes after $
Control = 5;

printf("%s", Dollar);

while (Dollar < Limit)
{
printf ("\n%s", Dollar);
while (Dollar < Control) //these copsrasions may be an issue
{
Dollar + '$';
}
}
return 0;
}
//2 mar 18
I just don't understand how to manipulate arrays and how to introduce the dollar sings to each individual entry.

You can fuck off back there

>> Use Smalltalk.
>> Struggle with GUI applications.
>> Crash VM multiple times trying to get rid of a stuck Morph.
>> Move to Elm.
>> Code that took six classes in smalltalk becomes 100% straightforward and far less verbose.
>> Suddenly feel much less constrained in terms of what I can do, even though it's fucking Elm, the Golang of functional languages.

Smalltalk is trash. The VM & implementation and how it interacts with its reflective features is extremely interesting to learn from, but the language and standard library is frankly terrible. Even for GUI's, which are the classical OOP success story.

If you are currently using Python + PyQT and are considering Smalltalk for GUI's, don't bother. It's still worth looking into because of how insanely good the Smalltalk debugger is since the stack, all stack frames, and all scopes are objects that you can interact with. It's very good for teaching TDD. It does some things incredibly well, like debugging and repairing a running program, and generally developing by modifying a running process. But the dogmatic nature of it makes it extremely verbose even for some simple tasks and the incidental complexity ends up being higher than it needs to be.

no

>even though it's fucking Elm, the Golang of functional languages.
I really like Elm.
It's just a shame any sizable project will eventually become a jungle of coupling. Which kind of defeats the whole FPL style in the first place. And 0.19 still isn't here after 1 year and nearly 4 fucking months of no updates.

any language that doesn't have static typing, type inference, dependent types, algebraic types, linear types, closures, moan ads, type variables, and typeclasses is a shitlang
fite me

Why wouldn't you just do something like:
int i = 1;
while (i < 6) {
int j = 0;
while (j < i) {
printf("$");
j++;
}
printf("\n");
i++;
}


It doesn't seem like you need arrays for anything here.

anybody?

No.65003752
>type inference, dependent types
these things directly conflict, as per the abomination that is liquid haskell.
But you used "moan ads" so you're probably just (you) fishing.

[C#]

float n = 1000;
byte[] bArr = BitConverter.GetBytes(n);
float myFloat = BitConverter.ToSingle(bArr, 0);
string myStr = BitConverter.ToString(bArr);


Output: 00-00-7A-44

Why is this output? 1000 broken in octets should be 00000011-11101000 which should be 03-E8 in hex, should it not?

>The absolute state of dpt
Maybe try and write it correctly before you try and make it more efficient

>these things directly conflict,
i'm well aware that's the common sentiment in the air.
however, i strongly feel we just haven't figured out how to make them properly work together yet.
ergo, to date, all existing languages are shitlangs.

fite me

>muh moan ads

>we just haven't figured out how to make them properly work together yet.
There's nothing to figure out, type inference is trash when you have dependent types. Why would you want to lose information on important details that dictate the possible return types?

I don't think I've ever heard a it's the current year argument for programming languages before

>There's nothing to figure out,
Disagree. I maintain it's possible to fully and completely trace at compile time the "runtime" type of any given value under a dependent type system, thus sidestepping both potential loss of type information *and* any need for RTTI.

>I maintain it's possible to fully and completely trace at compile time the "runtime" type of any given value under a dependent type system,
I'm not doubting that. I'm saying in practice it's fucking stupid. Have you actually used Idris or another language with dep types? it becomes immediately obvious why type inference doesn't mix with them.

Microsoft Research + INRIA's F* language does type inference just fine in most cases despite having full dependent types. You just have to design the language with type inference in mind from the start and be clever with regards to inferring the types of parts of your program, even if not everything can be inferred.

Anyone here use Varnish Cache before? I'm trying to figure out if it's worth storing the cache on a separate server instead of just using malloc. The documentation isn't great and there's next to nothing about it on stackoverflow

Well the previews exercise required arrays so I supposed this one will also
I'll test your code tomorrow.

>> Implying that type inference implies information loss.
A very large portion of progams can have their types inferred automatically. Let the compiler do that, and leave the rest to humans. But don't make a human do a machine's work.

All that's obvious to me, is that the approach they apply at integrating the two doesn't work very well at all.
You don't understand. I'm talking about putting them together without loss of type information.
Consider two values a and b of type Nat.
Suppose, in this hypothetical language, the type Int is a supertype of Nat, per dependent types.
I am saying, that there is a way to determine, AT COMPILE TIME, whether the Int (a - b) will also be a Nat.

Elm is great for small projects and I use it for my own web pages. It's just less powerful than it could be.

github.com/Arefu/Wolf
Pretty much that.

>Determine at compile time if interested(a-b) will be nat
It's something different, but Microsoft's code contracts is able to do that. It doest work for all situations, like if a is gotten from input, but then it will give a warning to add a check on the input value.

Guise? guise pls

*** Fatal Error: Access Violation at 0X00007FF9FEBE4747
Module: quartus_map.exe
Lock in use: 54
Stack Trace:
0x14746: OPT_RAM_AI::OPT_RAM_AI + 0x114b6
0xbc64: OPT_RAM_AI::OPT_RAM_AI + 0x89d4
0xb6f5: OPT_RAM_AI::OPT_RAM_AI + 0x8465

0x45f8b: opt_bdd_small_arm_entry + 0xb9cb
0x49103: opt_bdd_small_arm_entry + 0xeb43

0x527ec: RTL_ROOT::process_sgate_netlist + 0x1dc
0x13e001: sgn_clear_check_ip_functor + 0xb3e01
0x1400e8: sgn_clear_check_ip_functor + 0xb5ee8
0xa41d6: sgn_clear_check_ip_functor + 0x19fd6
0xa6a44: sgn_clear_check_ip_functor + 0x1c844
0xa73ca: sgn_clear_check_ip_functor + 0x1d1ca
0x10dc7: sgn_qic_full + 0x257


0x11fad: qexe_get_command_line + 0x1b7d
0x14e0e: qexe_process_cmdline_arguments + 0x59e
0x14f21: qexe_standard_main + 0xa1

0x4c78: msg_exe_fini + 0x58
0x53bc: msg_exe_fini + 0x79c
0x1584: MEM_SEGMENT_INTERNAL::~MEM_SEGMENT_INTERNAL + 0x194
0x5f9f: msg_exe_main + 0x8f

0x11fe3: BaseThreadInitThunk + 0x13
0x6efc0: RtlUserThreadStart + 0x20

End-trace

Quartus II 64-Bit Version 13.0.1 Build 232 06/12/2013 SJ Web Edition
Service Pack Installed: 1


WHAT THE FUCK IS THIS??? quartus II 13.0 sp1

A Windownian sigsegv

What are some really good resources to start learning how to program in c? I kind of want to get a head start in a mandatory uni course that I'm about to take soon and start learning early.

No it wouldn't you fucking retard.

>It is really that horrible to type out those three extra characters?
Yes.

>fucking retard.
w-wow, calm down big guy.

im a fucking pythonlet
i want to learn C because systems programming and fast code sounds fun to me
but i start k&r and i feel like a fucking retard
i dont know what to do

Hey how would I do this tastefully. I have a class like this.
struct texture
{
SDL_Texture *data;
int x_offset; // etc.
void do_option();
string display_text = "";
string msg = "";
};

The reason I have display_text and msg in there is because sometimes these textures function as options, in that I'll click the texture and it will send the msg to another function to relay which option was pressed. I was thinking of doing this
struct option : public texture
{
void do_option();
string display_text = "";
string msg = "";
};

and moving those things over here. Problem is I'm just storing the textures like this in some window struct
vector textures;

So when someone clicks on a texture, there's no way to check if that texture is in fact on option. Should I do something like this
struct texture
{
texture_type _type = texture_type.texture;
// etc.
};
struct option
{
texture_type _type = texture_type.option;
// etc.
};


/* inside some onclick function */
if(texture->_type == texture_type.option) {
// code to check if mouse click falls within this texture's boundaries
auto _option = static_cast(texture);
_option->do_option();
}


Is that how you would do it?

if (option *opt = dynamic_cast(texture)) {
opt->do_option();
}

...

Thanks I had the feeling there was an easier solution.