/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

github.com/yegor256/eo
youtube.com/watch?v=X36ye-1x_HQ
twitter.com/SFWRedditGifs

first for C#

Reposting since the thread was dead
(You) here.

Would you say, (based on your feedback) this is a fair TL:DR to entering the Programming Industry?
1. Learn more Python, then Java
2. Take some beginners Comp Sci courses on Coursera/edX
3. Actually get good at Python/Java
4. Start learning C++
5. Wipe my ass with my Toilet Paper diploma and look for a job

yeah fuck norskmaend
sut min brune pik

>Python then Java
Fucking shit advice

Real thread:

A puzzle-platformer.

C + OpenGL 3.3 + GLFW + gl3w + portaudio.

Python for level generation from images.

holy shit who cares just get gud
start programming that's how you learn

No, this is not the real thread, let it die and come here

Why exactly CS?
Are there other degrees?

>Learn more Python, then Java
Wouldn't agree with this generally speaking, but your first languages should be based on what you actually want to do.

One does not typically do the same things with C#, C, and R.

If you just "want a job" then learn Java first. C# also has a fuckton of jobs, and C++/C/Python have plenty after that.

>not in English

What is the book in the OP? Looks pretty easy to understand.

> What is the book in the OP? Looks pretty easy to understand.
SICP

SICP chapter 1 is the square part and chapter 3 is the cons thing

>claims to be a programmer
>can't figure out a language very similar to one he is fluent in

>SICP
Well, never mind, I guess.

I've tried starting both that and K&R and kept waiting for them to show me something useful and productive.

K&R is just a book about C, what did you expect?

What can I read to learn about various data structures?

anybody here ever used a fibonacci heap or a van emde boas tree?

Why .NET isn't anywhere wide as Java?

Could someone help me write a method to clear (initialize/reset) elements in an array based priority queue?

free(array)

