Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5097
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Mon Jan 25, 2016 10:40 pm UTC

hotaru wrote:
Xeio wrote:Well, I'm only really annoyed I can't select 4 bytes, convert it to an int, and get a sane number output.

what language are you trying to do it in? you can't just do this?
By hand, I meant, or copy-pasting into a hex-to-decimal converter anyway. <_<

Could probably just find a better binary file viewer that could do that to selected bytes or something.

User avatar
phlip
Restorer of Worlds
Posts: 7554
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Tue Jan 26, 2016 12:28 pm UTC

korona wrote:What is REALLY annoying is crazy bit numbering. In the RFCs describing IP and related protocols bit 0 is the most significant bit. I.e. bit 0 equals 0x8000. Except for 32-bit fields where it is 0x8000'0000. Or 48-bit fields where it is 0x1'0000'0000'0000. Yeah, that totally makes sense.

Wait, really? I don't think I've ever read any spec for anything, ever, that didn't have bit 0 as the LSB.

[edit] Wow, just looked it up. That's just ridiculous. I almost feel I should boycott IP just for how ridiculous that is.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

commodorejohn
Posts: 1108
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Tue Jan 26, 2016 2:27 pm UTC

A variety of '70s and early '80s documentation (manuals for miscellaneous minicomputers, the TMS-9900 manual, etc.) does that. It is rather bizarre, especially since it means that the value of a bit is no longer equal to 2 ^ bit number.
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6238
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Thu Jan 28, 2016 6:00 pm UTC

I counted, 70% of indents in this file have a prime number of spaces. 2, 5, 7, 11, and 19 are all present.
Summum ius, summa iniuria.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Thu Jan 28, 2016 8:41 pm UTC

That's why I configure my editor to have 1 space = 1 tab. Plus there are no more spaces vs tabs debates.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11083
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Thu Jan 28, 2016 8:48 pm UTC

Real programmers use 1 tab = 0 spaces.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Thu Jan 28, 2016 8:50 pm UTC

Tab = backspace or gtfo.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
chridd
Has a vermicelli title
Posts: 824
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: Coding: Fleeting Thoughts

Postby chridd » Thu Jan 28, 2016 9:13 pm UTC

Thesh wrote:I counted, 70% of indents in this file have a prime number of spaces. 2, 5, 7, 11, and 19 are all present.

Code: Select all

class Foo {
  void doSomething() {
   for(int i = 0; i < 10; i++)
     for(int j = 0; j < 10; j++)
       for(int k = 0; k < 10; k++)
           if(i < j && j < k)
             System.out.println(
                 i+","+j+","+k+"\n");
  }
}
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · she(?)(?(?)(?))(?(?(?))(?))(?) · Forum game scores
mittfh wrote:I wish this post was very quotable...
flicky1991 wrote:In both cases the quote is "I'm being quoted too much!"
chridd (on Discord) wrote:
Dummy wrote:Sorry You're Gay Dads
SYG'D

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6238
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Thu Jan 28, 2016 9:24 pm UTC

I don't think there is an indent of 1 space in the code.

What happens here is that some people here love to to align the code on different lines, but after years of modifications and copy-pasting with no one bothering to realign the code, you just end up with nothing being aligned and the number of indents being seemingly random.
Summum ius, summa iniuria.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5097
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Fri Jan 29, 2016 8:05 pm UTC

The person who wrote this code seemingly didn't test it at all.

It's a complicated calculation, but additions instead of multiplication? Not converting X% into 0.0X to actually multiply? Missing variables?

WTF?

I would probably think about passive aggressively asking questions about it at him, but he's not even listed in outlook so I don't think he works for us anymore.

EDIT: OH FOR F-s SAKE! We have utility methods for all of these calculations. I can replace the 30 lines of buggy code with one line.

I JUST SPENT ALL DAY TRYING TO FIX IT FOR NO REASON.

User avatar
Wildcard
Candlestick!
Posts: 253
Joined: Wed Jul 02, 2008 12:42 am UTC
Location: Outside of the box

Re: Coding: Fleeting Thoughts

Postby Wildcard » Sat Jan 30, 2016 4:23 am UTC

