/dpt/ - Daily Programming Thread

What are working on, Sup Forums?

Old thread:

Other urls found in this thread:

github.com/NodeBB/nodebb-plugin-write-api
pastebin.com/kuBAhREr
youtube.com/watch?v=53rohjWiAKo
stackoverflow.com/questions/5488608/how-define-an-array-of-function-pointers-in-c)
pastebin.com/wgagEh1d
godbolt.org/g/2Hezpp
microsoft.com/net/core
twitter.com/NSFWRedditGif

Newb here, could really use some help with this webdev-related thing

tl;dr:
- working on a simple client for NodeBB forum software for the sake of learning
- found this: github.com/NodeBB/nodebb-plugin-write-api
- discovered that mynodebbdomain.com/api/login will return a login token of some sort if I send user/pass in a POST request

That github page states that I can use some kind of bearer token or a JSON web token of some sort, but I'm not clear on how to interface my user's login with any of that. Obviously I can create a token manually for each user using the admin panel as per the github readme but that's pointless—I'm going for a functional client here which doesn't require admin intervention for each separate user

Anyone have any helpful tips etc.?
please respond, have yet another pepe

jfc op wtf are you doing

fucking everything up, I suppose.

RAM based forum + chat for ungodly shitposting performance

Whats the best way to pass an array as a template argument. I have an array of function pointers and can not pass the array pointer and size as a run-time argument.

Something like
template< glm::f32vec3 *Palette, size_t Size >
glm::f32vec3 Foo(...)
{...}

>Whats the best way to pass an array as a template argument.
You would pass the type the array holds and the size as separate template parameters.

I currently have my arrays as an std::array type. Is there a way to use this statically in C++11 or should I use simple C arrays. If I use a simple C array then I need to use a templated "ArraySize" for the size parameter. Has to be a cleaner way or ill just settle with that.

Trying to make a visualization for Conway's Game of Life, but running into a weird bug...

I'm updating each cell, but somehow I screwed up the detection for the "alive neighbors"

here's my output (top is the grid, bottom is the number of neighbors each cell has)

------------------------
- - - - -
- - X - -
- - X - -
- - X - -
- - - - -
------------------------
0 1 1 1 0
0 2 1 1 0
0 2 1 1 0
0 1 0 0 0
0 0 0 0 0


Here's the relevant code... any help?
pastebin.com/kuBAhREr

>Conway's

Heh. You're updating the board you're checking. You need to use a second board or mark the board so you can tell the difference between the current and previous cycle. Right now, those things are seeing a mix of the current and next cycle updates.

youtube.com/watch?v=53rohjWiAKo

Don't std::arrays already have a templated size argument?

I'm not sure I fully understand what you're trying to do, but here's a small, "hope I'm doing the right thing", suggestion:

Template
void foo()
{
//If (int *) is an array of integers, and (retType* *) is an array of function pointers, couldn't you do:
/*
//First is for function pointer, second is for array... I think/hope
retType (*bar) /* param list */ * functionArray { retType (*bar1) /* parameter list */), retType (*bar2) /* param... */), ...
*/
}

Actually, you're trying to do the right thing, but you're ignoring your returned grid, and you're referencing the original instead of copying it in the update function.

Why do you hate Indians so much?

yes. Im talking about passing an std::array as a template parameter.

Why do you want to?

template
T x(typename T::value_type p);

x(false);

Not him, but I used to live in a part of Southern CA that was heavily Indian. Never again.

I'm sure you have plenty of anecdotes of how wonderful Indians are to be around and what great coworkers they make, but for every one of those I have a counter example.
I base my opinion on my own experiences.

Is this sort of what you're looking for, but with templates?

/*Arrays follow the normal C syntax of putting the brackets near the variable's identifier, so:*/

int (*foo_ptr_array[2])( int )

/*declares a variable called foo_ptr_array which is an array of 2 function pointers.*/