for(i=0;i++;i

Nothing comes close to Java's market share.

I'm curious what it will look like 10 years from now once .NET Core becomes more robust and Mono/.NET Framework merge into a FOSS state of existence with more device penetration.

I'm creating Abstract syntax trees for my programs.

what should i call the function that creates the nodes?

make_node
mk_node
create_node
...

if the queue is contiguous in memory why not try memset(buffer,0,sizeofbuffer)? Its usually faster than just writing a loop.

How does strcmp() work?

I know what it returns, but how does it actually work? What does it check for?

Because I'm comparing strings that are obviously different and strcmp returns 0.
So whatever strcmp checks for these strings have in common despite having different characters.

for example:
const char *hash = "50FhJkW";
cont char *new_hash = "50hjHHd";

if (strcmp(hash, new_hash) == 0)
{
printf("%s",new_hash);
}

will print out every new hash I generate despite being different from the original on a character by character basis.

node.new

it's a priority queue, it probably isn't contagious

if you want lg(n) time anyway

node_create

NAME
strcmp - compare two strings

SYNOPSIS
#include

int strcmp(const char *s1, const char *s2);

DESCRIPTION
The strcmp() function compares the two strings s1 and s2. It returns an integer less
than, equal to, or greater than zero if s1 is found, respectively, to be less than, to
match, or be greater than s2.

RETURN VALUE
The strcmp() function returns an integer less than, equal to, or greater
than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than,
to match, or be greater than s2.

That doesn't answer my question. Do you have poor comprehension?

What language has OOP implemented right?

int strcmp(const char *cs, const char *ct)
{
unsigned char c1, c2;

while (1) {
c1 = *cs++;
c2 = *ct++;
if (c1 != c2) {
return c1 < c2 ? -1 : 1;
}
if (!c1) {
break;
}
}
return 0;
}

github.com/yegor256/eo

smalltalk and ocaml

Nothing will be printed with your code. If you're going to post an example snippet, at least post one that shows the problem you're having.

I want to track my sales from sites like redbubble myself and was thinking of using Python to write a script that read my emails, and used that information to fill a spreadsheet of my sales and sales times. Is python a good choice for this? I'm pretty new to coding but I don't feel like this sounds too hard to do.

Yeah python is fine.

>ocaml
I'm an OCaml lover but pretty much no one uses its OOP facilities though. I'm sure we'd find some shortcomings in it otherwise.

I don't like Python, but for your task it's OK.

What's your program structure? If you're doing something like C++ or Java where classes can have member functions, and you have the syntax tree as a separate structure from the nodes it contains, I'd suggest something like SyntaxTree.addNode(). If you're doing C-style ``OOP", on the other hand, my convention is to create new structs "manually", using either stack or heap allocation, and then calling an "init" function to set its initial values. To emulate C++ namespace behavior, I prefix the function name with the struct tag name, followed by an underscore, e.g. node_init() to initialize the value of the first node. A pointer to the object itself is passed as the first argument.

Absolutely.

Dependent types completely invalidate OOP. You don't need encapsulation to indirectly enforce an invariant any more, you just make the invariant part of the type.

>I'm comparing strings that are obviously different and strcmp returns 0
I just ran your code and strcmp is returning -34, not 0.

>-34

If you don't learn a second language it is very unlikely that you will become a good programmer.

Yes, -34.

This, I'm going to learn 日本語

>hash
Are you comparing binary values or actual strings? If your value contains a 0 byte, strcmp will stop at that point.

If that's the case, use memcmp instead.

I am bilingual

This, pretty much.

OOP has been on the ropes for a while but when dependently typed languages enter the mainstream, it will be completely obsolete.

Sadly, like COBOL, it will cling on for decades in legacy systems.

Good.

Xould you spoonfeed on dependent types?

The value returned by strcmp is only defined to be less than, equal or greater than zero.

The implementation he is using is returning the difference of 'F' and 'h'. For easy calculation in your head the difference in ASCII between lower case and upper case is 32.

youtube.com/watch?v=X36ye-1x_HQ

>46 minutes video
Something to read, maybe?

>use struct pointer in inline asm
>g++ optimizes the whole thing away
>make it volatile
>g++ takes 5 minutes to print all the invalid cast errors

>type driven development
>Not Test Driven Development

It's a really good video. You can stop around the 30 minute mark, where he goes into Idris' algebraic effect library and it's not really focused on dependent types any more.

>meme driven development
>Not Meme Driven Development

Sorry if you don't have a job don't reply to me

>muh memes

Want is the hardest, most complex programming language to learn? Besides assembly.

What buzzwords do I need to know?

inline Malboge

Malbolge

He actually explains that "type driven development" is pretty similar to test driven development. It makes sense, since dependent types (i.e. proving theorems about your program) do essentially replace unit tests.

fun : Bool -> Type
fun True = Int
fun False = String

fun2 : (b : Bool) -> Int -> fun b
fun2 True = id
fun2 False = show

>muh type feeree
i just came all over my haskel code

Int -> fun b

Will it ever work? fun takes Bools.

b is a Bool.

fun is a function from a bool to a type

(b : Bool) -> Int -> fun b
indicates that the result type is
Int -> fun b
that b is the bool that was passed in, it DEPENDS on that value

it's better than Java/C# style OOP at the very least. Crystal and Ruby are also pretty good implementations of OOP

should i cast here?
struct xxx {
struct xxx *n1;
struct xxx *next;
};

struct xxx *node_create()
{
// cast or not??
struct xxx *temp = malloc(sizeof(struct xxx));
temp->n1 = NULL;
temp->next = NULL;
return temp;
}

In C, no. In C++, yes but you're doing it wrong.

>Programming assignment that I need a B or higher on due in 2 hours
>Haven't done much work and barely know what's going on
>Probably going to fail this and then get kicked out of college
Quick suicide methods?

no, casting malloc is dumb

no
also no parens for sizeof

ODing on heroin is probably the most fun but it'll take a while to die

whats the assignment?

hmmm
xxx.c:18:44: error: expected parentheses around type name in sizeof expression
struct xxx *temp = malloc(sizeof struct xxx);
^
( )
1 error generated.

So, if I pass b = True, I get the id function as a result which is Int -> Int or if I pass b = False, I get the show function which is Int -> String?

You need parentheses if doing

sizeof(struct xxx)

but not,

sizeof *temp

which is arguably better design.

In C pointers are implicitly casted from void* to other types, so no, you don't.

Yes.

Yes, exactly.
And it's type safe, and can be checked at compile time.

It's nothing new, you can do all of this in CL

tanks

run your compiler with all warnings enabled (-Wall for gcc and clang).
If there's no warning, your code is fine.

new @ python 2.7 & bad

I want to take a list as an argument. The list is normally 3 items long, but is sometimes 4 items long.

I want to do something with this 4th item if it exists for the list. In order to do that, I need to check if it exists.

However, I can't do

if mylist[3]:


as a list index doesn't have boolean nature I think, I just get an index out of range error when I try the check.

How can I check it?

>checked at compile time

Except for, you know, the dependent types.
You know, the thing you asked about?

It's not just a macro

Just do,

if len(myList) < 4:
do_something(myList)
else:
do_something_else(myList)

you can retrieve the length of the list with
len(mylist)

and check if it's greater than 3

Yes it is. Anything you can do in a compiler, you can also do in a macro.

Begginer to C
What went wrong?
#include
#define M_PI acos(-1.0)
/* Program that generates a table of an circle radius,area and perimeter. */
main() {
float radius, perimeter, area;
int low, high, step;
low = 0;
high = 20;
step = 1;
radius = low;
printf("Radius\tPerimeter\tArea\n");
while (radius

IT Manager here.

I'm neither one way or the other about your 1-5 steps, because the real question is - well, what do you want to be doing?

If I get slapped by my C-Suite one day and they say, "You've got a db project for our client, we've budgeted for a new junior, don't fuck this up..." then I'm going to look for a junior who's got as much db experience or db projects as I can find. Same if it was a sysadmin/MSP shop and the senior left. Same if it was a webdev/Node.js shop and I'm just building it up.

Of course we give a shit about what languages you know. Multiple languages means multiple angles to attack a problem and pad our bottom line on time (I would pay you in blowjobs if I could depend on you to finish on time). But really, am I going to hire the guy who merely "learned" something off Code Academy, or someone whose done projects in the things we do?

What do you want to do, user?

>main()
Should at the very least be void main()

>acos
You haven't included the appropriate header file