korona wrote:What is REALLY annoying is crazy bit numbering. In the RFCs describing IP and related protocols bit 0 is the most significant bit. I.e. bit 0 equals 0x8000. Except for 32-bit fields where it is 0x8000'0000. Or 48-bit fields where it is 0x1'0000'0000'0000. Yeah, that totally makes sense.

I'm trying to see where you get this. Wouldn't it be 0x8000'0000'0000 in a 48-bit field? Am I misreading it somewhere?
There's no such thing as a funny sig.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Sat Jan 30, 2016 12:41 pm UTC

Yes, of course, I made a mistake there.

User avatar
Echo244
Posts: 511
Joined: Wed May 20, 2015 9:49 am UTC
Location: Ping! Ping! Ping! Ping!

Re: Coding: Fleeting Thoughts

Postby Echo244 » Mon Feb 01, 2016 12:50 pm UTC

Xeio wrote:The person who wrote this code seemingly didn't test it at all.

It's a complicated calculation, but additions instead of multiplication? Not converting X% into 0.0X to actually multiply? Missing variables?

WTF?

I would probably think about passive aggressively asking questions about it at him, but he's not even listed in outlook so I don't think he works for us anymore.

EDIT: OH FOR F-s SAKE! We have utility methods for all of these calculations. I can replace the 30 lines of buggy code with one line.

I JUST SPENT ALL DAY TRYING TO FIX IT FOR NO REASON.


I feel your pain. I'm still finding stuff in my projects from a numpty who knew we had utilities for all the calculations, but decided he'd do them all himself, again, in ways that broke, and in places that weren't common and centralised.
Unstoppable force of nature. That means she/her/hers.
Has committed an act of treason.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11083
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Mon Feb 01, 2016 3:18 pm UTC

Is this morally wrong?

http://coliru.stacked-crooked.com/a/d9e7bf282e021036

Code: Select all

    namespace implies_trick {
      struct lhs_t {
        bool v;
        constexpr lhs_t(bool b):v(b) {}
        constexpr explicit operator bool() const { return v; }
      };
      struct implies_t { constexpr implies_t() {} };
      constexpr implies_t implies = {};
      constexpr lhs_t operator->*( bool a, implies_t ) { return {a}; }
      constexpr bool operator*( lhs_t a, bool b ) { return a?b:true; }
    }
    using implies_trick::implies;
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Mon Feb 01, 2016 5:50 pm UTC

I guess not.

I also think that this is morally wrong (taken from the GNU bash source code):

Code: Select all

/* The LC_MESSAGES locale category is the category used by the functions
   gettext() and dgettext().  It is specified in POSIX, but not in ANSI C.
   On systems that don't define it, use an arbitrary value instead.
   On Solaris, <locale.h> defines __LOCALE_H (or _LOCALE_H in Solaris 2.5)
   then includes <libintl.h> (i.e. this file!) and then only defines
   LC_MESSAGES.  To avoid a redefinition warning, don't define LC_MESSAGES
   in this case.  */
#if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun))
# define LC_MESSAGES 1729
#endif

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Tue Feb 02, 2016 3:39 pm UTC

Yakk wrote:Is this morally wrong?

http://coliru.stacked-crooked.com/a/d9e7bf282e021036

Code: Select all

    namespace implies_trick {
      struct lhs_t {
        bool v;
        constexpr lhs_t(bool b):v(b) {}
        constexpr explicit operator bool() const { return v; }
      };
      struct implies_t { constexpr implies_t() {} };
      constexpr implies_t implies = {};
      constexpr lhs_t operator->*( bool a, implies_t ) { return {a}; }
      constexpr bool operator*( lhs_t a, bool b ) { return a?b:true; }
    }
    using implies_trick::implies;


That is truly disgusting. I like it!
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

jareds
Posts: 436
Joined: Wed Jan 03, 2007 3:56 pm UTC

Re: Coding: Fleeting Thoughts

Postby jareds » Wed Feb 03, 2016 1:35 am UTC

Yakk wrote:Is this morally wrong?

C++ already has a non-short-circuiting boolean implication operator: <= . Fair warning: unlike the other boolean operators, it doesn't implicitly convert to bool. :twisted:

User avatar
ucim
Posts: 6480
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Wed Feb 03, 2016 3:23 am UTC

Yakk wrote:Is this morally wrong?
I am not familiar enough with this notation, but this stack-overflow post and the link in your post tells me that this is the standard logical "implies" thing... where -> means "implies" and

a->b means ~a doesn't imply anything about b. i.e. b could be TRUE or FALSE if a is FALSE.

But
the highest rated answer to the post I reference wrote:"if A is true, then B must be true". This implies (pun intended) that if A isn't true, then B can be anything. Thus:

False implies False -> True
False implies True -> True
True implies False -> False
True implies True -> True
...which to me is an abuse of the word "implies". If a implies b, and we let c=~a, we get:
(c implies b) AND (c implies ~b). Using the same abuses, I come up with c implies (b AND ~b).

I conclude that since (b AND ~b) cannot (pun) be, that c must be false, and a must therefore be true.

Since this is independent of what b is, anything that implies anything else must be true!.

I wonder what the implications of that are.

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6238
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Wed Feb 03, 2016 3:42 am UTC

I spent an hour looking for irreducible polynomials in GF(2) in sage expecting them to be significantly more plentiful. It turns out that they are extremely easy to find if your code actually works:

This doesn't work:

Code: Select all

(x^256 + F.fetch_int(randint(0,2**256) | 1)).is_irreducible()


This does:

Code: Select all

(x^256 + F.fetch_int(randint(0,2**256) | 1).polynomial()).is_irreducible()


I'm playing with a one-round, impervious to linear and differential cryptanalysis, cipher design (that is highly susceptible to side channel attacks, likely slow, and might have some simple mathematical attacks) and I need a bunch of high hamming weight moduluses for GF(2^256).
Summum ius, summa iniuria.

User avatar
phlip
Restorer of Worlds
Posts: 7554
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Wed Feb 03, 2016 4:46 am UTC

ucim wrote:...which to me is an abuse of the word "implies".

To be more specific, it's material implication, and your description of what it means (and the truth table) is correct. The motivation makes more sense when you consider "for all" conditions... for instance, a statement of "all A's are B's", or "if anything is an A, then it is a B" can be formalised as "for all x, A(x) -> B(x)". The only thing that can be a counterexample is an x where A(x) is true but B(x) is false, so that's the only case where A(x) -> B(x) is false. All other cases are acceptable.

ucim wrote:If a implies b, and we let c=~a, we get:
(c implies b) AND (c implies ~b).

Neither of those are the case. We can't claim that c -> b because it's possible that c is true and b is false... because our given (ie: a -> b) doesn't rule out the possibility that both a and b are false.
Similarly, our given doesn't rule out that a is false and b is true, so we can't claim that c -> ~b.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Flumble
Yes Man
Posts: 2050
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Wed Feb 03, 2016 6:29 pm UTC

Code: Select all

view-source:http://live.waterbase.nl/waterbase_dbh.cfm?loc=EEFDBVN&page=start.locaties.databeschikbaarheid&taal=nl&loc=&wbwns=5396|Aan+actief+kool+geabsorbeerd+organisch+gebonden+halogeen+in+ug%2Fl+uitgedrukt+in+chloride+%2F+na+filtratie+in+oppervlaktewater&whichform=1

For some reason I think that site could use an update. :roll:

(This is really what the web looked like in 2000, isn't it?)

User avatar
ucim
Posts: 6480
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Wed Feb 03, 2016 6:47 pm UTC

phlip wrote:Neither of those are the case. We can't claim that c -> b because...
Yes, I know. That's why I said " Using the same abuses, I come up with..." :)

My objection is to using (co-opting) the word "implies" when the real meaning to be conveyed is "is consistent with". Yeah, the math/philosophy people did it long ago and it won't change, thus the fleeting thought.

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

KnightExemplar
Posts: 5494
Joined: Sun Dec 26, 2010 1:58 pm UTC

Re: Coding: Fleeting Thoughts

Postby KnightExemplar » Wed Feb 03, 2016 7:04 pm UTC

When I see the word "implies" in logic, I replace it with "Is it true that X implies Y?". It seems to help me.

Mapping English to Logic is just... weird. It blew my mind that the vast majority of Natural Language Processors for example equate the word "BUT" to "Logical AND", for example. So the "implies" thing is par for the course.
First Strike +1/+1 and Indestructible.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11083
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Wed Feb 03, 2016 10:55 pm UTC

phlip wrote:
ucim wrote:If a implies b, and we let c=~a, we get:
(c implies b) AND (c implies ~b).

Neither of those are the case. We can't claim that c -> b because it's possible that c is true and b is false... because our given (ie: a -> b) doesn't rule out the possibility that both a and b are false.
Similarly, our given doesn't rule out that a is false and b is true, so we can't claim that c -> ~b.

But, ~b->c.

(a->b) <-> (~b->~a)
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Jplus
Posts: 1711
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Coding: Fleeting Thoughts

Postby Jplus » Thu Feb 04, 2016 7:59 am UTC

KnightExemplar wrote:Mapping English to Logic is just... weird. It blew my mind that the vast majority of Natural Language Processors for example equate the word "BUT" to "Logical AND", for example. So the "implies" thing is par for the course.

Well, it's true. "But" and "and" both have the meaning of logical AND. The only difference is that "but" expresses some sense of surprise, dissatisfaction, etcetera about both operands being true that "and" doesn't.

Fun fact: ancient Greek didn't distinguish between "and" and "but". It was both "men". I don't know whether that's still the case in modern Greek.

Edit: English also has a word for XOR. Can you identify it?
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Thu Feb 04, 2016 10:22 am UTC

ucim wrote:...which to me is an abuse of the word "implies". If a implies b, and we let c=~a, we get:
(c implies b) AND (c implies ~b).

I cannot follow your reasoning at all here. Why should c imply b or ~b?

Material implication really is what we usually mean when we use "implies" in a (propositional) natural language sentence. It is constructed so that a ∧ (a -> b) semantically entails b. (EDIT: I was linking to the Wikipedia page for "Interpretation (Logic)" here but I removed this link as I could not find a good explanation of propositional syntax and semantic and the semantic entailment operator on Wikipedia)

EDIT: The only other use of implies in natural language is either modal or temporal. In these cases it can be seen as the implies operator in Kripke semantics for modal logic.

Btw C already has a clean circuited implication that implicitly converts to bool: !a || b.

EDIT: XOR can be expressed as "either .. or" or (in the binary case) as "exactly one of ...".

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Feb 04, 2016 3:10 pm UTC

korona wrote:Btw C already has a clean circuited implication that implicitly converts to bool: !a || b.
I'm not sure I'd call that clean, especially if the "operands" to the implies start becoming complicated. Perhaps this is my fault, but if I see that I don't start thinking about what it means in terms of "implies", I go in thinking "or". And logically equivalent doesn't mean that they're as easy to understand. There have been a few times I've wanted an implies operator in C++ (not nearly badly enough to use implies_trick...) and have resorted to commenting the actual check with a comment that says "// Note that this means 'A implies B'". (This usually arises for me inside an assertion, where I want to say "assert(a implies b)".)

I have become more at peace with "==" meaning "iff", though that usually still gets a comment too. :-)

User avatar
Yakk
Poster with most posts but no title.
Posts: 11083
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Thu Feb 04, 2016 3:26 pm UTC

a?b:true is also a short and simple "implies", without the || baggage.

The first part reads "if a then b", the second "otherwise true". And "if a then b" means "implies".
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

KnightExemplar
Posts: 5494
Joined: Sun Dec 26, 2010 1:58 pm UTC

Re: Coding: Fleeting Thoughts

Postby KnightExemplar » Thu Feb 04, 2016 8:21 pm UTC

So... bought a windows phone, and am excited about Win10 in all honesty. Sideloading is now available everywhere, Visual Studio Community Edition is excellent, all Microsoft examples are just out on github and are open-source.

Microsoft is of course still screwing things up. Only the 950 and 550 support the Win10 platform right now, and their rollout to the 640 (the most popular Windows Phone) has been met with delay after delay. But still, the Win10 desktop rollout has reached 10% of desktop users... so it actually makes sense to start learning Win10 development. Finally, if you write a good app on the Windows platform, you're treated like some kind of hero due to the absolute dearth of apps. Easy differentiation, easy development (VS Community Edition is awesome), seems "morally sound" (sideloading allowed, no more lockin... etc. etc.), and the design language is intriguing.

