Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Hi P

Low level programming languages

Recommended Posts

3 hours ago, wasab said:

And no java has no goto. For loop isn't goto because control follow are handle by curly brackets and for is a keyword, not a label. Variables lifetime are scope between curly brackets as well. You don't need jump to handle such messes.  

You seem to always purposefully misread arguments. The focus of my example was the "LABEL: break LABEL" construct, which acts as a goto inside a for loop that jumps to a label...

 

Oh, and yes, a for loop is either a LOOP, GOTO, or JUMP construct. So is a while loop, and a foreach loop.


Teacher: Does anyone have a thin ruler?

Students: No.

Teacher: Ok. Does anyone have a nail file.

Students: Why do you need a nail file?
Teacher: I have a staple I need to remove.

Student: Oh. I have a staple remover...

 

People don't want power drills, they want holes.

Link to post
Share on other sites
20 minutes ago, Unimportant said:

No matter how en when the function is exited, the memory will always be cleaned up.

with the smart pointers in your example yes, because as that function goes out of scope the std::unique_ptr destructor will do that for you. That wouldn't work if you just used raw pointers. (this is also why you should use always use smart pointers in modern C++ unless you have to interface with a low level API that forces raw pointers)


Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to post
Share on other sites
4 minutes ago, reniat said:

(this is also why you should use always use smart pointers in modern C++ unless you have to interface with a low level API that forces raw pointers)

Even then, you can always `get()` the raw pointer to pass on, but there's only one owner, the unique_ptr.

 

Although I admit I'm somewhat bothered by Qt's insistence of taking ownership of pointers and deleting them in due time, trying to act as a garbage collector, which conflicts with RAII.

Link to post
Share on other sites
2 minutes ago, Unimportant said:

Even then, you can always `get()` the raw pointer to pass on, but there's only one owner, the unique_ptr.

just be SUPER careful with this. If you expose the raw pointer from your smart pointer, it CAN get deleted and then you can get undefined behavior. For example, even if nothing else is needed from your pointer after that point, you would still get double deletion and undefined behavior when the unique_ptr goes out of scope.


Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to post
Share on other sites
On 3/14/2019 at 6:30 PM, wasab said:

There is a programming paradigm call spaghetti code which is characterized by an immoderate and glorified misuse and abuse of goto statements+labels. Know what languages use spaghetti code paradigms? They are assembly languages. There is no concepts of functions and loops so everything is labels and gotos. 

 

Avoid avoid avoid. I can't say this enough. Avoid assembly. 

The paradigm you speak of is imperative. Spaghetti code is a synonym for messy code, in those languages. Of course, spaghetti code can exist in languages that don't even contain `goto`... consider Java, with it's `try/catch` and `throw`... at least `goto` doesn't let you jump outside of a function unpredictably, right? Indeed, we can write rubbish in any language we like. Perhaps we should just stop speaking, reading, writing and listening, and snort HEAPS of cocaine. I think that could work.

I've played with some nice assembly languages. It's not really my style; I prefer the more expressive languages, but meh.

Link to post
Share on other sites
  • How do you declare a higher-order function in assembly? Take `qsort` and `bsearch` for example, here are their prototypes:
void *bsearch(const void *key, const void *base, size_t nel,
       size_t width, int (*compar)(const void *, const void *));

void qsort(void *base, size_t nel, size_t width,
       int (*compar)(const void *, const void *));
  • ... and `puts((splice_queue[splice_queue_size_hi] & 1 << lo) ? "\?\?/" : "\\");`... How is that written in assembly? Is that all going to be one expression? Because it seems this expression is too complex to be considered low-level in any capacity...
  • How do you write compound literals and designated initialisers in x86 assembly?
  • What is the nearest analogy for the `sizeof` operator in assembly?
  • Do you still think C is low-level? How do you switch from real mode to protected mode, in C?


I think the problem here is we are talking with a narcissist who likes to think he knows C, he might even have a professor who likes to make him think he knows C... maybe... I wouldn't believe everything he says, though, as he doesn't seem to know what we're talking about. Stewie isn't who I'm talking about, but the ignorant rubbish might be rubbing off on him a bit...

 

On 3/15/2019 at 3:15 AM, straight_stewie said:

Just wait until you study formal languages. Then you'll realize that they are all the same, just with different words.


I assume one who would read a book on applied linguistics would also read C11/5.1.2.3p1... and p4... Can show me an example of agglutination in assembly? The preprocessor makes it pretty simple in C... check this working example out:

#define expr_as_str(expr) #expr
#define join(x,y) x##y

#include <stdio.h>
int main(void) {
    join(pu,ts)(expr_as_str(You might think this is complete rubbish but it works));
}

Do you know of any way to do anything like this in x86 assembly? ... I am also looking at you wasab, as you said, the onus is on the person who makes the claim... what is the assembly language idiom for this?

Note that you appear to be using turing completion as an argument. I'm not saying these languages aren't turing complete... it's just, you know, x86 assembly doesn't have some features that C does have... and those features make C high-level. You're welcome to try to translate `join(pu,ts)(...)` if you like... it should be pretty straight-forward, but you also won't be able to use those features at all in assembly... right?
 

On 3/15/2019 at 4:37 AM, wasab said:

I seriously don't know why you guys like to go against common wisdom and advocate gotos and labels can be a good programming styles....

 

I talk in absolutes because if something is bad  idea, then just don't do it, regardless if outcome is good or not. You can be completely fine if you rush red lights but I would talk in absolute term you shouldnt. Same goes for goto.

But whatever. I guess you just need to be open and accommodating. 


Allow me to be absolute with you... where is your book? That's the only reason I come here now, after all...

`goto` as it stood in 1968 (which was a long time ago) was a very different beast to what it is today. Actually, Djikstra wrote it as `GOTO`, if I recall correctly, so... that was about BASIC, not even C! The behaviour was very different back then, too... much more like JUMP in assembly, you know? `20 GOTO 10` and so forth... Able to transfer control outside of the function is not good; keeping control in the function is not so bad. C came around long after Djikstra retracted these claims that seem to curse us constantly now... heck, C came about after "Goto considered harmful" considered harmful was published (1978)... thus this belief that "goto is evil" has been defunct for a long time now.

In short, your concerns appear to be antiquated and sheepish... but then again, you can expect that from someone who appears to have narcissistic personality disorder... does it hurt too much when you're wrong? Awww, tiddles! I wonder how the rest of us cope... I don't get along well with people that have cluster B personality disorders... you want all the attention in the world to the point where you'll change the goalposts and manipulate to no end to get it, even when it makes you look like thatGood for you!
 

On 3/15/2019 at 5:10 AM, Mira Yurizaki said:

You're describing the behavior of literally any source code with control flow statements in it. Besides that, how is this:

def fubar(a, b):
    return a + b;
print fubar('hello', 'world');
print fubar(42, 1);

Sorry, I couldn't help it... they're not going to be able to translate THAT into assembly easily, right? C kind of has this, too, in the form of sockets and pipes treated the same as files, and `bsearch` and `qsort`, of course... assembly doesn't natively have this concept, as far as I can see.
 

On 3/15/2019 at 5:10 AM, Mira Yurizaki said:

Also am waiting for your comment about Torvald's use of gotos in C code.


Actually, I wouldn't consider Linus Torvalds uses of `goto` to be particularly clean, at least not the first few. Maybe you intentionally chose some poor examples to try to make him look foolish, if so that seems to have worked pretty well. You've given some much better examples below that, though you've also had me warned for telling people like yourself when you need to read more and guess less. You're not drivelling all of the sudden. It's good to see eyes open... I wonder what changed... was it my ways?

Cascading error handlers are good, as is jumping out of multiple loops without an intermediate variable or jumping into another switch label to avoid duplicate code... that kind of thing. In PMs I provided some more in the form of my solution to exercise 1-23 (from K&R2E, you know?)... I'll be most interested in seeing how they manage lines 167 and 176... it's a shame we all can't just read the books and do the exercises. I guess we don't all need to, since some of us can just drink beer and vomit instead.

 

Link to post
Share on other sites

Regular expressions... if assembly is considered as expressive as any other language, then it must have regular expressions for matching against strings. Haskell has pattern matching on other types, too. There's a lot of ignorance going on here, I feel like we all just need to open our freaking eyes a bit more... and not swallow the crap other potentially ignorant people feed us without question... you know, cross-reference our resources... like we should in university.

Link to post
Share on other sites
7 hours ago, Sebivor said:

if assembly is considered as expressive, then it must have regular expressions for matching against strings.

Well, there's your mistake in your logic: "expressiveness" is open to interpretation. Does it mean:

  • Says the most with the least.
  • Makes it explicit what's happening.

The two are quite different statements, and "expressiveness" is open to interpretation. In the first definition, a language like python is highly expressive, and by your logic highly preferred. In the other mode of thinking, assembly is more expressive, because it hides (if we ignore that the physical processor is different than the programmers model) no details about what's going on. RegEx is probably the most expressive thing ever in the first statement, and the least expressive thing ever in the second.

 

And, as for your example about using the preprocessor in C, that is not a language feature, that is a toolchain feature. And yes, any good assembler also has a macro language. Just because it uses a different syntax doesn't mean it isn't as powerful. Some assemblers (notably MPASM for PIC) even have builtin macros for managing arrays, both constant and not. That's a feature that C can't even dream of, so let's not get into a pissing contest about who's favorite language has a better toolchain...


Teacher: Does anyone have a thin ruler?

Students: No.

Teacher: Ok. Does anyone have a nail file.

Students: Why do you need a nail file?
Teacher: I have a staple I need to remove.

Student: Oh. I have a staple remover...

 

People don't want power drills, they want holes.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×