/*The syntax can get pretty messy, so it's often easier to make a typedef to the function pointer and then declare an array of those instead:*/

typedef int (*foo_ptr_t)( int );
foo_ptr_t foo_ptr_array[2];

//In either sample you can do things like:

int f1( int );
int f2( int );
foo_ptr_array[0] = f1;
foo_ptr_array[1] = f2;
foo_ptr_array[0]( 1 );


(source: stackoverflow.com/questions/5488608/how-define-an-array-of-function-pointers-in-c)

I live in Leicester

No more like
template
void Honk(int blah)
{...}

template
void Bonk(int blah)
{...}

auto ProcList[] =
{
Honk,
Honk,
Honk,
Bonk,
Honk,
Bonk
};

ProcList[index](5555);

AHHHHHHHHHHHHHHHHH!!!!!!!!!!

just fucking shoot me

bang bang

Okay, i changed a bit of code (const correctness in Java, at least an approximation of it, and not ignoring the new boolean[][] grid I create), but the output is still a bit messed up


BEFORE ASSIGNMENT
------------------------
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
------------------------
AFTER ASSIGNMENT
------------------------
- - - - -
- - X - -
- - X - -
- - X - -
- - - - -
------------------------
NOW UPDATING GRID (Now showing how many alive neigbors a particular cell has):
0 1 1 1 0
0 2 1 1 0
0 2 1 1 0
0 1 0 0 0
0 0 0 0 0
AFTER UPDATING
------------------------
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
------------------------


Pastebin code:pastebin.com/wgagEh1d

Okay, i'm not too well-read in terms of the C++ spec, but I'm unsure if you can have a list of different types of function pointers in an array. (the way I'm thinking about it, which is probably wrong, is that arrays are containers of one data type. a function of type has a different type of function pointer than a function of type

indians are nigger tier. the only difference is that niggers are more violent, while curry niggers try to abuse loopholes.

What smartphone operating system is best suited to develop augmented reality apps on?

I thought this was a technolo/g/ board, not Sup Forums

>tier
Please learn English before you use this website

...

It works. So long as the prototype is the same it doesnt matter what you put there.

I am doing it elsewhere in my code, but for this I am passing in an array.

Here's some sample code I typed up. The only difference for my current case is that I need to pass an array as a template argument.

godbolt.org/g/2Hezpp

And yess of course it will generate new instances for each function pointer.

Your replies only perpetuate it, homo.
Be the change you want to see &c.

Whhy not just pass an initializer list or variadic argument instead? So you'd call:
proc[i](1, 2, 3, 4);


Or:
proc[i]({1, 2, 3, 4});

Still learning design patterns desu.

Am I right in thinking this is what the decorator pattern is?

var loliWith = {
gun: function(loli) {
loli.hasGun = true;
loli.speed -= 5;
},
armour: function(loli) {
loli.hasArmour = true;
loli.health += 25;
loli.speed -= 10;
},
innocence: function(loli) {
loli.isVirgin = true;
loli.health += 10;
}
};

function createLoli(name, age, decorateWith) {
var loli = {
name: name,
age: age,
health: 100,
speed: 100
}

decorateWith.forEach(function(decorator) {
loliWith[decorator].call(undefined, loli);
});

return loli;
}

var sarah = createLoli("Sarah", 10, [
"innocence",
"gun",
"armour"
]);

because the context that is calling the "ProcArray[index](...)" knows nothing of the array the function should be using, and shouldn't.
It's simply going "ProcArray[index]( SomeData )"

>design patterns
STOP

So how about this?
#include
#include
#include

template
size_t Multiply(std::array v)
{
size_t result = 0;
for (const auto &elem: v) {
result += Value * elem;
}
return 0;
}

int main(int, const char **)
{
auto v = Multiply;
return 0;
}

The problem is now that you'll have to know the size beforehand since it's a compile time constant, not VLA.

You have to learn design patterns to write comfy code otherwise it's just uncomfy spaghetti desu.

this is your chance to take the true path

VPet Monster Hunter

App for android. Just to spend time.

This is still passing the array as a parameter. But not as a template parameter. I can not change the prototype of the function. This missed the whole structure entirely seen in: The "size_t Blah(size_t)" prototype cant change as the calling function has no way of knowing the array that configures the templated function. Id rather get back on track on the topic of passing an array(or, pointer-size) as a template argument. The "just pass it as a function parameter" talk can stop.

If I wrote a simple kernel space program with the following code:
for (uint8_t *p = 0; p < reinterpret_cast(0xffffffff); p++)
{
*p = 0;
}

And booted it on real hardware, what would happen? I'm more interested in the long term or permanent effects.

probably weird shit to all your peripherals that have memory mapped IO

eventually the program is going to over-write itself and nothing really happens

Add to that:
for (uint16_t p = 0; p < 0xffff; p++)
{
outb(p, 0);
}

Before the memory wipe loop.

for (uint8_t *p = 0; p < reinterpret_cast(0xffffffff); p++)
{
if (p < __KERNEL_START || p >= __KERNEL_END)
{
*p = 0;
}
}

Ok what now.

Why does the loli get more health if she's a virgin?

I hate this meme, girls who have lost their virginity are not worth less than girls who haven't.

is there a better way to do conways than to just have a fuckhuge 2d array?
>shit takes forever in any language when you have > a few thousand in length and width

>girls who have lost their virginity are not worth less than girls who haven't.

t. used-goods

Hey, what are some good chat rooms for learning. I've been fucking around with python, but also have been doing some vanilla JS, and other front-end stuff.

Is there anything where people are up late just bullshitting? discord / gitter / irc

idc. I just need somewhere to go and chat to keep my motivation to learn.

Hey, guyse, how can I improve my formatting?

Never mind the actual content.
package flatfileextractor;

/**
* Substance objects, suitable for further usage.
* The constructor takes specific string arrays - lines split by tab from a Substancefile, which are identified to describe a Substance.
*/

import java.util.*;

public class Substance {

private List Synonyms = new ArrayList();
private long nodeId;
private String casCode;
private String euIndexCode;
private String einecsCode;
private boolean declarationDuty;
private boolean isUnwantedIsUnspecified = false;
private Boolean isUnwanted;
private boolean isProhibited;
private boolean isReach;
private boolean isDeleted;
private boolean isHidden;
private int amountOfSynonyms;


public Substance (String[] attributes) {
this.amountOfSynonyms = 0;
this.nodeId = Long.parseLong(attributes[1]);
this.casCode = attributes[2];
this.euIndexCode = attributes[3];
this.einecsCode = attributes[4];
this.declarationDuty = "1".equals(attributes[5]);
this.isProhibited = "1".equals(attributes[7]);
this.isReach = "1".equals(attributes[8]);
this.isDeleted = "1".equals(attributes[9]);
this.isHidden = "1".equals(attributes[10]);
}

public void addSubstanceSynonym(SubstanceSynonym syn0) {
this.Synonyms.add(syn0);
this.amountOfSynonyms++;
}


public String getFirstLocaleSynonymName() {
SubstanceSynonym dummy = new SubstanceSynonym(); //is returned if nothing else found.
try {
Locale mylocale = Locale.getDefault();
String languageCode0 = mylocale.getCountry();
for (SubstanceSynonym syn : Synonyms) {
if (syn.getLanguageCode().equals(languageCode0)) {
return syn.getName();
}
}
return dummy.getName();
} catch (IndexOutOfBoundsException e) {
return dummy.getName();
}
}

}

that's a stupid loop

depressing!

I am currently learning about C. What's the difference between c and c++? is GUI programming in C viable? what exactly is the C standard library? Why is 'printf' not a part of it?

formatting is fine
add spaces around beginnings/ends of control structures like if/for/try/catch/except/while; except for things like the if within the loop in this example
split up variable declarations/definitions by the their similarity and or type
also, avoid using the Boolean class unless you really need it; it's not particularly useful desu

read wikipedia for an intense comparison of the languages

also, printf is in the c standard library; you need to ``import it'' via the header file where it is declared
#include

thanks, will do.

>avoid using the Boolean class unless you really need it

i seem to really need it, because the attribute can be either true, false or exciplitly undefined.

hmmmm; an enum may be appropriate

what's the complete usage of that variable

unknown - yet. i simply have to store it in a appropriate way, for later usage.

a Substance might either be unwanted (isUnwanted = true), not unwanted (isUnwanted = false) or have an unknown unwanted status (isUnwanted = null).

Still working on my web 1.0 application.

It's still fast as fuck, with its zero external js dependencies, simple css and common-sense markup.

The stuff on the back end is growing rather enterpricey, with DTOs and DAOs and all that shit, but at least I haven't wired up injectors yet.

> But user! You now have to decide at compile-time what classes to load instead of parsing a 2mb xml file!

FUCKING EXACTLY. Do you know how much easier my life has become after I removed the magic, and when I needed to, built proper abstractions to handle complexity?

I don't even use ORM. I just use SQL. My data model works just fine for that. Since i actually know how to write SQL, I can do 90% of the modelling on the database, and just pull out the objects I want.

And finding all employees with names beginning with "Ad", who have themselves as a manager, and sorting them by wage (descending) is faster on a database than anything I would be likely to write myself.

Actually using the SQL database as something other than a glorified object storage feels amazing.

> But you're writing in Java! Isn't that a terrible language?
No, it isn't. It's a terrible language for small programs, and it's mediocre for exploratory programming.

But for things like talking to a database, creating some model, and pushing it to a webpage, it's actually really fucking great.

> But I don't like JSP/JSF very much
Then don't use it. Use something like Freemarker or Thymeleaf if that's more to your liking.
Instead of writing web.xml, you can use Play or SparkJava.

I'm not sure if it's Stockholm syndrome or if it's finding libraries and frameworks that actually makes my life easier instead of harder, but Java feels comfy now.

well, seeing as you haven't decided how to use it yet that seems fine
a boolean should really have only 2 possible values, however

you may end up treating isUnwanted == null as either of the two boolean values, in which case you can just set isUnwanted to a default boolean primitive value

if you really do need more than 2 states, consider using an enum or an int instead

Just finished programming Conway's Game of Life!

(The 2-D array was just for debugging purposes... Makes it easier to work with, imho)

Yes there are.
Google Conway optimizations and find a treasure trove of neat shit.

Well, ignoring the contents, which is hard, I'd say that the only things that I can think of is:

> group variables by type, and leave a space between types
But that's if you have a truly disgusting amount of variables. I've had objects with 30+ variables. Grouping them together in some coherent fashion really helped out there.

> Use diamond notation.
This means that there's less noise in your code.

Some people (like me) prefer to have catch and else on their own line, others don't. Either is fine, but it's a thing to consider.

Also arg0 names for args are stupid. Put semantic meaningful names there always.
Instead of syn0, synonym is a better name.'

But that's small fries. your code looks decent as is.

I picked up GameMaker Studio when it was a humble bundle. I know Unity is better/ more commonly used in the industry, but I like what I've done with GMS so far.

Other than that, I've been messing around with Rust. Been a pretty educational break so far.

Is experience in C# + SQL or in Java app development more valuable?

SQL is always really fucking useful.

Java/C# should be pretty similar in value in this regard.

me too, i spent $1 for the professional

what kind of game you making

is there a function like strerror() but prints out the text of the enum rather than its description?

There is no point in learning Swing today, right?

I should just go for JavaFX.

Swing is pretty good for basic desktop applications, which is not done in Java anymore.

JavaFX is more of the same.

Is it true that .NET will become multi-platform soon and everyone should basically start learning C# RIGHT NOW?

>Is it true that .NET will become multi-platform soon
yes. microsoft.com/net/core
> everyone should basically start learning C# RIGHT NOW
that's up to you really. C# is pretty based as a language though

I'm SOOOOOO fucking sick of this.
People actually assume that functional and OOP are the only two programming paradigms.
It's not worth to tell these people anything because they're clearly dumb as rocks but it frustrates me to see people so far out of the reach of common thought.

Why?

You want to build a basic desktop application?
You have languages like Python for that.

C# isn't all that great a language. It's approximately what happens when Java 1.4 fucks Delphi.

Java 8 is moving closer to Common Lisp. With two decent-to-good GUI libraries.
And yet, nobody would suggest that everyone should use Java for everything (without being paid money by Oracle).

It's not that C# is a bad language, but don't get caught up in the hype. Take a cup of tea, think about it, and then make a calm decision.

>Microsoft
It's a bad idea to adopt anything Microsoft makes because they have a good history of trying to lock people to their platform.

And usually you don't really get anything for it, like with DirectX.

how do I write business logic how do I know what to do what is a domain model how does using a framework help me at all if I have to ask these questions in the context of a DSL is programming being made unnecessarily complex as part of a corporate conspiracy for sabotage or a clandestine one for control how is app formed how do I write a jump() function in a video game what is a video game can I write tests for it someone hold my hand my feet hurt

has anyone here worked with Swift? (the Apple forced meme?)

how bad is it?

>is programming being made unnecessarily complex
Yes.
>as part of a corporate conspiracy
No. It's just people being stupid and thinking they are helped but useless crap. So now you have to learn the useless crap to do something that was originally simple.

>mfw C++ made me think OOP is just about unifying procedures and variables into objects
I hope I'm wrong.

>I hope I'm wrong.
Well you are but I don't see why you'd hope for that.

float *f = new float{0.0};
long *i = reinterpret_cast(f);
std::cout

OK, in what way I'm wrong?

Any interesting books out there for learning C#? Preferably something that tries to keep things fun. I don't have a whole lot of experience, and I'm trying to find some motivation to work on something.

Is this good or bad design?

public void testCorrectFormatting() {
this.currentFile.testCorrectFormatting();
}

Generally, how do I get an object to make its object call a method?

> reinterpret_cast
no i won't

>Preferably something that tries to keep things fun
If you've made your way here, you must know there's no fun left.

You should use int32_t when reinterpreting a float. The long data type can be 32 bits or 64 bits depending on the operating system and ISA. Ideally, the long data type should never be used for anything other than platform-specific typedefs.

can i just do the originally simple thing i am made to feel like it's a nonfunctional toy because i don't have a fancy logo and the implementation is less than 50,000 SLOC and I understand how it works

also did you ever notice that you can talk about something where you actually know what you're doing but if you don't speak in a confident manner people think you don't know what you're doing and vice versa you can be full of shit buf it you have confidence than the world is your oyster what's the fastest way i can kill myself in c++ without libraries

I'm a math genius but never learned any programming. I did some basic Matlab stuff in college if that counts but I hated it. Should I learn to program? Where should I start?

probably haskell or F#.

lol no nice contrived shit example

don't listen to

For what reason m8?
F# is ez mode for 300k starting.

>ask actual question about programming on /dpt/
>no answers

>"OLOLOL OOP/JAVA/SEPPLES A SHiT :DDDDD
>get drowned in (You)s

i cri evrytiem

half of /dpt/ is retarded and the other half is deliberately shitposting to kill time

What about the third half?

...

They're too busy actually working on shit to post here.

not that guy and a complete noob
is F# used so much that just saying you know it will land you a job?

what is this anime?

no

F# and especially haskell are mostly irrelevant shitlangs

here again
I've read That C and Java are the two main starter languages to consider. Should I just pick one and start?