flat assembler
Message board for the users of flat assembler.

Index > Heap > sleepsleep's vitally important things

Goto page Previous  1, 2, 3 ... 196, 197, 198 ... 251, 252, 253  Next
Author
Thread Post new topic Reply to topic
guignol



Joined: 06 Dec 2008
Posts: 725
guignol
Haven't you heard that philosophy is dead
Post 23 Apr 2019, 10:11
View user's profile Send private message Reply with quote
guignol



Joined: 06 Dec 2008
Posts: 725
guignol
and revolution as always tries puns on blondes
Post 23 Apr 2019, 10:13
View user's profile Send private message Reply with quote
guignol



Joined: 06 Dec 2008
Posts: 725
guignol
sleepsleep wrote:
Quote:
COLOMBO, Sri Lanka (AP) — More than 200 people were killed and hundreds more wounded in eight bomb blasts that rocked churches and luxury hotels in Sri Lanka on Easter Sunday — the deadliest violence the South Asian island country has seen since a bloody civil war ended a decade ago.
Riding on atoms and doing all kinds of destructions.
look, ss, all blasting/gunfire attacks on public_civic places are maintained by moscow
Post 23 Apr 2019, 10:20
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 558
Location: Russian Federation, Sochi
ProMiNick
Thou`re right as regular weapon producer & trader country moscow maintained part of such uncivil actions (especialy in role of producer of best weapon in a world with price-quality ratio). But It(moscow) not holds all weapon market, and similar things are made by other weapon market participants.
Post 23 Apr 2019, 11:31
View user's profile Send private message Send e-mail Reply with quote
fpissarra



Joined: 10 Apr 2019
Posts: 64
fpissarra
guignol wrote:
Haven't you heard that philosophy is dead

Shocked When this happened? There is no more logic?


Last edited by fpissarra on 23 Apr 2019, 13:09; edited 1 time in total
Post 23 Apr 2019, 12:26
View user's profile Send private message Reply with quote
fpissarra



Joined: 10 Apr 2019
Posts: 64
fpissarra
guignol wrote:
look, ss, all blasting/gunfire attacks on public_civic places are maintained by moscow

And China... don't forget China! Razz
Post 23 Apr 2019, 12:28
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9002
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
Post 23 Apr 2019, 15:43
View user's profile Send private message Reply with quote
guignol



Joined: 06 Dec 2008
Posts: 725
guignol
logic is there as well as logos
Post 23 Apr 2019, 16:29
View user's profile Send private message Reply with quote
fpissarra



Joined: 10 Apr 2019
Posts: 64
fpissarra
guignol wrote:
logic is there as well as logos

Both philosophical concepts...
Post 23 Apr 2019, 16:52
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1494
Furs
fpissarra wrote:
Yep, nothing wrong with '=' as assignment operator if there is a different style for equality. But use ":=" as assignment and "=" for equality is valid as well (as in Pascal). It is preference.

Your example explores a (designed) side effect of C language expressions and the evaluation of boolean values. "Sometimes" that kind of expression is useful, most of the times, not, for example:
Code:
if ( socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ) ) ...    

Here socket() returns -1 in case of error or a value greater then 2 in case of success (stdin, stdout and stderr uses 0, 1 and 2), all possible return values are evaluated as "true".

In your example it is a happy (designed) thing NULL is defined as 0 (ok, ok... (void *)0 ) and malloc() returns NULL in case of error...

Furs wrote:
This is more evident when you have a chain of logical ORs since you'll have to assign it at some point but want the same block to execute.

Are you talking about "short circuits"? They aren't exclusive to C/C++.
I mean the combination of that and assignment within the condition, e.g.:

Code:
c = abc;
if(a || b || (c = blah()) != d || e || f)
{
  ...
  if (c) { ... }
  ...
}    
As you can see assignment and even (in)equality check can be useful in the same conditional. To share the code otherwise you'd have to either use goto, or a helper function, both of which are sometimes undesirable (and some special people have an allergy to goto).
Post 23 Apr 2019, 17:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
Why not just this?
Code:
c = blah();
if(a || b || c != d || e || f)
{
  ...
  if (c) { ... }
  ...
}    
Post 23 Apr 2019, 17:22
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1494
Furs
Because it's not the same thing. Note the c = abc case for when a || b happens.

Also note that blah() may depend on a or b (I didn't use parameters because I tried to keep it simple, or maybe they are class members). Or maybe it's really expensive to call blah() and a || b is very common so... really doesn't matter, it's just an example.
Post 23 Apr 2019, 17:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
How would it be done in a language without assignment in conditionals?
Post 23 Apr 2019, 17:47
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1494
Furs
I guess you could try with a goto:
Code:
c = abc;
if(a || b) goto stuff;
c = blah();
if(c != d || e || f)
{
 stuff:
  ...
}    
Or a helper function:
Code:
c = abc;
if(a || b) do_stuff(...);
else
{
  c = blah();
  if(c != d || e || f) do_stuff(...);
}    
Or some boolean variable:
Code:
var = false;
c = abc;
if(a || b) var = true;
else
{
  c = blah();
  if(c != d || e || f) var = true;
}
if(var)
{
  ...
}    
All of them are uglier to me, though.
Post 23 Apr 2019, 18:42
View user's profile Send private message Reply with quote
guignol



Joined: 06 Dec 2008
Posts: 725
guignol
Will it be safe if something the size of a soccer field will fall, for the planet that is?
Post 23 Apr 2019, 21:18
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 774
Location: Belarus
DimonSoft
Furs wrote:
But there's nothing wrong with a plain = for assignment. The issue was in the equality comparison (i.e. ==) but that is solved today easily by compilers.

Note that sometimes it's useful to assign and check for NULL like:
Code:
if((p = malloc(blah)))    
(parentheses to avoid warning)

Good to know there’s a notation that requires additional parentheses to suppress the warning that prevents introducing bugs caused by that same notation. Looking forward to when newbies start writing double parentheses just to “avoid warnings for sure”. This stuff definitely shows the best parts of the “logically ideal” and “well-designed” notation.

Furs wrote:
This is more evident when you have a chain of logical ORs since you'll have to assign it at some point but want the same block to execute.

Another “good” part of C. Something like 17 (sometimes arbitrarily ordered) levels of operator priority (with logical and bitwise and/or separated just because those guys were lazy to define a stricter type system) instead of only 4 well-defined levels in some other language.

Furs wrote:
DimonSoft wrote:
The same happened with anyone who started diving deeper into C++ far before elements of functional programming got borrowed. Sure, adding something new to a language that is a mess in the first place cannot improve its consistency.
Can't agree. Template metaprogramming (which is functional at its core) is notorious for being "hard to understand", it's a known meme at this point. It even has a section in wikipedia mentioning this.

So, you’re judging functional programming by looking at the completely unrelated set of features which just happened to share some basic ideas with FP. That explains a lot.

Furs wrote:
When it comes down to semantic differences, people tend to pick what's easier (since they're lazy in general) or to avoid what's unnecessarily convoluted.

I know a good example. Esperanto. Language that is made with simplicity and logical consistency in mind. While having a lot of speakers it never made it to become a native language for everyday use for any significantly large group of people.

I know another one. Pascal. Language that is created to be easy to teach and designed so that with proper background you can write a compiler for it in a few hours or so even without any parser generators, by hand. Having more powerful set of HLL features than C, preventing a programmer from making stupid mistakes (unlike C that tends to help in making mistakes). Can’t say many people picked it.

And it is quite easy to explain. Majority can never be sufficiently educated to make good decisions. Only minority really understands all the mechanics that let one make the right choice. No matter what kind of choice: electing a president, choosing a toothbrush or gathering their personal toolset.

Furs wrote:
I agree about good/bad, but the point was that in semantics or syntax, there's no other difference (literally) than how easy it is to understand or read. It won't change the output, useability, factor-ability, or whatever.

It influences the reliability of software: syntax and semantics of a good language tend to help a programmer to avoid many common stupid mistakes that occur due to being tired, inattentive, etc. Reliability and maintainability are dependent on that.

fpissarra wrote:
I can't agree with the notion of "mature notation" of other programming languages, specially if they are newer than C. But, maybe you are talking abour mathematical symbology, which will turn the coding pratice hell (try to imagine coding a complex piece of software entirely in LaTeX AMS package style, for example).

I was talking about mathematical notation in that particular place. I can’t see how LaTeX syntax (mostly related to text representation) can be used as an example of mathematical notation (used to represent relationships between different concepts from numbers to functions, matrices, etc.). Those are two completely different sets of tools. The ability of LaTeX to represent formulae doesn’t make it a superset or an equivalent of mathematical notation.

fpissarra wrote:
In your example it is a happy (designed) thing NULL is defined as 0 (ok, ok... (void *)0 ) and malloc() returns NULL in case of error...

Thanks for mentioning this another amazing example of semantics consistency of C Smile NULL == (void *)0 but generally NULL != (void *)x with x = 0.

Furs wrote:
I mean the combination of that and assignment within the condition, e.g.:

Code:
c = abc;
if(a || b || (c = blah()) != d || e || f)
{
  ...
  if (c) { ... }
  ...
}    
As you can see assignment and even (in)equality check can be useful in the same conditional. To share the code otherwise you'd have to either use goto, or a helper function, both of which are sometimes undesirable (and some special people have an allergy to goto).

In our company we tend to fire people who start writing such code ASAP. Leads to “amazing” readability. Makes it an exciting experience to use step-by-step debugging for the program. Hides the complexity of the code behind the condition.

Note that e and f in this example were pre-calculated even though they’re never used. blah() would have at least a few parameters in a real-world project.

With a function with at least 5 sequentially dependent steps you have more serious problems than expressing the logic in as few characters as possible. In fact, you’d better write it down as explicitly as possible. The first thing to check is whether you’re doing a good job separating your levels of abstraction (why do you have most variables pre-calculated while mixing them (passive data) with a function call that has completely different semantics (code execution)). The second thing to worry about is whether your function still implements the SRP. The third thing is about the cyclomatic complexity and test coverage.

A language making difficult things look easy is a language making dangerous things look safe.

Of course, we’ll need to see a more specific example for further discussion. A made-up example of smelly code is not an excuse for advertising the notation that makes such code look right.
Post 23 Apr 2019, 21:28
View user's profile Send private message Visit poster's website Reply with quote
fpissarra



Joined: 10 Apr 2019
Posts: 64
fpissarra
Furs wrote:
...some special people have an allergy to goto

I am not one of them! Smile
Post 23 Apr 2019, 22:37
View user's profile Send private message Reply with quote
fpissarra



Joined: 10 Apr 2019
Posts: 64
fpissarra
DimonSoft wrote:
Good to know there’s a notation that requires additional parentheses to suppress the warning that prevents introducing bugs caused by that same notation.

Actually, Furs is mistaken. Adding parentesis will not prevent warnings...

DimonSoft wrote:
Another “good” part of C. Something like 17 (sometimes arbitrarily ordered) levels of operator priority (with logical and bitwise and/or separated just because those guys were lazy to define a stricter type system) instead of only 4 well-defined levels in some other language.

I think you are confused. Pratically ALL languages have multiple levels of operators precedence and lateral associativity. Aren't you complaining about type promotions?

DimonSoft wrote:
I know another one. Pascal. Language that is created to be easy to teach and designed so that with proper background you can write a compiler for it in a few hours or so even without any parser generators, by hand. Having more powerful set of HLL features than C, preventing a programmer from making stupid mistakes (unlike C that tends to help in making mistakes). Can’t say many people picked it.

Another mistake. Pascal became popular in the 80's and 90's because of Borland extensions to it. Standarized Pascal is almost impossible to deal with. Before Pascal, in universities, FORTRAN was the programming language of choice.

DimonSoft wrote:
Thanks for mentioning this another amazing example of semantics consistency of C Smile NULL == (void *)0 but generally NULL != (void *)x with x = 0

Who told you a type casting, promoting a value or identifier to higher precision, changes the value? if 'x' is 0 then NULL == (void *)x... For pratical reasons NULL == 0.

DimonSoft wrote:
Furs wrote:
I mean the combination of that and assignment within the condition, e.g.:

Code:
c = abc;
if(a || b || (c = blah()) != d || e || f)
{
  ...
  if (c) { ... }
  ...
}    
As you can see assignment and even (in)equality check can be useful in the same conditional. To share the code otherwise you'd have to either use goto, or a helper function, both of which are sometimes undesirable (and some special people have an allergy to goto).

In our company we tend to fire people who start writing such code ASAP. Leads to “amazing” readability.

I think If someone in your company cannot understand this simple if statement, deverve to be fired.
Post 23 Apr 2019, 22:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
I would be most in favour of this one from your options.
Furs wrote:
I guess you could try with a goto:
Code:
c = abc;
if(a || b) goto stuff;
c = blah();
if(c != d || e || f)
{
 stuff:
  ...
}    
But I think this might be better:
Code:
c = abc;
if (a) goto stuff;
if (b) goto stuff;
c = blah();
if (c != d) goto stuff;
if (e) goto stuff;
if (f) goto stuff;
goto done_stuff;
stuff:
  ...
done_stuff:    
To me that is very clear. No need for double brackets and other non-intuitive things to satisfy the compiler's quirks. The assignments to c are clearly shown. The program flow is obvious. And I have absolutely no problem with using goto.

I guess many hardcore C programmers will hate me for that. Well too bad. They can do it their way and I will do it my way. Razz
Post 24 Apr 2019, 01:14
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 774
Location: Belarus
DimonSoft
fpissarra wrote:
DimonSoft wrote:
Another “good” part of C. Something like 17 (sometimes arbitrarily ordered) levels of operator priority (with logical and bitwise and/or separated just because those guys were lazy to define a stricter type system) instead of only 4 well-defined levels in some other language.

I think you are confused. Pratically ALL languages have multiple levels of operators precedence and lateral associativity. Aren't you complaining about type promotions?

No, I’m complaining about enormous number of operator priority levels in C. See section 6.5 Expressions in ISO 9899. Even if you don’t count primary expressions, there’re still 16 levels. Including stuff that is mostly unknown to people who think they know C, like > and < having higher priority than ==. Pascal has around 4 levels that are easy to remember: unary, multiplicative, additive and comparison operators. And that just works. And avoids any confusion. Just a result of having the type system and language in general well-designed.

fpissarra wrote:
DimonSoft wrote:
I know another one. Pascal. Language that is created to be easy to teach and designed so that with proper background you can write a compiler for it in a few hours or so even without any parser generators, by hand. Having more powerful set of HLL features than C, preventing a programmer from making stupid mistakes (unlike C that tends to help in making mistakes). Can’t say many people picked it.

Another mistake. Pascal became popular in the 80's and 90's because of Borland extensions to it. Standarized Pascal is almost impossible to deal with. Before Pascal, in universities, FORTRAN was the programming language of choice.

I’m well aware of Borland/Turbo Pascal and Delphi as those have been tools of choice for ages. Pascal tends to lose its role in universities and gets replaced by C and/or Python, at least in our country. AFAIK, in Western universities it was earlier replaced by Java which shares a lot of inconsistencies of C.

Anyway, from what I know and can see, Pascal (in any of its forms) has never been considered as the language of choice of the majority of people (although a lot of excellent software is actually written in it and its dialects/descendants), and C has always tended to be more popular in spite of its terrible design.

fpissarra wrote:
DimonSoft wrote:
Thanks for mentioning this another amazing example of semantics consistency of C Smile NULL == (void *)0 but generally NULL != (void *)x with x = 0

Who told you a type casting, promoting a value or identifier to higher precision, changes the value? if 'x' is 0 then NULL == (void *)x... For pratical reasons NULL == 0.

Who told you a null pointer is zero? Plenty of platforms (have) use(d) non-zero representation for null pointer.
ISO 9899, section 6.3.2.3 Pointers wrote:
3 An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.
<…>
5 An integer may be converted to any pointer type. Except as previously specified, the result is implementation-defined, might not be correctly aligned, might not point to an entity of the referenced type, and might be a trap representation.

Note that only constant expression is specified to produce a null pointer value. Any kind of non-constant expression (say x variable of integer type) produces an implementation-defined value. Are you relying on implementation-specific and platform-specific behavior in your programs?

DimonSoft wrote:
I think If someone in your company cannot understand this simple if statement, deverve to be fired.

You’re judging based on a synthetic example. Replace the names with good identifiers, replace the function call with some real function with parameters and it will not be as good and/or immediately obvious. Add the fact that parameter passing is not sequenced in a particular way, that any variable, a, b, e and f would in fact be subexpressions (say, comparisons).

In C to check the condition while reading the code one needs to remember the operator precedence rules, sequencing rules, the side effects that particular function call might have, etc. Even in languages with much simpler semantics (Furs states semantics simplicity is important in a language) such code is treated as smelly and asking for a rewrite. Besides, these rules are different for different programming languages, so any programmer who is any better than a first-year student might easily get confused.

If someone in a company relies on someone else being able and willing to read and recheck unnecessarily complex write-only pieces of code (written so just to be cool or to have short code), such a person is dangerous for the company as it would lead to serious bugs in software and, consequently, serious financial and reputational loss.

If you’re OK to have a time bomb in your team or to hire those who know just a single programming language with narrow outlook, you’re free to keep such people. Just do not advertise your way as something good.
Post 24 Apr 2019, 08:14
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3 ... 196, 197, 198 ... 251, 252, 253  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.