/dpt/ - Daily Programming Thread

Absolutely no gf edition ;_;

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

Other urls found in this thread:

docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#GetPrimitiveArrayCritical_ReleasePrimitiveArrayCritical
youtube.com/watch?v=nXaxk27zwlk
youtube.com/watch?v=rX0ItVEVjHc
youtube.com/watch?v=GPpD4BBtA1Y
pastebin.com/shqDPWsw
twitter.com/NSFWRedditVideo

...

stdbool.h did nothing wrong

first for python is ok if you're just a hobbyist making automation scripts

Nudes?

Started the cryptopals challenge. Thinking of posting my code on Github as I complete the exercises, but too much of a beta to do it.

No it becomes
>"Good idea user. !!"
When the processor is done. Which is not what I meant (double exclamation points are dumb). So you see the communication error.

His parameter guards against that. It's how you make slightly more safe macro's.

It also solves your operator precedence issues explicitly for you. As you clearly define if you meant for a full expression to be negated or just the first term or whatever.

Well maybe read my post again and realize that I've already answered this reply completely.
Int is 4 bytes (usually). you mean char.
And even so char is 8 bits, you only need one.
>C++'s bool is big
Yes, but back then you need to conserve space so it's much wiser to let people choose a full byte for their bool type knowingly than have the deceptive type of 'bool'. If they care about that memory usage difference they are aware they can shift/mod/divide out the individual bits for usage, making a 8x more compact bool where more than 1 boolean value is used.

Which is quite frequently.

Nowdays it's important for other reasons but nevermind that for now. Focus on the now for you.

Quick answer is that you define that variables have to be 'resolved' using the scope resolution operator '::' by putting them in a namespace. The uses for this are many. You can have a way of grouping methods, static/global variables and other things. Which does simplify things a lot. It also allows for certain fancy automatic method selection. Like if you have two different swaps, one from the standard and one from your own code, using namespace std before the call can allow the compiler to pick yours when it exists and otherwise use the standard one without you modifying that code specifically.

But such close to invisible features aren't exactly something I endorse.
'using' is generally just to save typing.
Isn't this enough user? She's clearly very pretty right there. Unrealistically so.

i don't think she has nudes

macros don't get expanded in strings

Well yeah. Ok. I don't use string literals much I had no idea. Though I should know.

Doesn't particularly matter because the problem holds true in other areas.

I'm going to write a piece of software that aggregates images from across multiple cloud storage services and basically treats them as one directory, and lets you organize them by tags..
I have no idea what I want to write this in, so far I've only done C\C++. I want to be able to use it on locally stored files as well, and my supervisor thinks it would be a good idea if it ran as a web service.
what do you think /dpt/, how would you tackle this?
this is going to be my bechellor thesis btw

It's less readable because it's only one character.

if(x==false)
{
//I know that x equals false because it's painfully obvious from the if statement
}
if(! x)
{
//oops. In my rush, I didn't see the negation. I now think this executes whenever x is true
}

I mean, this example is trivial. But imagine a if statement with multiple conditions. Misread one "!" and you'll be troubleshooting the wrong thing.

like where?

This. After the lexical scanning is done, if any matches a macro, then the macro replacement is done. A string literal is not an .

>trying to defend == false

>pretty looking grown up girls who buys Kingdom hearts 2 dakimakura
What's up with this?

>It's less readable because it's only one character.

how does that make it less readable? Its simplicity is what makes it so readable.

He's a Java programmer.

That explains it

! is more readable *because* it's just a single character - less clutter to read, especially in something like: (!a && !b) || c

should I do it in .NET?

Yes

imagine being a python scriptkiddie

Why not:
(x==false)==true
You want to be explicit after all!

This isn't a YLYL thread

Which is more efficient?

Calling this once, creating a new Java Array and cloning the values, and then reading each value.
JNIEXPORT jfloatArray JNICALL Java_finnstr_libgdx_liquidfun_ParticleSystem_jniGetParticlePositionBufferX(JNIEnv* env, jobject object, jlong addr) {
b2ParticleSystem* system = (b2ParticleSystem*)addr;
int32 count = system->GetParticleCount();

jfloatArray array;
array = env->NewFloatArray((jsize) count);

jfloat fill[count];
for(int i = 0; i < count; i++) {
fill[i] = system->GetPositionBuffer()[i].x;
}

env->SetFloatArrayRegion(array, 0, (jsize) count, fill);
return array;
}


