/dpt/ - Daily Programming Thread

Real Programmers Edition #5

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

Attached: theo.jpg (605x420, 32K)

Other urls found in this thread:

dailyprog.org/~ryukoposting/
twitter.com/AnonBabble

Aw, I posted right as the last thread ended.

Reposting
I'm starting a software developer - ui/ux, position in a couple months. It's an engineering position (and not design), but I'm looking for some decent seminal reads. I have no formal background in ui/ux, so it's kind of a weird story how I'm here.

Attached: lbwjfgph7ea11.jpg (800x561, 39K)

Which vim keybindings Firefox extension is best for FF 57+ ?

>Vimium-FF
>Tridactyl
>Vim Vixen
>Something else...

Now that Vimperator doesn't work on new firefox and I need to upgrade, which extension is the most feature complete as vimperator was?

>Using Treehouse to learn Java
>My code isn't running in their compiler even though it's the exact same as the one the teacher uses in the video
>Consider unsubbing because their compiler is obviously broken
>Rewatch the video to make sure I didn't miss anything
>Realise the teacher always saves his files before running the program
>Do the same
>It works

Fuck's sake. I feel like a complete idiot right now. Am I a brainlet, Jow Forums?

Attached: Facepalm.png (900x720, 402K)

nah sounds a bit idiotic on their part that you have to press two buttons to run the code as-is

oops
>Not that user, but please tell me more.
you'll need ibus and then it's ctrl-shift-u

> I feel like a complete idiot right now
As you should

>FF 57+
i thought there were only 15?

Attached: pizzer poss.webm (600x600, 2.87M)

hwat

Get used to these kinds of errors. They will be all you know from now on.

I am about finished with my CS meme degree.
What now? What field has the lowest suicide rate?

Work 2 or 3 years and be promote to non tech positions.

UX is kind of a new field, so their is no seminal books that I know of. One big secret of UX is that it's very much driven by fashion and fads so something that's very relevant now could be dated in a few years. Here's some books I really liked :

- The Design of Everyday Things - Don Norman
- A Pattern Language - Christopher Alexander
- The Visual Display of Quantitative Information - Edward Tufte

Also, the core77.com blog will have references to other stuff.

Well my job prospect emailed me this as a test.

1. SQL scripting – importing/exporting from SQL Server 2012+ to and from Excel

2.Write a small program with a basic web UI, using MVC design pattern, that accepts and Excel file and writes it to the database as per #1 above.

i just got out of CC with a comp programming meme degree and can do basic stuff but im confused. WTF am i doing hiere i go

Attached: flat,550x550,075,f.u2[1].jpg (389x550, 54K)

I have a shell script that runs an infinite loop polling a database. I want to know whether this script is running from a different place (e.g. a separate script, a php file, a simple C binary, whatever). Is there an established way to do this?
>use PID or process name
I can't know the PID in advance (obviously) and the script's name could easily clash with something else (even accidentally), unless I rename the file just to make it more unique.
>use a service runner like an init system or supervisord
I'd like this to be portable and not rely on init systems, and supervisord is a pretty big and bulky dependency considering the rest of my project is pretty small and this is the one single place where I'd use it.

Right now I'm using a lock file as a preliminary solution, but deleting it sounds really unreliable. I'm trapping SIGINT (should probably trap a few others like HUP and stuff), but the file will remain if the script crashes, is killed with SIGKILL, or in fact if the entire machine crashes. Is there anything better?

Typing this out I just had the idea to write the PID to the lock file. Then when checking if it's running, don't just assert the lock file exists, but read it and see if there's a process with that PID, and if its name matches my shell script. Then if the process crashed, that PID will either not exist, or be used by something else. Theoretically not foolproof if I get really unlucky, but sounds robust enough in practice. Does that sound like a good idea?

I have a function that returns a string obtained from a binary file.
Each character found is appended to the string.
So if something goes wrong the function will simply return an empty string.

Sounds reasonable to me but would actually handling errors be better? Throwing an exception for this seems overkill.

>Throwing an exception for this seems overkill.
If the rest of your program depends on your string not being empty you should throw an exception imo.
Actually probably just throw an exception, why not

>1. SQL scripting – importing/exporting from SQL Server 2012+ to and from Excel
Just ignore the job prospect if they're going to pull this bullshit task on you

you store the excel files as binary blobs in the db
asp net mvc framework is probably the easiest mvc
not sure why this needs mvc framework but just use a basic model

did they give you some kind of template to start from?
it's not too tricky to do this assignment with experience but if you're a junior out of college this will likely take you all weekend and then some.

>ifdef is for emacs programmers

Working on a web app which will give people the ability to query Nash equilibrium strategies for different poker situations.

returning an empty string is probably a bad idea
return null, a maybe string or throw an exception

