Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prague/ Q&A

Name: Anonymous 2013-11-19 12:18

Ask /prog/ anything.

Although don't expect an answer or even a good one.

Also, keep it /prog/ related.

Name: >>31 2013-11-23 19:58

>>30
Now that I explained GC-time list compaction, how do you feel about it?

This has the potential to turn into a debate on whether handles are a good idea.

Name: Anonymous 2013-11-24 1:05

I'm familiar with object-oriented programming, but what is functional programming? Are they compatible? Are they reconcilable? Do individual programmers generally favor one over the other, or do they utilise each when appropriate? Are the any other styles or philosophies of note or of relevance?

Sorry if those are silly questions, I'm a mere hobbyist who will never even hope to one day achieve Satori.

Name: Anonymous 2013-11-24 1:21

>>42
I'm familiar with object-oriented programming, but what is functional programming?
Object-oriented programming is when things are centered around objects and their composition (inheritance, for example), and functions/procedures/methods are defined in terms of/around objects. Functional programming is when emphasis is put on functions instead and their composition, and objects/structures are just things that functions operate on. Purely functional programming is the extremest form of this, where all code is part of functions (in the mathematical sense) and so there is no mutation ("assignment"). Turns out that all of the above are equal in computational power (i.e. there are no computations that one of them can do but the other ones can't), so this is really just about clarity and efficiency and all those other things.

Are they compatible? Are they reconcilable?
Yes; an excellent example is Common Lisp and the CLOS.

Do individual programmers generally favor one over the other, or do they utilise each when appropriate?
The average programmer has the IQ of a highly-trained rhesus monkey. That being said, a Haskell programmer will almost always use functional programming (even when clarity/performance are hurt) while a Java programmer will almost use object-oriented programming (because they don't know any better).

Are the any other styles or philosophies of note or of relevance?
Read up about defmacro. Also read SICP (or if you find it too hard, something like Land of Lisp).

Name: Anonymous 2013-11-24 3:03

>>43
Thank you for the fantastic response. The defmacro functional programming article really helped shed a bit more light on the topic for me. (Un)fortunately I am as Java-ignorant as anyone can be so any nuance or implication of the given examples went over my head. I feel like I'm right on the brink of getting it, but that last puzzle piece of understanding still looks like a corner when I've already completed in the border.

even when clarity/performance are hurt
Is this due to the flexibility and ease of debugging that was mentioned in the article, or am I missing something?

Name: Anonymous 2013-11-24 3:16

>>44
What article are you referring to?

Name: Anonymous 2013-11-24 3:19

>>22
Doushiou. I always lose the address of the malloc'd object somewhere in the program..
Fonbuk.c

#include <stdio.h>
#include <string.h>

typedef struct _record {
char *firstname;
char *lastname;
char *mobilenum;
struct _record *Next;
} Record;

void newentry(Record *Rec);
int insert(Record *Rec, char * lname, char * fname, char * mobile);
void viewall(Record *Rec);

int main()
{
char c;
Record *Phonebook = NULL;

while(1) {
printf("%s\n", "Phonebook: ");
printf("%s\n", "\t[1] Insert");
printf("%s\n", "\t[2] Display");
printf("%s\n", "\t[3] Exit");

do {
scanf("%c", &c);
} while (!((c == '1') || (c == '2') || (c == '3')));

switch (c) {
case '1':
newentry(Phonebook);
break;
case '2':
viewall(Phonebook);
break;
case '3':
return 0;
}
}
}

void newentry(Record *Rec)
{
char lname[30], fname[30], mobile[15];
int error;

clrscr();
printf("%s", "Last Name: ");
scanf("%s", &lname);
printf("%s", "First Name: ");
scanf("%s", &fname);
printf("%s", "Mobile No.: ");
scanf("%s", &mobile);
error = insert(Rec, lname, fname, mobile);
if (error > 0) {
printf("%s\n", "Not enough memory.");
getch();
}
}

int insert(Record *Rec, char * lname, char * fname, char * mobile)
{
/*
RETURN 0 IF SUCCESSFUL.
*/
Record *New, *Temp;
int i;

New = (Record *) malloc(sizeof (Record));

/* If malloc returns an invalid pointer */
if (!New) {
return 1;
}

/* Allocate memory for strings and
copy the arguments into them.
*/
New->lastname = (char *) malloc(strlen(lname) + 1);
strcpy(New->lastname, lname);
printf("%s", New->lastname);
New->firstname = (char *) malloc(strlen(fname) + 1);
strcpy(New->firstname, fname);
New->mobilenum = (char *) malloc(strlen(mobile) + 1);
strcpy(New->lastname, mobile);
New->Next = NULL;

/* If malloc returns an invalid pointer on the strings.*/
i = !(New->lastname) || !(New->firstname) || !(New->mobilenum);
if (i) {
return 1;
}

if (Rec == NULL) {
Rec = New;
} else {
Temp = Rec;
while (Temp->Next != NULL) {
Temp = Temp->Next;
}
Temp->Next = New;
}

return 0;
}

void viewall(Record *Rec)
{
Record *Temp;

clrscr();
printf("%s\t\t", "Last Name");
printf("%s\t\t", "First Name");
printf("%s\n", "Mobile Number");
Temp = Rec;
while (Temp->Next != NULL) {
printf("%s\t\t", Temp->lastname);
printf("%s\t\t", Temp->firstname);
printf("%s\n", Temp->mobilenum);
Temp = Temp->Next;
}
}

Name: Anonymous 2013-11-24 6:48

Name: Anonymous 2013-11-24 9:06

>>46
Nvm /prog/, I got it working. It took me some time to figure it out while avoiding **-pointers as per >>23's advice but I just gave in.

Anyway, since this is a Q&A, can /prog/ please review my code for shit? How do I improve myself? Am I an annoying fag who should stop posting?
Also, please don't mind for me using a linked list.

Fonbuk.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct _record {
char *firstname;
char *lastname;
char *mobilenum;
struct _record *Next;
} Record;

void newentry(Record **Rec);
int insert(Record **Rec, char * lname, char * fname, char * mobile);
void viewall(Record **Rec);

int main()
{
char c;
Record *Phonebook = NULL;

while(1) {
system("cls");
printf("%s\n", "Phonebook: ");
printf("%s\n", "\t[1] Insert");
printf("%s\n", "\t[2] Display");
printf("%s\n", "\t[3] Exit");

do {
scanf("%c", &c);
} while (!((c == '1') || (c == '2') || (c == '3')));

switch (c) {
char lname[30], fname[30], mobile[15];
int error;
case '1':
newentry(&Phonebook);
break;
case '2':
viewall(&Phonebook);
break;
case '3':
clrscr();
}
if (c == '3')
break;
}

return 0;
}

void newentry(Record **Rec)
{
/* I am now a two-star programmer. (NOT a good thing) */
char lname[30], fname[30], mobile[15];
int error;

clrscr();
printf("%s", "Last Name: ");
scanf("%s", &lname);
printf("%s", "First Name: ");
scanf("%s", &fname);
printf("%s", "Mobile No.: ");
scanf("%s", &mobile);
error = insert(Rec, lname, fname, mobile);
if (error > 0) {
printf("%s\n", "Not enough memory.");
getch();
}
}

int insert(Record **Rec, char * lname, char * fname, char * mobile)
{
/*
RETURN 0 IF SUCCESSFUL.
*/
Record *New, *Temp;
int i;

New = (Record *) malloc(sizeof (Record));

/* If malloc returns an invalid pointer... */
if (!New) {
return 1;
}

/* Allocate memory for strings and
copy the arguments into them.
*/
New->lastname = (char *) malloc(strlen(lname) + 1);
strcpy(New->lastname, lname);
New->firstname = (char *) malloc(strlen(fname) + 1);
strcpy(New->firstname, fname);
New->mobilenum = (char *) malloc(strlen(mobile) + 1);
strcpy(New->mobilenum, mobile);
New->Next = NULL;

/* If malloc returns an invalid pointer on the strings... */
i = !(New->lastname) || !(New->firstname) || !(New->mobilenum);
if (i) {
return 1;
}

if (*Rec == NULL) {
*Rec = New;
} else {
Temp = *Rec;
while (Temp->Next != NULL) {
Temp = Temp->Next;
}
Temp->Next = New;
}

return 0;
}

void viewall(Record **Rec)
{
Record *Temp;

system("cls");
printf("%s\t\t", "Last Name");
printf("%s\t\t", "First Name");
printf("%s\n", "Mobile Number");
Temp = *Rec;
while (Temp != NULL) {
printf("%s\t\t", Temp->lastname);
printf("%s\t\t", Temp->firstname);
printf("%s\n", Temp->mobilenum);
Temp = Temp->Next;
}
}

Name: Anonymous 2013-11-24 9:12

>>47
I was referring to defmacro the macro-creation macro in Common Lisp, not defmacro the website. I don't know how accurate/good that page is because I have too much work to do and too little spare time to read it.

(Un)fortunately I am as Java-ignorant as anyone can be so any nuance or implication of the given examples went over my head. I feel like I'm right on the brink of getting it, but that last puzzle piece of understanding still looks like a corner when I've already completed in the border.
If you are truly new to programming, try reading SICP[1] or, if it's too rough, Land of Lisp[2], like I said before. And, of course, do at least some of the exercises as you go along.

Is this due to the flexibility and ease of debugging that was mentioned in the article, or am I missing something?
Programming is all about tradeoffs. Come to think of it, anything in the world is all about tradeoffs. When you code in C, you are trading off readability, security and terseness for that extra vroom vroom. When you code in Java, you trade off, uh, everything for (the illusion of) portability. When you code in Haskell, you trade off a lot of readability for (type) safety, theoretical purity, and terseness. Overusing functional programming can certainly lead to unreadable and/or unsafe and/or slow code, as would taking any one programming approach to be your hammer and pretending everything else is a nail (or in the case of C++, a thumb).

[1] https://mitpress.mit.edu/sicp/full-text/book/book.html
[2] http://landoflisp.com/

Name: Anonymous 2013-11-24 10:01

>>49
When you code in C
trading off security
And that's why C is the most used language for security programming

Come to think of it, anything in the world is all about tradeoffs
wow so wize

Name: Anonymous 2013-11-24 15:45

How's the board going, /prog/riders? Are you enjoying the total lack of moderation? I completely forgot I was hosting this place for about the past month.

The server space and domain are paid off for forever so don't worry about it ever going down in case I forget this place exists.

Name: Anonymous 2013-11-24 16:24

>>49
Who needs Lisp, when you have Dot fucking NET?


public static D[] map<S,D>(S[] xs, Func<S,D> f) {
D[] ys = new D[xs.Length];
int i = 0;
foreach (var x in xs) ys[i++] = f(x);
return ys;
}

Name: Anonymous 2013-11-24 18:31

>>51
The site attracted a few VIP quality posters, which is definitely an improvement over the old /prog/. Once again, thank you for giving us the chance of starting over by using your site.

There have been some occasional shitposts but other than that it's been cool.

Name: Anonymous 2013-11-24 20:03

>>50
And that's why C is the most used language for security programming
And that conclusively proves that people are retards.

Name: Anonymous 2013-11-24 22:34

Why is dynamic typing bad?

I know it introduces bugs in expressions like actually_a_str += 5 where actually_a_str was expected to be an int.

Other than that, is there anything bad about it?
I know it introduces a lot of bugs in a situation like I just mentioned, but are there any good things to say about it?

I dislike dynamic typing myself purely on the grounds of what I just showed, I just want to broaden my horizons like I did with Haskal

Name: Anonymous 2013-11-24 23:35

I prefer dynamic typing because I can always add type-checking macros or even pass the whole program through a static analyzer.

Name: Anonymous 2013-11-25 0:17

>>51
It's going well. One of the key ingredients for the success of a bbs is for the admin to forget it exists for a while. Thanks again for hosting this. I don't post on dis.4chan.org anymore because it's too difficult to obscure my ip there, so I wouldn't be a part of this community if it wasn't for this site.

>>54
Indeed. To be fair though, the alternatives to C generally come with large libraries that are generally written in something c like and can contain vulnerabilities of their own. So there is some merit to writing a very heavily reviewed code base of c with minimal library dependencies.

>>48
you can remove char lname[30], fname[30], mobile[15]; from main.

Also if (c == '3') break; could be optimized with a goto under case '3': that exits the while loop.

If you modified the Record structure to save a pointer to the last node in the list, you could eliminate the linear search for the end in the insert function. It may be good form to separate the Record constructor from the list insertion procedure, as in the future you may wish to make a Record but not necessarily insert it into a list, but that's not a big deal.

viewall can just take a Record* since it doesn't need to modify the pointer to the list.

but it looks good enough. Oh and at some point you should write procedures for freeing the memory used by your datastructure.

Name: Anonymous 2013-11-25 0:26

>>55
Dynamic typing is bad for the following reasons:

1. Some bugs that could be caught via static typing may not be caught at compilation time, and may turn up at run time. For some applications, failure at run time (that could have been prevented with more analysis) is not an option and this is not acceptable.

2. If the compiler is not able to determine the types of variables, the performance of the program may be degraded relative to how it would be if the compiler was given the set of types each variable could obtain explicitly. For some applications where high performance or minimal resource use is required, this extra overhead that could be prevented is not acceptable.

But if you are writing a quick script and think you a good enough coder to avoid bugs due to 1, and don't care about loss of performance due to 2, then dynamic typing can improve your productivity to an extent because you can just quickly write something up and not bother with type declarations. However, for large projects, type declarations serve as good documentation and type errors at compilation time will actually improve your productivity, as otherwise you'll be debugging type errors caught at runtime.

So in short, dynamic typing is good for shitty and short php scripts that no one cares about, and is bad for everything else.

Name: Anonymous 2013-11-25 0:35

How can UTF8 represent every unicode character if it is only 8 bits?

Name: Anonymous 2013-11-25 0:42

>>58
1. Static analyzer. Put the static analyzer in your makefile to prevent the code from even compiling.
2. By insisting that the code (for a specific program) fully passes static analysis and by 'wiring' the aforementioned static analyzer into the compiler, the compiler should now be able to infer all types in the program.

So in short, dynamic typing is good for shitty and short php scripts that no one cares about, and is bad for everything else.
So in short, static typing is good for shitty and short C programs that no one cares about, and is bad for everything else.

>>59
UTF-8 encodes each of the 1,112,064 code points in the Unicode character set using one to four 8-bit bytes (a group of 8 bits is known as an "octet" in the Unicode Standard). Code points with lower numerical values (i.e. earlier code positions in the Unicode character set, which tend to occur more frequently) are encoded using fewer bytes. The first 128 characters of Unicode, which correspond one-to-one with ASCII, are encoded using a single octet with the same binary value as ASCII, making valid ASCII text valid UTF-8-encoded Unicode as well.

Name: Anonymous 2013-11-25 2:56

>>60
1. Static analyzer as a compilation check works. However, assuming this is working off of type inference, the type error messages may not be all that clear. If the programmer has written out the type signatures eyself, then the analyzer can point out the conflicting points directly. Otherwise, when types are inferred, the analyzer may infer types that weren't intended by the programmer, and when the conflicts are listed, they might not make sense. For it to really work it needs to be interactive. Or the analyzer would need to list all inferred types so the programmer could look through it and find the ones that doesn't match what they thought, and fix the problem there.

2. That's certainly possible but not really achievable using crap like python. It's a large effort and can only really work if the compiler and analyzer are designed to work together from the start. I think the easiest way to get this would be to have the analyzer output the code in a sub language with explicit types, and then feed this into a secondary compiler.

Name: Anonymous 2013-11-25 3:29

>>59
See >>60 , but tl;dr - it's not only 8 bits. Different codepoints may be represented by different numbers of bytes, which is what makes it hard to get the ith character of a UTF-8 string in less than O(n) time.

Name: Anonymous 2013-11-25 3:57

>>61
For it to really work it needs to be interactive. Or the analyzer would need to list all inferred types so the programmer could look through it and find the ones that doesn't match what they thought, and fix the problem there.
This is actually what I was thinking about, thank you for articulating it so nicely. Sometimes this can be difficult, for example if the code is actually part of macroexpanded code, but it should still be feasible. Most of the time the static analyzer will be complaining about the lack of annotations rather than pointing out mismatches.

I think the easiest way to get this would be to have the analyzer output the code in a sub language with explicit types, and then feed this into a secondary compiler.
Or just let the compiler accept type hints (like CLs have been doing since forever) and use them whenever it can.

Name: Anonymous 2013-11-25 4:38

>>63
Yeah, it should be pretty easy. Every time some sort of definition is encountered, the analyzer can make a note of it, infer all types as far as possible, and then create a list of type signatures for all definitions, per file. These files would correspond to the header file in C, and I think ocaml has something similar with .mli. And if I recall correctly ocaml has a compilation option to generate mli files from ocaml source, although I could be wrong here.

Name: Anonymous 2013-11-25 7:04

>>51
The server space and domain are paid off for forever

How does that work? I thought you could only register a domain at a max of 5 years?

Name: Anonymous 2013-11-25 7:44

>>65
In five years we'll all be dead and the internet will be shut down, so it doesn't matter anyway.

Name: Anonymous 2013-11-25 11:47

>>66
The sad thing is that neither of those will happen (well, maybe some of us will die or commit suicide, but not all of us).

Name: Anonymous 2013-11-25 21:57

Name: Anonymous 2013-11-25 22:31

>>68
Does /jp/ know about these videos? I still don't understand then, but I enjoy them thoroughly.

Name: Anonymous 2013-11-25 22:47

Tell me [spoiler]/prog/[/spoiler, should I buy some Bitcoins now?

Name: conway's game of dicks 2013-11-25 23:07

>>70
We don't know what's going to happen in the next few weeks, but if the trend continues, it should stay stable at that absurd price (~$800 as of today) and rise very slowly to $1000 or so. It's not certain if it will crash again, but if it does, it's likely it will fall to a price that will make you say out loud "shit i wish i would have waited a bit more".

You'd have to make a very risky investment if you want to get some profit[1].
_________
[1] Extracts from MY ANUS: Copyright 1985 - 2013.

Name: Anonymous 2013-11-26 12:18

Why are global variables bad? Everyone just keep saying that it is but no one ever tells me why.

Name: Anonymous 2013-11-26 12:27

>>72
I asked that a long time ago and got bombarded with dozens of reasons, many of which were language specific. The one that stuck with me was
The more global variables you have, the more you have to worry about exactly what each function may do in terms of unexpected side effects. If you have no global variables, you can look at just what a function returns and what it calls. If you have many global variables modified in a function, you have to track each one down across every other part of your program to figure out what a function actually does.
So when I avoid global variables, I do so for reasons of clarity.

Name: Anonymous 2013-11-28 12:16

What the fuck is code golfing and why is it the new fad among hackers?

Name: Anonymous 2013-11-28 12:31

>>74
All responders to this post are honorary recipients of the IHBT medal of meritorious service to Prague.

Name: Anonymous 2013-11-28 13:01

>>74
Kolmogorov complexity.

Name: Anonymous 2013-11-28 18:18

>>73

Ever do embedded systems programming on trash boards? you're pretty much forced to use global variables exclusively

Name: Anonymous 2013-11-28 18:30

>>77
Nope. If an environment forces you to write code a certain way, it can't be helped.

Name: (cddr SCHEMA) 2013-11-29 2:58

>>78
That's what ̶µ̶$PHP said.

Name: Anonymous 2013-11-30 8:04

I want to work as a hacker to a company like Kaspersky. I don't care if they don't make FOSS b-but I am in love with the idea of taking files apart and analysing their payload and shit. I only have a very minimal programming experience, though. What path should I take /prog/?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List