Or calling this 50 times
JNIEXPORT jfloatArray JNICALL Java_finnstr_libgdx_liquidfun_ParticleSystem_jniGetParticlePositionBufferX(JNIEnv* env, jobject object, jlong addr, jint particleNumberX) {
b2ParticleSystem* system = (b2ParticleSystem*)addr;

// I don't know c++ syntax
jfloat positionX = system->GetPositionBuffer()[particleNumberX].x;

return positionX;
}

Bitch I just explained it.

How about you make an argument as to why "!" should be used. You know, other than making you look smarter than you actually are.

I mean, it definitely compiles to the exact same assembly
bool check(int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
cmp DWORD PTR [rbp-4], 0
jne .L4
mov eax, 1
jmp .L5
.L4:
mov eax, 1
.L5:
pop rbp
ret
bool check2(int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
cmp DWORD PTR [rbp-4], 0
jne .L7
mov eax, 1
jmp .L8
.L7:
mov eax, 1
.L8:
pop rbp
ret

//code I used to compile with
template
bool check(T a)
{
if(a == false )
return 1;
else
return 2;
}
template
bool check2(T a)
{
if(!a)
return 1;
else
return 2;
}


That wasn't the original example. The original example was
if(!x)

I'm not saying negation doesn't have its uses. But negation like that is prone to errors for future programmers maintaining your code

in haskell this is just

not x
e.g.

if not x then

Measure it.

Most don't use capital letters for variable names more than once, so in the case of NOT it's usually fine. But you can imagine if you later in the code define something containing NOT where you might not consider it like: ANOTHER_DEFINE
The preprocessor will go through the code, insert ! instead of NOT so it's A!HER_DEFINE
which is annoying.

At which point you'd have to change either of the defines, or undef then redefine NOT.
Which is not ideal for a utility macro.
With NOT(X) you avoid far more cases of this annoyance.

> It definitely compiles to the exact same assembly
Irrelevant

>future programmers LIKE YOU maintaining your code

File actions need to be loosely coupled from the service that's hosting them (incl. local files). At that point you're really just using the API for each service you plan to integrate. If you use .NET, there are probably nuget packages for using the API of all major hosts.

>The preprocessor will go through the code, insert ! instead of NOT so it's A!HER_DEFINE
>which is annoying.
No user, that's not how preprocessors work. Stop embarrassing yourself. Preprocessing isn't your find/replace like in a text editor.

See this for more information.

>How about you make an argument as to why "!" should be used.
It's simpler. It's more terse (lower verbosity). It's more standard practice, so most programmers will expect to see it.

These are good things for readability. Making something long and verbose doesn't mean something is readable. That's why Java was such a disaster.

>But negation like that is prone to errors for future programmers maintaining your code
[citation needed]

== introduces the potential of confusing with =, seems like a wash in terms of accidental typing to me.

I just set up a RTMP stream that i stream movies to with OBS.

Now i want to create a simple webpage that displays a player that shows that stream and host it from my computer.

I tried some simple code i found but it says server not found.


Doest anyone have any experience in doing something like this? I have never coded anything like this before.

>Making something long and verbose doesn't mean something is readable
Still less prone to errors

>== introduces the potential of confusing with =
By who?

No programmer has ever mixed up = and ==. Fact.

STOP

>By who?
The one writing the boolean test.
If your argument is that they might forget ! they can just as easily forget the extra equal sign.

Not sure if you're being serious or not.

I used to do this all the time when I was a noob and used ActionScript. Fucked me over because it wouldn't cause any exception at runtime if you did
if (muhVar = "sheeeeeeeeiiiiit") {


Though since then I've used sane langugaes that don't allow that shit to compile.

Yes you are in fact correct user. you can't be selective with your use of ==false and !
Ever, it's simply not allowed.
If you're a person who writes ==false in one situation you must write (a==false && b==false) || c

God forbid you do what suits you best.

My argument is that future programmers who are maintaining code can easily rush through a piece of code (trying to understand how it works), and not notice the negation.

>Though since then I've used sane langugaes that don't allow that shit to compile.
like Haskell

What the fuck is this. I swear I've had issues with this before. I remember being very annoyed at it.
What am I mistaking this with?

I'll probably go with .NET then, my supervisor is going to be upset though, he runs Linux and he said he could make use of such tool

>What are you working on, Sup Forums?

I'm trying to remake a number word converter (i.e. you put in an interger (e.g. 6584) and it gives the words (e.g. six thousand five hundred eighty four) from Java to Python. This is though given the only Python program I made was a shitty temperature conversion program.

then why was yoda conditions invented? checkmate rebels

Stop being ridiculous.

Good luck user, a program like that is actually pretty tricky because there are so many rules in the english language

is that project euler 17

or anything statically typed

>he's not printing out his datasheets
Why? Are you some kind of retarded or just a fat weeb?

.NET runs on linux

>removes the ability to search
Why
Was there a point to this?
Is this just a cheap replacement for a n+1'th monitor?

>What are you working on, Sup Forums?
Premature optimizations.
// Formats a human-readable representation of file size
func readableFileSize(s int) template.HTML {
if s < (1

>How do I do this?
Get precise timing values, somehow. I don't know how you do that in java.

Run the function a large sample of time and average the times.
Then run the function 5-25 times and try to ruin the cache inbetween (load a bunch of junk into the CPU cache by reading and doing useless operations, don't forget to save the results to the compiler doesn't eliminate the dead code). This is to simulate a worst case.
Then you swap the function for the other option and do the same.
Compare. Read the functions to see if you can make either of them better (you could go mad doing this so keep yourself sane and limit your time).
Pick the one that comes out on top and/or is easier to work with.

Also rememeber to profile all your code first. You don't know what's taking the longest amount of time. and where you can get the largest gains.
There's no point in making a part of the program that takes 0.001% of execution time a million times faster. it's already next to free.

>not having a 4k e-ink display

>Good luck user, a program like that is actually pretty tricky because there are so many rules in the english language

It's not that hard, since the integers are formed by pretty regular rules. I was able to do it in Java in an afternoon.

A real challenger would getting number words into an interger.

>is that project euler 17

No, it's much simpler. Although I might try that one. I could perhaps cheat and just count the numbers my previous program generated.

You can make nice notes on some pages :-)
Also mark them with a post-it, if they are important for you're current project

awfully repetitive. can you factor out the first two ifs into a macro at least?

oh fug :-D, it does?
nice

that keyboard is encrusted with buggers

! sticks out just fine, it's an operator, not allowed in other symbol names, it comes first in the boolean expression making it read better (if not x).
Not buying your argument at all.

Acctually need to get a new one. Those little nipples on J and K are nearly gone and I misstype because of that quite often. Sucks, mang :'(

reading the haskell function i made to rotate a matrix by 90 degrees and i genuinely don't understand how it works. i have no idea how i got it to be so concise

haskell really is arkane

not sure what you're trying to do but

docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#GetPrimitiveArrayCritical_ReleasePrimitiveArrayCritical

or use a native float buffer

Thank you so much! I'm print screening this post
I'll write the code I want to test, then I'll do this!

Thank you

I Want Morgan.

>tfw 30% of your project is just Makefiles

J and F, lel*

I just do comments in my PDF or in my notebook program.

But honestly I should probably cull/sort some from the notebook.
It's starting to get messy.

i have pic related it's based af

Why do so less people outside of academia use LaTeX? It just werks.

so you have 7 lines of C++ and 3 lines of make

Fair point.
// Formats a human-readable representation of file size
func readableFileSize(s int) template.HTML {
format := func(n, end string) template.HTML {
l := len(n)
buf := make([]byte, l, l+len(end))
copy(buf, n)
return template.HTML(append(buf, end...))
}

switch {
case s < (1

Well if you're interested in this I'd recommend a few talks who are also worth considering. These are people who probably make things go fast more than 99% of go-fast programmers. So they're good sources.
youtube.com/watch?v=nXaxk27zwlk
youtube.com/watch?v=rX0ItVEVjHc
youtube.com/watch?v=GPpD4BBtA1Y
In order of approachability. They're fast of course, they're talks. But they're all worth watching. The end of the third one is good because it goes through the process of optimizing an arbitrary thing in detail. Which shows you how you think about these things.

But remember, if you aim to make everything go fast you will never finish. Second talk mentions this, you have to put your energy where it matters.
Because people don't care that much about formatting usually and it takes some learning.
That's my understanding anyway.

interface Bank {
public double getBalance(User user) throws BankNoAccountException;
public void addBalance(User user, double amount) throws BankNoAccountException;
public void removeBalance(User user, double amount) throws BankNoAccountException, BankNotEnoughException;
public void transfer(User src, User dst, double amount) throws BankSrcNoAccountException, BankDstNoAccountException, BankNotEnoughException;
}


vs

interface Bank {
public Double getBalance(User user); // returns null on error
public boolean addBalance(User user, double amount); // false on error
public boolean removeBalance(User user, double amount); // false on error
public boolean transfer(User from, User to, double amount); // false on error
}


Which is better?

Also how do i stop obsessing about good interface designs and actually write code?

What should I search if I want to figure out what the distribution of whatever is counted in those percentages (lines) might exist.

Like for instance if this was 100 line it checks out, 70 lines C++, 29 lines makefile 1 line C.
Every multiple of that works. But then there's the rounding. it says .0, so there can be other distributions assuming different forms of rounding (truncation, floor, ceil, typical rounding).

I want to know what that is called.

Don't use Java

When opening this code in a web browser i just get the code displayed in plain text. The guide says it should display a site.

The code is saved in a file.html.

>Which is better?
The former.

>Also how do i stop obsessing about good interface designs and actually write code?
Don't do Java.

No user

Probably the former in java. Exceptions are often bad but it's not a language made for return codes. Like most languages with exceptions they give you little other options.

the first one but you should probably redesign it so you only have valid users in the first place (BankNotEnoughException is ok though)

I'm not webdev but looks like PHP not html, install and configure PHP on your server then save the file as .php

>Don't use Java
No other choice in this particular case unless i want to spend the next 2 years rewriting existing code in another language.
Besides the same thing happens in C++. Even more so in C++ actually because you need to worry about satisfying standard C++ concepts when for example writing your own data structures. Unless you're suggesting a functional language in which case good luck writing a huge multithreaded application that connects to multiple databases with clever one-liners.

I think i'll go with exceptions yeah. Maybe also a BankUser interface with a loadUser() method in the Bank interface.

Do this in your html file
#index.html

Correction

// Paste that code here

Also, I don't see how that'll display that. Your HTML file needs some display elements like also I believe, although I'm no web developer.

>>/wdg/

getBalance :: (?bank :: Bank) => User -> Maybe Double
addBalance :: (?bank :: Bank) => User -> Double -> Maybe Bank
removeBalance :: (?bank :: Bank) => User -> Double -> Maybe Bank
transfer :: (?bank :: Bank) => User -> User -> Double -> Maybe Bank

>Even more so in C++ actually because you need to worry about satisfying standard C++ concepts when for example writing your own data structures.
Well that or simply ignore the standard and use your own shit.
And if I were to be a bit disruptive to your programming style then I'd question why Bank is an interface and not a class. Why you're doing OOP (because it's bad) and more.

But that's just distracting, so keep going. This looks like homework, obviously. Doesn't really matter.

Golang.

>(because it's bad
Why? I'm not the guy who you're replying to but I'm interested. Also, what paradigm do you instead suggest?

>why Bank is an interface and not a class
Because there are multiple banks each with its own unique way of storing money.
I have several systems that don't care which bank the money comes from, as long as it comes from somewhere.
And nah, it's not homework, it's a personal project.

Optimizing some OpenGL code. Removing useless state changes, moving more stuff to VAOs (-> fewer function calls), better shader uniform handling, etc.

Why do so many people cast the result of malloc?

None, sadly. And she barely posts any cleavage pictures, so have fun.

Type safety

There's a .NET program that I want to use that is no longer maintained and has a critical bug in it. I'm trying to fix it by IL weaving with Mono.Cecil, but I've reached an impasse.

The exception is
>Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.

Basically happens when something goes wrong with Delegate.CreateDelegate().

The relevant class, decompiled and fixed up: pastebin.com/shqDPWsw

It's a bit of clusterfuck, basically what it does is look for particular types using the Microsoft.CodeAnalysis API. Anyway, I tried using it in my own project and it ran without a problem.

How the fuck can I track down the issue?