Why does C++ not have monads?

Oh, I actually do have Tufte's Visual Display of Quantitve Info. I'll have to give it another glossing over, thanks.

if your program depends on the string, and if you return null or "", then you still have to check whether the function returned null or "" before continuing execution.

unless you have some fallback, i'd just throw an exception.

std::optional get_str()
{
if (fail) {
return std::nullopt_t;
}

return s;
}

auto s = get_str();
if (s) {
std::printf("%s\n", (*s).c_str());
}

its my best prospect, really like the company.
>you store the excel files as binary blobs in the db
that's fine
>asp net mvc framework is probably the easiest mvc
>not sure why this needs mvc framework but just use a basic model
is there some where i can just grab a basic model ?
>did they give you some kind of template to start from?
nope. is there some where i can just grab a template?
>it's not too tricky to do this assignment with experience but if you're a junior out of college this will likely take you all weekend and then some.
great i just started.
my outline is :
1. create basic DB and populate it
2. export it to excel
3. create macro for sql and excel for importing / exporting
then
4.grab some MVC template and have input masks to verify clean entries and on click ad to db server through excel macro

damn this is larger than i thought, i thought i'd complete it tonight

its really amazing how using an optional in sepples looks exactly the same as using any other pointer type

yep, that's cause of operator overloading:

operator->
operator*
accesses the contained value

operator bool
checks whether the object contains a value

however you could write that as:
auto s = get_str();
if (s.has_value()) {
std::printf("%s\n", s.value().c_str());
}

respond you fucking turds

not programming related you fucking turd, go to the stupid questions thread

in java this is just
get_str().ifPresent(System.out::println);

How about try them out yourself and report back to us you piece of shit

suck my ass you fucking pile of diarrhea

understandable

get fucked cocksmoker

Can I get a code monkey job without a university degree?

Get an AS in Comp Sci from a community college, get experience and have projects. It will be harder and take longer but yes.

doing node.js tutorials today

good for you user, keep at it friend

b-but Jow Forums says it's poopoo

Is programming principles and practice using c++ a good starting place?

c++ is not a good starting place
do the courses at mooc.fi

But I don't speak Finnish

Oh, sorry. I made a tutorial for you on how to translate the site.

Attached: tutorial.png (2231x1068, 1.76M)

I have learned C/C++, SQL, and bash. I want to get more into the CS side now with data structures and algorithms. What do I need to do to learn it right? I have Introduction to Algorithms. Would there be any benefit in going to back to school?

fucking rekt

dumbass 2 year old boomer can't read the fucking web page lmao