I've gotten "Hello World" working in C++ Native code (although the C++/CX extensions still scare me, the true-native nature of the code tickles my fancy). It compiles to ARM and x86 and x64, so the single package can move between my ARM phone and my x86-64 desktop.

So Microsoft: is the 3rd time a charm?
First Strike +1/+1 and Indestructible.

User avatar
Flumble
Yes Man
Posts: 2050
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Thu Feb 04, 2016 9:20 pm UTC

I've been in the win10 beta programme with my 735 for half a year now. The worst bug I remember encountering is the data usage monitor complaining (twice!) that I was past the quotum every time I connected to wifi (its statistics were all over the place). And of course the updater getting confused and refusing to install a newer build of the beta for more than a week.

In hindsight I'd have been slightly better off with an android phone (restricted to the ones that have an image without gapps available), but I'm happy with any system that allows to be responsive* and offers teamviewer. :P

KnightExemplar wrote:So... bought a windows phone, and am excited about Win10 in all honesty. Sideloading is now available everywhere, Visual Studio Community Edition is excellent, all Microsoft examples are just out on github and are open-source.

I really like that move. Of course, they're miles behind the competition, but it's a dared step for an old company that heavily relies on IP.

*You know, not hanging when you open the notification area or open the keyboard or push a busy app to the background. It amazes me that not all phones seem to do this out-of-the-box.

KnightExemplar
Posts: 5494
Joined: Sun Dec 26, 2010 1:58 pm UTC

Re: Coding: Fleeting Thoughts

Postby KnightExemplar » Thu Feb 04, 2016 9:43 pm UTC

Flumble wrote:I really like that move. Of course, they're miles behind the competition, but it's a dared step for an old company that heavily relies on IP.


I'm not sure. They're miles behind Google from 2010 for example, but Google has taken significant steps backwards in terms of openness and "don't be evil". What's really allowing Microsoft to catchup to Google is due to the start of Google's anti-competitive behavior.

Google blocked Microsoft's Youtube app for example. Or Google screwing up the official "Gmail" apps on iOS. (Its good enough to say things are supported, but poor enough that I'm cynical. Its almost like Google is trying to make the iOS experience worse with Google services). Google has begun to leverage 90s-era Microsoft tactics. Full support of Google services is only supported on the Android platform. In many regards, Microsoft's move to support Office 365 on iOS and Android, Word, Outlook, Exchange servers and everything... Microsoft is the more open player.

Take AOSP for example, Amazon Kindle or Blackberry implementations of Android don't really count, because Google has tied a lot of the OS into services now (like Google Maps, or Google Payment). Google's use of AOSP is closer to embrace, extend extinguish... there's no real way to make a valid competitor against Google through AOSP due to Android APIs being tied into google services specifically. Consider AOSP Music vs the closed-source Google Play Music... or Google Hangouts vs AOSP SMS Messaging and you'll kinda get where I'm going. More and more of Android has turned into a closed-source google project now.

EDIT: Here's an image that more or less sums up AOSP vs Google:

From: https://fralef.me/using-android-without ... -apps.html

Image

Its probably based on tactics though. Google can leverage its presence due to being a stronger player in the marketplace, while Microsoft now has to work and beg for users. Google is trying to lock in users and developers now through the use of an Open Source project.
Last edited by KnightExemplar on Thu Feb 04, 2016 10:36 pm UTC, edited 2 times in total.
First Strike +1/+1 and Indestructible.

User avatar
ucim
Posts: 6480
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Thu Feb 04, 2016 10:12 pm UTC

korona wrote:I cannot follow your reasoning at all here. Why should c imply b or ~b?
It's not that c (which is ~a) "implies" anything. It's that (in the logic world), c is compatible with b, and is also compatible with ~b, because only a (aka ~c) carries any real implication about b.

My objection is to the use of the word "implies" in this stack-overflow post.

