/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: dpt.gif (278x296, 2.51M)

Other urls found in this thread:

play.golang.org/p/EZZqB7mWbfq
wiki.haskell.org/Let_vs._Where
sean-parent.stlab.cc/presentations/2013-03-06-value_semantics/value-semantics.cpp
twitter.com/SFWRedditVideos

nth for Nim!

it's probably overkill for the use case, but here's an approach using parser combinators
module Quotes where
import Text.Parsec
import Text.Parsec.String

names = ["user", "Ralph", "Susan"]
notQuote = noneOf "\""
quoted = between (char '\"') (char '\"') (many notQuote)
skipQuote = quoted >> return Nothing
skipNQ = skipMany notQuote

match = try $ do
x

>1th
>oneth

zeroth

Friendly reminder that if you don't understand this code, you're literally dumber than the average Go programmer and the exact kind of person that Go was made for.
play.golang.org/p/EZZqB7mWbfq

nth for filtered

>hasklel

Anyone got an idea if there's a better way to populate this structure without changing the mesh to a simple array?

typedef struct {
float x, y, z;
}SDLS3D_Vector;

typedef struct {
SDLS3D_Vector p[3];
}SDLS3D_Triangle;

typedef struct {
int tri_number;
SDLS3D_Triangle tri[];
}SDLS3D_Mesh;

SDLS3D_Mesh* SDLS3D_CreateMesh(int size)
{
SDLS3D_Mesh *mesh =
malloc(sizeof(SDLS3D_Mesh) + size * sizeof(SDLS3D_Triangle));
mesh->tri_number = size;
return mesh;

}

main()
{
SDLS3D_Mesh *cube = SDLS3D_CreateMesh(12);
cube->tri[0].p[0].x = 0;
cube->tri[0].p[0].y = 0;
cube->tri[0].p[0].z = 0;
cube->tri[0].p[1].x = 0;
cube->tri[0].p[1].y = 1;
cube->tri[0].p[1].z = 0;
cube->tri[0].p[2].x = 1;
cube->tri[0].p[2].y = 1;
cube->tri[0].p[2].z = 0;
....
}

You can tell what I'm doing here gets cumbersume really quick and I can't find any other methods

Does it look for the first duplicate in an array of indexes?

Take coding boot camp or self study?

Tired of working in trades, I unironically want to learn to code (web app dev). I've got the markup languages down and some JavaScript so far. I'm looking into learning mean stack or Rails/Ruby. But I'm having trouble with the big picture on how to put everything together to make professional grade products. Would it be better to take a code boot camp or just keep wading through free resources and udemy classes?

of all the trades to pick, why the fuck do you mongs pick programming?

use constructors

Web app dev is literally 100% self teachable. Just learn HTML, CSS, and some Javascript plus a framework (React, Angular or Vue).

because it's in demand

>I'm having trouble with the big picture on how to put everything together to make professional grade products.
You'll get there, especially web development is such a mess of different technologies and languages and poor design decisions it does take time. Just learn one thing at a time, and practice making finished products and you'll get there in no time.

mesh is not ready to go after that function as you did not set tri. I probably would have done two separate allocations, but you don’t have to. What is cumbersome about your approach? The only thing I see is renaming the triangle struct member to point instead of p, and a few other nicer names so it’d read more like
myMesh.triangles[17].point[1].x = 1.2;

BuildIdentityMatrix();
BuildMatrix( 1, 0, 0
0, 1, 0,
0, 0, 1);
BuildTranslationMatrix(100, 100);
What do you have against functions?

Also I would really avoid making a 3x3 Matrix out of 3xVec3's. I get why it's tempting to, but not only is the naming weird and inconsistent with normal Linear Algebra practices, but it's less data-efficient and doesn't lent itself to the way values are actually piped through the graphics pipeline.

typedef struct {
n_00, n_01, n_02,
n_10, n_11, n_12
} MatrixTransform
etc.

When is a project "worthy" of being shared on eg. Github?

>Github
>"worthy"
I throw up any old test code on git hub. The only criterion of worthiness is if I want to save it for whatever reason, because I might want to look at it later, and whether I can be arsed to upload it.

Cool I'll keep plugging solo. What should I learn for back end?

Well I'm a broadcast/Telecom technician. So I'm literally driving up mountains and climbing towers. I'd much rather stay inside and type all day, I'm tired of physical exertion.

Always, user :)

It is actually possible to do backend in Javascript, but practically any language can be used as a backend if you use a RESTful API. Also at some point you will want an SQL database but that shit is very easy to learn and google so don't dive too deep unless you feel like you really want to be involved in database shit.

I would be glad for some physical exertion once in a while at my job, for a change. Sitting on the same chair in the same office corner day in day out gets old.

Anyone use Visual Studio?
How can I check the type of an expression/variable? Basically CTRL+Shift+P in IntelliJ but in Visual Studio.

I still don't quite understand the difference between let and where in Haskell.

i share stuff that i think others might find useful (e.g. libraries or applications i wrote) and projects that i'm proud of (works properly, has a good ui, i like the way the code turned out, etc.).
you never know who might use it.
at some point in school i wrote a library, never advertized it and didn't look at it for a few years, until i realized that a few years later it was forked to be used in a popular os. they rewrote a bunch of it, but i'm sure my initial codebase helped a bit with getting them started.

Yeah I feel the same. Also uploading stuff to public version control is a really comfy way to back up your project :)

foo {
...
}

or

foo
{
...
}

and why?

Whichever one you like best. It doesn't matter.

while they're often similar and only make you read the code differently, they sometimes can be used in different contexts and it may sometimes be easier for the compiler to optimize something.

you're everything wrong with nu-/dpt/

Attached: 1548911036299.jpg (1052x1342, 402K)

first one is boomer shit, an artifact of when vertical screen space was scarce. if you aren't working from a 1366x768 resolution, there's no reason to use it.

fuck off cshart

thanks, i love you too user!

Attached: 1525137042534.png (1172x675, 20K)

Personally prefer the second. It makes more sense and is more readable to have the opening and closing brackets align.

The former is more common though. Codestyle at work dictates the former. Frustrating.

So how do I know when to use which?

wiki.haskell.org/Let_vs._Where

print(y)
{
print(x)
}

// vs

print(y)
if z {
print(x)
}


Notice how the start and end of the blocks match regardless of whether the block starts with an if label or not. There's no semantic reason to try to align the actual braces, aligning the start and end of a block is enough.

>weebshit
you're everything wrong with everything.

Yeah I read that before I asked here. Didn't stick.

in that case, maybe just write some more haskell code and don't worry about it.
you'll come across cases where it's obvious which one to use and cases where it's simply just a style preference.

not using c++ (yet?)

I think you misunderstand. my above code works, but it takes a ton of lines to populate a mesh and I want to reduce those.

I didn't think of using a populate function when I made that post.
Haven't read through all of the material yet so I don't get where the problem is, but I'll keep that advice in mind and maybe go back on my current approach.

Ok. Thanks.

When I disassemble an object I get this
0000.. second:
...
0080... first:
...

Is there any way to control the ordering such that first is at 0000..?

Why the fuck is everyone telling me this is bad style?
struct Base {
virtual ~Base() = default;
virtual void process() = 0;
};

struct Derived : Base {
const int x;
Derived(int x) : x{x} {}
void process() override;
};

SO told me to add ugly accessors... I don't need accessors. I just need an immutable data structure with those two virtual member functions.

it's fine

class Example {
// Method that takes a "method" as argument
static void exampleMethod(Runnable toRun) {
toRun.run();
}

// Method to pass
static void sayHello() {
System.out.println("Hello");
}

public static void main(String[] args) {
exampleMethod(Example::sayHello); // prints "Hello"
}
}

Does this create a new thread when .run() is called?

Forth!
>How can I check the type of an expression/variable?
By hovering over it

Accessors for what?

Also, sorry if this is a dumb question, what's a SO?

stupid frogposter

No, it doesn't create a new thread. Runnable is an interface with a run method, that's it.

Another Haskell question.
How do I write a test module for another module, that tests functions that the module to be tested doesn't export?

Is that possible? Am I being an idiot?

>Accessors for what?
The member variable of Derived.
>Also, sorry if this is a dumb question, what's a SO?
I should have written Stack Overflow.

I think so too. The C++ community seems to be full of people who follow these OOP principles religiously.

no

>Am I being an idiot?
yes
you *could* use the CPP extension to use C preprocessor macros

you need Thread::start to run the runnable in a seperate thread

...

Thanks

It's ok. But you can go full sean parent and do type erasure to handle polymorphic objects as value types:
sean-parent.stlab.cc/presentations/2013-03-06-value_semantics/value-semantics.cpp

Lisp is the most powerful programming language.

That's pretty interesting. This kind of reminds me of Go's interfaces because implementation of the interface is implicit.

>The member variable of Derived
Oh. I kind of thought of that as private. Dumb of me.
Nah, it's fine. No need to go overboard with unnecessary crud.
It's a bit of a style consistensy question to not mix code like
obj.x = x;
obj.setY(y);

but you seem to know what you're doing, so who cares. I'd say not using mutators if you can get away with it looks nicer.

>he uses OOP retardation.
kys faggot.

C++ was a mistake.

OOP-style accessors, like singletons, are almost always a bad idea. If your type has strict invariants, you'd use methods that contain the logic to preserve them. If the type is just a record without any invariants, then just make its members public.

C++ was a lot of mistakes

C++ was only two mistakes.

This post is a mistake

Most C++ programmers have told me that structs should only have trivial member functions and never virtual ones. Then they tell me that classes should never have public variables. In the end, I'm left with
class Base {
public:
virtual ~Base() = default;
virtual void process() = 0;
};

class Derived : public Base {
const int x_;
public:
Derived(int x) : x_{x} {}
int x() const noexcept { return x_; }
void process() override;
};

which is kind of ridiculous.

"let x = ... in e" x is scoped to the expresison. You can only use variables that are known in the expresison and it can only be used in the expression.
"where x = ..." x is scoped to the current functionial equation. You can only use variables that are known in every part of it and it can be used in every part of it. Slight caveat in regards to "current functional equation": pattern guards are equivalent to a case expression, so they count as a single functional equation.
Every "where" can rewritten as a "let", but when you can use a where it tends to look better.

There are performance subtleties but don't bother with them for now.

the solution is to stop listening to C++ programmers

IMO structs should never have member functions, but it's fine to have a public variable in a class.

perhaps you should do what you feel is best instead of listening to other people
virtual functions are literally as expensive as dereferencing a poiinter (not expensive)

I know how virtual works. I'm mostly concerned about writing code which will get me a job.

then you should use virtual functions and maybe accessors too, C++ developers are not super-anal about encapsulation, that's more Java territory

how do I structure my GUI code? now it's just a single huge file with many functions in the same namespace, in the same class and with many global variables

Attached: 1530949478985.jpg (768x960, 51K)

Because they drank the OOP koolaid.

>classes and global variables
why

I have a file for each gadget type
and then I have files for each visual style

>classes should never have public variables

Only if you foresee changing how the variable is encoded. Like a complex class might change from storing real and imaginary and instead store magnitude and angle or store both with a flag stating which needs to be recomputed.

>how do I GUI
nobody has figured it out yet

>I'm mostly concerned about writing code which will get me a job.
This mentality is where 99.9% of the needless bloat OOP hierarchies and design patterns comes from. I bet whatever you're working on doesn't even need to use classes and inheritance and you're awkwardly shoehorning them in just to signal that you can use those tools.

>dereferencing a pointer
>not expensive

>I bet whatever you're working on doesn't even need to use classes and inheritance and you're awkwardly shoehorning them in
extreme projection

>I bet whatever you're working on doesn't even need to use classes and inheritance and you're awkwardly shoehorning them in just to signal that you can use those tools.
Absolutely, one hundred percent true. My project would be about half of its current length if I were writing C-style code.

correct

>extreme projection

I've seen it before.

yeah let me just wait 100 cpu cycles just to call a function

Depends on the pointer. vtables tend to be pretty cache-hot.

>t embedded dev

>drinking the cache autist kool-aid
run some tests before you spout off retarded shit

Then why aren't you? You know C++ isn't Java and you don't need to use classes. Use C++ features when they makes your life easier. Nobody looks down at you for writing code that's C like (unless if you use #defines, those are cancer).

who

(You)

who?

What's an actual good book for learning C?
Something that teaches good practices, etc.

such a lust for revenge

Use a declarative Markup Language

c primer plus