hi Jow Forums can someone teach me how to turn a recursive process into an iterative process? I have a quadtree in a JS game and it uses recursion. It eats memory for breakfast (100,000K when checked in chrome's dev tools)

I want to lower it's overhead. How can I do this? Please use a simple example and I'll do the rest. I just need someone to break the ice. Thank you

Why are you posting a jew?

>that 57 year old boomer who doesn't know about FF >= 16

I am currently reading pic related, and it uses C++ as the expository language. I know a bit of C, so reading C++ isn't that hard, however, I know next to nothing about "classes", and there's a whole chapter about classes in this book. How hard is it to grasp this concept, and could I learn it in a short time so that I don't feel lost when I get to the part of this book that deals with it? Thanks in advance.

Attached: thinkLikeAProgrammer.jpg (378x499, 47K)

Think of C structs - except that these structs can also have methods inside of them where you don't have to explicitly pass the struct pointer to the method.

a class is a struct that has functions defined on it, that can "inherit" functions from other structs.

that's basically a big chunk of what you need to know, everything else is the specific rules your language applies to OOP related stuff

It's your fault. Try using a text editor + terminal to make Java. It'll be the same thing you have to save then compile then run. Annoying but everyone does it at first so don't feel bad.

structs can have methods, and can inherit from other structs/classes.

There's little that's different between classes and structs.

can classes inherit from structs and vice versa?

I don't get it. I've never been linked to a Finnish site before. Is it a meme or legit?

lol nvm didn't read carefully enough

Think of classes as blueprints. Instances of classes are objects. Classes define how you construct the object (with the constructor) and its functions (called methods) define what an instance of the class is allowed to do.

For example, the blueprint of a car is the class. The actual car itself is the object and it could have functions/methods like drive() which is what the object can do.

A class is a collection of member functions and member variables.

Rather than putting all functions in global scope like in C, you can group them by a common theme.

Learn namespaces at the same time as structs/classes

If you learn the rest of C++, you'll get this too.

There's some interesting posts online about object-oriented C, give those a Google. They're very interesting

You know how you have strings and numbers?
You can combine them to have more powerful objects. For example, a video game character would have a name (string), a health gauge (number), etc.

Maybe you would have different classes for enemies: a Goblin class, a Zombie class, etc.

It's basically a way to organize code. A powerful concept is inheritance. It's a way to keep the common parts of the code in a common class, instead of copy/pasting and duplicating the code.

Maybe you can have a class Enemy that has the stuff that all enemies have (name, health bar) or can do (drop items when dead). And then you have specific classes that implement only the stuff particular to a given type of enemy (e.g. Zombies can bite).

But you can go pretty far. You can have an inheritance hierarchy where some, but not all, enemies bite.

So you have:

* Enemy
* Biter, which inherits from Enemy
* Zombie, which inherits from Biter
* Wolf, which also inherits from Biter

The concept goes further with multiple inheritance, abstract classes, etc. but you will figure it out.

Thanks for the replies. So they are C structs with functions inside them. I am a bit confused on what you meant by "inherit functions from other structs", but it is a good start. Thank you.
Also, just to see if I completely understand, by "structs can also have methods inside of them where you don't have to explicitly pass the struct pointer to the method", do you mean that is the opposite of doing something like this, where you need to pass the pointer of the struct?
typedef struct Node{
int data;
struct Node* next;
}Node;

Sorry if this is a really dumb question, but I am trying to wrap my head around it.

No, consider the following:
struct Foo
{
int value;
};

void foo_a(struct Foo *foo)
{
foo->value = 1;
}

void foo_b(struct Foo *foo)
{
foo->value = 2;
}

vs.

struct Foo
{
int value;

void a()
{
value = 1;
}

void b()
{
value = 2;
}
};

But that's only true for C++ structs and classes afaik, C structs are different.

We aren't talking about C struct's, are we?

He said he comes from C, so I guess he would compare it to the structs he knows.

This of like this:

Any function you put in Foo knows about the value var, a(), b(), and anything else you add.

Wow, this is all pretty interesting. I am really interested in learning this in a deeper manner. I will try to write OOP in C, and then move to a language that truly uses OOP. Is C++ a good OOP to learn, or is it too daunting for a C programmer? Thanks for all your replies, I greatly appreciate it.

Now I get it. Instead of having different functions, and having to pass the pointer of the struct to each functions, we simply integrate the functions in the struct. Please correct me, if I am wrong. Thank you user.

OP: >I know next to nothing about "classes"
Sounds like he doesn't know much about C structs or classes to begin with.

Java and C# should be completely banned in industry. "Programmers" who use them aren't deserving of the appellation.

i don't fully understand what you mean by checking 'whether this script is running from a different place', but i think you are headed in the right direction with some of your ideas. using the init system is probably the best option, this is still very portable and you get lots of nice stuff for free (especially if using systemd). there are lots of programs that are supervisors like this (init systems, monit, supervisord like you said, etc). you could create something like these, but you are just reinventing the wheel and yours will probably be less reliable. some of these do use pidfiles, generally your program will write its own pid to /var/run/program.pid or just /var/progam.pid then whatever is watching the program will monitor that pid

it's legit, it's the best java learning material I found when I started out

What languages am I allowed to use?

>Is C++ a good OOP to learn, or is it too daunting for a C programmer?
If you know C already, then C++ isn't bad.

Is there a comfy programming channel?
I want some videos to watch while eating. Nothing that requires too much focus, but you can still learn from

C++, Lisp

youtube channel*

is Bjarne's "Programming principles and practice using c++" a good book to dive in, or are there better options available?

>Nothing that requires too much focus, but you can still learn from
You can't learn if you don't focus on the lesson, though

>C++
Is this a fucking joke?

yeah I was thinking the same while I was typing it
idk I'm just getting tired of twitch streams

Not at all.

>C++
c++ is worse than both java and c#

The best. Guarantee it.

All I have learnt from Bjarn is, that std::vector is better than any other data structure, always.

I'm kind of self-taught starting from high school, a little in college and then crushing it in work, so I'm maybe not a good source of good C++ books.

Find the best rated books, look at sample chapters and see if it reads okay to you.

I'm a webdev now!
dailyprog.org/~ryukoposting/

You don't need anything other than C, Lua and Assembly

Lua might be the ugliest language that I have ever seen.

I think learning something like C++ is a you-interactive activity, plus it requires reading and understanding the language by sight.

You're just not going to soak in the knowledge just by hearing it spoken to you.

C++ Primer (the one by Lippman, not Prata) is good

idris & Nim*

idris & lisp*

nimshills pls leave

I like std::vector too, but std::array is a more recent addition but nice if you want fast, fixed-size contiguous data collection.

>idris & lisp*
literally Shen.

...

The size variable, being constexpr, is also generally optimized out.

C is just an uncomfortable C++. The lack of templates also makes it infeasible to do basic thing like swap two variables. A macro cannot declare the necessary type to hold a value, unless you use a void* or some other hack.