if x and y are "compatible" (could happen together), this doesn't mean that one implies the other (in the vernacular sense of implication). But that's what the post... er... implies. :) So, I just continued the abuse.
let x be c and b.
let y be c and ~b.
Both are TRUE (under the original statement a -> b)

Rewrite it as
let x be c implies b.
let y be c implies ~b.
Distract the audience so that they swallow the new meaning of "implies".

c.

By x, b
By y, ~b

And now I can derive a date with your mom. :)

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11083
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Fri Feb 05, 2016 2:16 am UTC

ucim wrote:My objection is to the use of the word "implies" in this stack-overflow post.

The question? The answers? The comments? Please be more clear than "post", link contains dozens if not hundreds of stack overflow posts.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
ucim
Posts: 6480
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Fri Feb 05, 2016 3:01 am UTC

Yakk wrote:The question? The answers? The comments? Please be more clear than "post", link contains dozens if not hundreds of stack overflow posts.
I was referring to the highest rated answer, which was the first answer after the OP. It said:
Boolean implication A implies B simply means "if A is true, then B must be true". This implies (pun intended) that if A isn't true, then B can be anything. Thus:

False implies False -> True
False implies True -> True
True implies False -> False
True implies True -> True


This can also be read as (not A) or B - i.e. "either A is false, or B must be true".


While it is logically correct, surely they could have used a better word than "implies".... many years ago when this was first set up. "Is consistent with" would be a good choice. (Note also that simply saying "False implies False" is meaningless, because each instance of False refers to a different (false) statement.

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

User avatar
Wildcard
Candlestick!
Posts: 253
Joined: Wed Jul 02, 2008 12:42 am UTC
Location: Outside of the box

Re: Coding: Fleeting Thoughts

Postby Wildcard » Fri Feb 05, 2016 5:45 am UTC

I think of the boolean "implies" relationship as simply "if A then B".

Code: Select all

A         B         if A then B
True      True      True
True      False     False
False     True      N/A (therefore, True)
False     False     N/A (therefore, True)


The illogic of using the word "implies" and the distinction from the typical English meaning may become clear when I make the following statement:

(A implies B) implies (B implies A).

From an English standpoint, this statement is false. The fact that A implies B does not in any way imply that B implies A. However, with the mathematical definition of "implies", this statement is "True" if A and B are both true, "True" if A and B are both false, and "False" only if A is false and B is true.

Or to put it another way which is mathematically sound but linguistically absurd:

The fact itself that B implies A implies that (A implies B) implies that B implies A.
There's no such thing as a funny sig.

User avatar
Wildcard
Candlestick!
Posts: 253
Joined: Wed Jul 02, 2008 12:42 am UTC
Location: Outside of the box

Re: Coding: Fleeting Thoughts

Postby Wildcard » Fri Feb 05, 2016 5:55 am UTC

Fleeting Thought: This is a crime against the Gods of bash1. Application name changed to protect the guilty.

Code: Select all

$ head -1 ./js/script.js
#!./shebang
$ cat ./shebang
#!/bin/sh
`which command1 || which command2` $@
$ # WTF????

:shock:

It reminds me of https://xkcd.com/763/ except that this is production code.

1: Exaggerated for dramatic effect; no offense meant, if the writer of the cited code ever reads this. :wink:
There's no such thing as a funny sig.

KnightExemplar
Posts: 5494
Joined: Sun Dec 26, 2010 1:58 pm UTC

Re: Coding: Fleeting Thoughts

Postby KnightExemplar » Fri Feb 05, 2016 6:15 am UTC

https://msdn.microsoft.com/en-us/library/dd492427.aspx

Holy crap, that's elegant. Congrats Microsoft.
First Strike +1/+1 and Indestructible.

User avatar
chridd
Has a vermicelli title
Posts: 824
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: Coding: Fleeting Thoughts

Postby chridd » Fri Feb 05, 2016 6:46 am UTC

Wildcard wrote:

Code: Select all

$ head -1 ./js/script.js
#!./shebang
$ cat ./shebang
#!/bin/sh
`which command1 || which command2` $@
$ # WTF????
What system does that work on? On my computer (Mac OS X), that sort of thing won't work—#! scripts can't call other #! scripts that way. (Attempting to execute such a script from the shell causes the shell it's executing from to interpret the script; attempting to execute it from a C program gives "Exec format error". This is different from the behavior if the interpreter simply doesn't exist.) From http://linux.die.net/man/2/execve it looks like it won't work on Linux either ("The interpreter must be a valid pathname for an executable which is not itself a script.").
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · she(?)(?(?)(?))(?(?(?))(?))(?) · Forum game scores
mittfh wrote:I wish this post was very quotable...
flicky1991 wrote:In both cases the quote is "I'm being quoted too much!"
chridd (on Discord) wrote:
Dummy wrote:Sorry You're Gay Dads
SYG'D

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6238
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Fri Feb 05, 2016 6:57 am UTC

Behold! A one-round cipher that is as resistant to linear and differential cryptanalysis as mathematically possible:

(note this is a sage script, and won't work in a regular python interpreter)

Code: Select all

from mpmath import mp

mp.prec = 8192

consts = []

p = mp.pi.real()

while len(consts) < 16:
   p -= floor(p)
   p *= 2**256
   consts.append(floor(p))

QQ.<t> = GF(2)[]
F = GF(2**256,'t')

p = 1

mods = []

while len(mods) < 15:
   p = next_prime(p)
   a = mp.sqrt(p)
   a = t**256 + F.fetch_int(int((a-floor(a))*2**256) | 1).polynomial()
   if a.is_primitive():
      mods.append(a)

def mult(x, k, m):
   A = GF(2**256, 't', modulus=m)
   return (A.fetch_int(k)*A.fetch_int(x)).integer_representation()

def inv_mult(x, m):
   if x == 0:
      return 0
   else:
      A = GF(2**256, 't', modulus=m)
      return (A.fetch_int(x)^-1).integer_representation()

def crypt(x, k0, k1, k2, k3, m1, m2, m3):
   x ^^= k0
   x = mult(x, k1, m1)
   x = (x >> 128) | ((x & (2**128-1)) << 128)
   inv_mult(x, m2)
   x = (x >> 128) | ((x & (2**128-1)) << 128)
   x = mult(x, k2, m3)
   return x ^^ k3


def get_subkey(key, n):
   return crypt(key, consts[n*4], consts[n*4+1], consts[n*4+2], consts[n*4+3], mods[n*3], mods[n*3+1], mods[n*3+2])

def encrypt(x, key):
   return crypt(x, get_subkey(key,0), get_subkey(key, 1) | 2**255, get_subkey(key, 2) | 2**255, get_subkey(key, 3), mods[12], mods[13], mods[14])

def decrypt(x, key):
   return crypt(x, get_subkey(key,3), inv_mult(get_subkey(key, 2) | 2**255, mods[14]), inv_mult(get_subkey(key, 1) | 2**255, mods[12]), get_subkey(key, 0), mods[14], mods[13], mods[12])

key = randint(0,2**256)
x = randint(0,2**256)
print x
x = encrypt(x, key)
print x
x = decrypt(x, key)
print x

Note, everything up to the function defs are computing constants, but it's less code to write than the constants. Also, even after computing the constants, it is ridiculously slow for a block cipher (and I made absolutely no attempt to optimize), and probably ridiculously susceptible to side channel attacks.
Summum ius, summa iniuria.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Fri Feb 05, 2016 7:14 am UTC

Wildcard wrote:The illogic of using the word "implies" and the distinction from the typical English meaning may become clear when I make the following statement:

(A implies B) implies (B implies A).

From an English standpoint, this statement is false. The fact that A implies B does not in any way imply that B implies A. However, with the mathematical definition of "implies", this statement is "True" if A and B are both true, "True" if A and B are both false, and "False" only if A is false and B is true.
Perhaps my brain is so warped to the "unintuitive" logical notion that I still can't see what the English meaning is supposed to be.

That expression does have a difference from the logical interpretation. Intuitively, I put a "for all A, B" before "(A implies B) implies (B implies A)" when trying to interpret it as English. Of course, if you make a similar adjustment to the logical expression it becomes false. But I view that as being not a difference with the meaning as "implies" but as a higher level aspect of the interpretation of a pseudo-logical expression with variables.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests