Coding: Fleeting Thoughts

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

Moderators: phlip, Prelates, Moderators General

Re: Coding: Fleeting Thoughts

Postby Steax » Tue Mar 20, 2012 1:36 am UTC

Xanthir wrote:Aw shucks, you're making me blush. This is just a natural result of being paid to do standards work, and thus spending 5+ hours a day on CSS, HTML, and JS language mailing lists.

On that note, woo, my Variables module got published as a First Public Working Draft!


I, and a million others out there, love you.

It's about time.

Out of curiosity, why are you opting for this solution rather than a new syntax, like the @variable syntax used by LESS?
In Minecraft, I use the username Rirez.
User avatar
Steax
SecondTalon's Goon Squad
 
Posts: 3037
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby phlip » Tue Mar 20, 2012 2:36 am UTC

Steax wrote:I, and a million others out there, love you.

It's about time.

Heck yes.
While no one overhear you quickly tell me not cow cow.
but how about watch phone?
User avatar
phlip
Restorer of Worlds
 
Posts: 7172
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia

Re: Coding: Fleeting Thoughts

Postby Xanthir » Tue Mar 20, 2012 10:18 pm UTC

Steax wrote:
Xanthir wrote:Aw shucks, you're making me blush. This is just a natural result of being paid to do standards work, and thus spending 5+ hours a day on CSS, HTML, and JS language mailing lists.

On that note, woo, my Variables module got published as a First Public Working Draft!


I, and a million others out there, love you.

It's about time.

Out of curiosity, why are you opting for this solution rather than a new syntax, like the @variable syntax used by LESS?

The stuff in the draft is a strict superset of the LESS/SASS/etc variables. If you restrict yourself solely to setting data properties on :root{}, you have identical power. Setting them on other elements, though, gives you a weak (but useful) form of scoping for "free".
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4310
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Coding: Fleeting Thoughts

Postby Xeio » Thu Mar 22, 2012 9:21 pm UTC

public static T Deserialize<T>(string serialisedString) where T : class

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

Re: Coding: Fleeting Thoughts

Postby Xanthir » Thu Mar 22, 2012 9:51 pm UTC

Blame the British.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4310
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Coding: Fleeting Thoughts

Postby Xeio » Thu Mar 22, 2012 10:01 pm UTC

It's not even that, it's inconsistent naming in the same line!

Now that you mention it, one of our architects is British though...
User avatar
Xeio
Friends, Faidites, Countrymen
 
Posts: 4784
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\

Re: Coding: Fleeting Thoughts

Postby Thesh » Fri Mar 23, 2012 1:24 am UTC

That's horrible, capitalizing random letters like that.
Deceiving appearance, they're dressed up as gods.
Fake that they care, their conscience is lost.
Denial their craft and riots our goal.
They lead those who follow and break those who fall.
User avatar
Thesh
Has the Brain Worms, In Case You Forgot.
 
Posts: 3646
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: California, Southern USA

Re: Coding: Fleeting Thoughts

Postby qubital » Fri Mar 23, 2012 2:55 am UTC

Coding, is it worth mastering Perl?
I'm currently reading Mastering Regular Expressions and the author is kinda pushing Perl but I'm not sure, seems kinda antiquated.
qubital
 
Posts: 24
Joined: Fri Mar 02, 2012 12:13 am UTC

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Fri Mar 23, 2012 5:39 am UTC

qubital wrote:Coding, is it worth mastering Perl?
I'm currently reading Mastering Regular Expressions and the author is kinda pushing Perl but I'm not sure, seems kinda antiquated.

Oh-oh! This could turn into a Religious War.

What languages do you know?

If you don't like the look of Perl you're in good company. :) Different languages offer slightly different "flavours" of RE, and Perl-style RE is often seen as the default flavour. I don't know Perl, but I often use regular expressions in python, awk & sed, and in grep commands. And I've used them occasionally in JavaScript.
User avatar
PM 2Ring
 
Posts: 3257
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Mid north coast, NSW, Australia

Re: Coding: Fleeting Thoughts

Postby qubital » Fri Mar 23, 2012 6:07 am UTC

PM 2Ring wrote:
qubital wrote:Coding, is it worth mastering Perl?
I'm currently reading Mastering Regular Expressions and the author is kinda pushing Perl but I'm not sure, seems kinda antiquated.

Oh-oh! This could turn into a Religious War.

What languages do you know?

If you don't like the look of Perl you're in good company. :) Different languages offer slightly different "flavours" of RE, and Perl-style RE is often seen as the default flavour. I don't know Perl, but I often use regular expressions in python, awk & sed, and in grep commands. And I've used them occasionally in JavaScript.

I know Haskell and some Scheme. I was looking to learn a language that would aid my Linux skills.
qubital
 
Posts: 24
Joined: Fri Mar 02, 2012 12:13 am UTC

Re: Coding: Fleeting Thoughts

Postby Thesh » Fri Mar 23, 2012 6:32 am UTC

Perl used to be the scripting language of choice for linux, but from what I hear the main contenders are Ruby and Python while Perl is on its way out.

I'm not a linux guy, so I may be wrong, but that's just what I've been hearing.
Deceiving appearance, they're dressed up as gods.
Fake that they care, their conscience is lost.
Denial their craft and riots our goal.
They lead those who follow and break those who fall.
User avatar
Thesh
Has the Brain Worms, In Case You Forgot.
 
Posts: 3646
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: California, Southern USA

Re: Coding: Fleeting Thoughts

Postby shawnhcorey » Fri Mar 23, 2012 11:52 am UTC

qubital wrote:Coding, is it worth mastering Perl?
I'm currently reading Mastering Regular Expressions and the author is kinda pushing Perl but I'm not sure, seems kinda antiquated.


Perl's regular expressions are the most powerful around. In fact, both Python and Ruby uses Perl's regular expression engine. You should be able to use the regular expressions from the book directly in these languages without any modification.
User avatar
shawnhcorey
 
Posts: 42
Joined: Sun Jan 08, 2012 2:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby EvanED » Fri Mar 23, 2012 11:56 am UTC

shawnhcorey wrote:
qubital wrote:Coding, is it worth mastering Perl?
I'm currently reading Mastering Regular Expressions and the author is kinda pushing Perl but I'm not sure, seems kinda antiquated.


Perl's regular expressions are the most powerful around. In fact, both Python and Ruby uses Perl's regular expression engine. You should be able to use the regular expressions from the book directly in these languages without any modification.

With the caveat that if there are places they are used in Perl code snippets, you'll have to transliterate them of course. That could take some effort.

I can also imagine there are some modifiers (like /abc/bi to match "abc" but insensitively -- I don't actually know if this is how Perl does it, but I think I've seen it) which also have to be translated as well. E.g. in Python you'd have to pass some CASE_INSENSITIVE constant to the re constructor.

Also, I'm with people who think that in a world with today's Python, Perl serves very little purpose and wish that no new code was written in it. (Of course, I also think that about C, with partial exceptions for actual embedded systems, so take that with a grain of salt.)
EvanED
 
Posts: 4133
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Coding: Fleeting Thoughts

Postby shawnhcorey » Fri Mar 23, 2012 12:12 pm UTC

EvanED wrote:I can also imagine there are some modifiers (like /abc/bi to match "abc" but insensitively -- I don't actually know if this is how Perl does it, but I think I've seen it) which also have to be translated as well. E.g. in Python you'd have to pass some CASE_INSENSITIVE constant to the re constructor.


Since the book is written in Perl's regex, they should work with Perl. The /i is called a modifier; for a complete list, see `perldoc perlre` and search for /Modifiers/.

EvanED wrote:Also, I'm with people who think that in a world with today's Python, Perl serves very little purpose and wish that no new code was written in it. (Of course, I also think that about C, with partial exceptions for actual embedded systems, so take that with a grain of salt.)


Yeah, Pythoners have been dis'ing Perl from the start. I'd wish they would grow up.
User avatar
shawnhcorey
 
Posts: 42
Joined: Sun Jan 08, 2012 2:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby EvanED » Fri Mar 23, 2012 12:28 pm UTC

shawnhcorey wrote:
EvanED wrote:Also, I'm with people who think that in a world with today's Python, Perl serves very little purpose and wish that no new code was written in it. (Of course, I also think that about C, with partial exceptions for actual embedded systems, so take that with a grain of salt.)


Yeah, Pythoners have been dis'ing Perl from the start. I'd wish they would grow up.

I've been dissing it well before I knew much about Python. You can feel free to like it if you want, but I'm more than content not having to deal with it. But I won't say any more about it in this thread.
EvanED
 
Posts: 4133
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: Coding: Fleeting Thoughts

Postby not baby Newt » Mon Mar 26, 2012 9:54 pm UTC

An old thread got me thinking of windows for. It's remarkably flexible, in an insane swiss army knife kind of way. For example, it does file parsing.

Code: Select all
C:\foobar>type silly.bat
@REM split file into tokens, pretend last token is a fully qualified file name.
@for /F "eol=; tokens=2,3* delims=," %%i in (myfile.txt) do @echo %%i^^^^%%j^^^^%%~dpxk^^^^

C:\foobar>type myfile.txt
foo,bar1,barbara,letsPretendThisIsAFileName.txt
;foo,bar2,barbara,banana2,foo
foo,bar3,bar;bara,banana3,foo
C:\foobar>silly.bat
bar1^^barbara^^C:\foobar\.txt^^
bar3^^bar;bara^^C:\foobar\^^

C:\foobar>
not baby Newt
 
Posts: 109
Joined: Wed Feb 03, 2010 11:30 pm UTC

Re: Coding: Fleeting Thoughts

Postby Falling » Mon Mar 26, 2012 10:28 pm UTC

EvanED wrote:shawnhcorey wrote:
EvanED wrote:
Also, I'm with people who think that in a world with today's Python, Perl serves very little purpose and wish that no new code was written in it. (Of course, I also think that about C, with partial exceptions for actual embedded systems, so take that with a grain of salt.)


Yeah, Pythoners have been dis'ing Perl from the start. I'd wish they would grow up.

I've been dissing it well before I knew much about Python. You can feel free to like it if you want, but I'm more than content not having to deal with it. But I won't say any more about it in this thread.


I'm a Rubyer and making fun of Perl is a favorite pastime of mine.
Falling
 
Posts: 175
Joined: Mon Nov 24, 2008 4:30 pm UTC

Re: Coding: Fleeting Thoughts

Postby shawnhcorey » Mon Mar 26, 2012 10:33 pm UTC

Falling wrote:
EvanED wrote:shawnhcorey wrote:
EvanED wrote:
Also, I'm with people who think that in a world with today's Python, Perl serves very little purpose and wish that no new code was written in it. (Of course, I also think that about C, with partial exceptions for actual embedded systems, so take that with a grain of salt.)


Yeah, Pythoners have been dis'ing Perl from the start. I'd wish they would grow up.

I've been dissing it well before I knew much about Python. You can feel free to like it if you want, but I'm more than content not having to deal with it. But I won't say any more about it in this thread.


I'm a Rubyer and making fun of Perl is a favorite pastime of mine.


Well, I've been taught not to pick on those less fortunate than me. That's why I don't dis Python or Ruby.
User avatar
shawnhcorey
 
Posts: 42
Joined: Sun Jan 08, 2012 2:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby Falling » Mon Mar 26, 2012 10:51 pm UTC

shawnhcorey wrote:Well, I've been taught not to pick on those less fortunate than me. That's why I don't dis Python or Ruby.


Ooh I'm gonna try to be mature and not start a war here. I have spent some time with Perl so I'm not totally talking out of my ass.

I honestly want to know though - what makes you think Perl is better than Ruby or Python?
Falling
 
Posts: 175
Joined: Mon Nov 24, 2008 4:30 pm UTC

Re: Coding: Fleeting Thoughts

Postby shawnhcorey » Mon Mar 26, 2012 10:59 pm UTC

Falling wrote:I honestly want to know though - what makes you think Perl is better than Ruby or Python?


Perl is the only one that can do arithmetic right:

Code: Select all
$ python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0
>>>
$ irb
irb(main):001:0> 1/2
=> 0
irb(main):002:0> $ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
$ perl -E'say 1/2'
0.5
$
User avatar
shawnhcorey
 
Posts: 42
Joined: Sun Jan 08, 2012 2:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby Falling » Mon Mar 26, 2012 11:23 pm UTC

shawnhcorey wrote:
Falling wrote:I honestly want to know though - what makes you think Perl is better than Ruby or Python?


Perl is the only one that can do arithmetic right:

Code: Select all
$ python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0
>>>
$ irb
irb(main):001:0> 1/2
=> 0
irb(main):002:0> $ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
$ perl -E'say 1/2'
0.5
$


Hah well there ya go; I'm converted.
Falling
 
Posts: 175
Joined: Mon Nov 24, 2008 4:30 pm UTC

Re: Coding: Fleeting Thoughts

Postby Maelstrom. » Mon Mar 26, 2012 11:59 pm UTC

Falling wrote:
shawnhcorey wrote:
Falling wrote:I honestly want to know though - what makes you think Perl is better than Ruby or Python?


Perl is the only one that can do arithmetic right:

Code: Select all
$ python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0
>>>
$ irb
irb(main):001:0> 1/2
=> 0
irb(main):002:0> $ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
$ perl -E'say 1/2'
0.5
$


Hah well there ya go; I'm converted.

Python 3 has 'correct' division by default, instead of integer division. Your argument is invalid as soon as Python 3 hits the main stream :)

See Whats new in Python 3, or PEP 238 for more information.
Maelstrom.
 
Posts: 71
Joined: Tue Oct 21, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby shawnhcorey » Tue Mar 27, 2012 12:25 am UTC

Maelstrom. wrote:Python 3 has 'correct' division by default, instead of integer division. Your argument is invalid as soon as Python 3 hits the main stream :)


Which will be a while. Many OSes are keeping v2 since it's backward compatible with all the old Python code. We still have COBOL hanging around for the same reason; Python 2 is not going away very fast.
User avatar
shawnhcorey
 
Posts: 42
Joined: Sun Jan 08, 2012 2:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Tue Mar 27, 2012 7:03 am UTC

Alternatively, just write 1.0/2.0 (or if you're hardcoding it, 0.5) and be done with it.
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!
User avatar
Aaeriele
 
Posts: 2107
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby shawnhcorey » Tue Mar 27, 2012 12:15 pm UTC

Aaeriele wrote:Alternatively, just write 1.0/2.0 (or if you're hardcoding it, 0.5) and be done with it.


The problem comes when using variables:
Code: Select all
x = ( a + 0.0 ) / b;

Programmers have to remember that integer division is not real division. And the more a programmer has to remember, the greater the chances of a bug. Remember: datatypes were invented by compiler designers to make writing compilers easier; they were not invented to make programming easier.
User avatar
shawnhcorey
 
Posts: 42
Joined: Sun Jan 08, 2012 2:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Tue Mar 27, 2012 12:32 pm UTC

PM 2Ring wrote:Oh-oh! This could turn into a Religious War.

What did I tell ya? :)

On "proper" arithmetic:

Maybe I'm just weird, but I think it makes sense for (traditional) Python to use integer division when dividing one integer by another. OTOH, I tend to explicitly use the // operator for integer division and to use a float() "cast" when I specifically desire real division. Maybe some people find this aspect of Python to be annoying or confusing, but I don't.

I used to enjoy programming in Amiga E, a rather powerful object-oriented compiled language. One of its quirky features was that it used "calculator precedence" for arithmetic, ie operators were evaluated in strict left to right order with no precedence, apart from that dictated by parentheses. It was annoying at first, but you soon got used to it.
User avatar
PM 2Ring
 
Posts: 3257
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Mid north coast, NSW, Australia

Re: Coding: Fleeting Thoughts

Postby shawnhcorey » Tue Mar 27, 2012 1:14 pm UTC

PM 2Ring wrote:One of its quirky features was that it used "calculator precedence" for arithmetic, ie operators were evaluated in strict left to right order with no precedence, apart from that dictated by parentheses. It was annoying at first, but you soon got used to it.


HP calculators have post-fix notation. It is annoying at first, but you soon get to hate it. :P
User avatar
shawnhcorey
 
Posts: 42
Joined: Sun Jan 08, 2012 2:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Tue Mar 27, 2012 4:10 pm UTC

PM 2Ring wrote:Maybe I'm just weird, but I think it makes sense for (traditional) Python to use integer division when dividing one integer by another.


^ That.

It's quite possible this is simply because I'm used to C, but integer division among integers makes sense to me. In almost every situation where I want a floating-point answer, I already have floating point inputs.
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!
User avatar
Aaeriele
 
Posts: 2107
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby korona » Tue Mar 27, 2012 11:12 pm UTC

shawnhcorey wrote:Programmers have to remember that integer division is not real division. And the more a programmer has to remember, the greater the chances of a bug. Remember: datatypes were invented by compiler designers to make writing compilers easier; they were not invented to make programming easier.

I don't think thats correct. Data types were invented because not all values used in a program have the same type.

I had to write the following code once:
Code: Select all
   real scalar bitwise_or(real scalar left_in, real scalar right_in) {
      real scalar left
      real scalar right
      real scalar result
      left = left_in
      right = right_in
      result = 0
      
      real scalar i
      for(i = 31; i >= 0; i--) {
         if(mod(left, 2^i) != left && mod(right, 2^i) != right) {
            left = left - 2^i
            right = right - 2^i
            result = result + 2^i
         }else if(mod(left, 2^i) != left) {
            left = left - 2^i
            result = result + 2^i
         }else if(mod(right, 2^i) != right) {
            right = right - 2^i
            result = result + 2^i
         }
      }
      return(result)
   }

Because the inventors of the programming language this is written in apparently thought that real division is the only correct division and that all non-complex numbers should share the same data type.
Yes, the code is incredibly ugly, I think that it is really the worst thing I ever wrote in my life. And no, the programming language had no integer types, integer division, bitwise shift, bitwise or, bitwise and or any other operator that worked directly on integer variables.
korona
 
Posts: 352
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby shawnhcorey » Tue Mar 27, 2012 11:33 pm UTC

And it, no doubt, worked with binary real numbers rather than decimal real numbers (like a calculator). Let's face it: some of the things program-language designers did was strange.
User avatar
shawnhcorey
 
Posts: 42
Joined: Sun Jan 08, 2012 2:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby b.i.o » Wed Mar 28, 2012 12:55 am UTC

from __future__ import division
User avatar
b.i.o
Green is the loneliest number
 
Posts: 2520
Joined: Fri Jul 27, 2007 4:38 pm UTC
Location: Hong Kong

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Wed Mar 28, 2012 1:04 am UTC

shawnhcorey wrote:HP calculators have post-fix notation. It is annoying at first, but you soon get to hate it. :P

I quite like postfix notation: I was rather intrigued by it when I first saw a HP calculator in the early 1970s, but I've never owned one myself. I have used postfix notation quite a lot in the last couple of decades, though, since I enjoy writing in PostScript. I admit it does take me a few minutes to get my brain into (or out of) postfix mode, but once I am in postfix mode I find it quite easy to read and write. I suppose it's fair to say that writing PostScript is slightly easier than reading it, but I tend to structure my PostScript programs to make them human-friendly and I rarely have problems understanding PostScript programs I wrote years ago.
User avatar
PM 2Ring
 
Posts: 3257
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Mid north coast, NSW, Australia

Re: Coding: Fleeting Thoughts

Postby Thesh » Wed Mar 28, 2012 1:15 am UTC

Aaeriele wrote:
PM 2Ring wrote:Maybe I'm just weird, but I think it makes sense for (traditional) Python to use integer division when dividing one integer by another.


^ That.

It's quite possible this is simply because I'm used to C, but integer division among integers makes sense to me. In almost every situation where I want a floating-point answer, I already have floating point inputs.


Agreed. I can't think of any situation where I had division where I wasn't taking advantage of integer division or using floating point numbers to begin with.
Deceiving appearance, they're dressed up as gods.
Fake that they care, their conscience is lost.
Denial their craft and riots our goal.
They lead those who follow and break those who fall.
User avatar
Thesh
Has the Brain Worms, In Case You Forgot.
 
Posts: 3646
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: California, Southern USA

Re: Coding: Fleeting Thoughts

Postby qubital » Wed Mar 28, 2012 1:21 am UTC

shawnhcorey wrote:
Falling wrote:I honestly want to know though - what makes you think Perl is better than Ruby or Python?


Perl is the only one that can do arithmetic right:

Code: Select all
$ python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0
>>>
$ irb
irb(main):001:0> 1/2
=> 0
irb(main):002:0> $ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
$ perl -E'say 1/2'
0.5
$

Code: Select all
Prelude> 1/2
0.5

Haskell gets it right too.
qubital
 
Posts: 24
Joined: Fri Mar 02, 2012 12:13 am UTC

Re: Coding: Fleeting Thoughts

Postby phlip » Wed Mar 28, 2012 1:46 am UTC

Haskell looked at all the different options for division and said "screw it, let's just put all of 'em in there". And so it has all three of floating-point-division, integer-division-rounded-down and integer-division-rounded-toward-0, each with its own name.
While no one overhear you quickly tell me not cow cow.
but how about watch phone?
User avatar
phlip
Restorer of Worlds
 
Posts: 7172
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia

Re: Coding: Fleeting Thoughts

Postby Rium » Wed Mar 28, 2012 6:02 pm UTC

I’m learning CSS, and I’d like the h2 elements to have a background image. The difficult part, for me, is positioning the image relative to the text. To my own surprise, I came up with something that kind of works:

Code: Select all
.bluebg {
   background: url(blue_1.jpg) no-repeat left bottom;
   width: 400px;
   height: 79px;
   padding: 0px 0px 0px 60px;
   }

and <h2 class="bluebg">, which allows you to move the text/image*, but I’m pretty sure that is not the best way to do that. Do you know a better solution?

* If the image is 400x79, a height greater than 79 will move the image down without affecting the text. height: 59px and padding-top: 20px, on the other hand, will move the text down by 20px without affecting the image.
User avatar
Rium
 
Posts: 70
Joined: Sat Feb 04, 2012 12:57 am UTC

Re: Coding: Fleeting Thoughts

Postby Xanthir » Wed Mar 28, 2012 8:56 pm UTC

No, combining height+padding to equal the height of your background image is pretty normal. Do you have a live example somewhere?
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4310
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Coding: Fleeting Thoughts

Postby Rium » Wed Mar 28, 2012 11:38 pm UTC

Huh, I didn’t know that, thanks. I don’t have a live webpage yet. I guess what bothered me with this method was that the position of the text didn’t stay the same, but then I realized that this is easy to fix with position: relative.
User avatar
Rium
 
Posts: 70
Joined: Sat Feb 04, 2012 12:57 am UTC

Re: Coding: Fleeting Thoughts

Postby Xanthir » Thu Mar 29, 2012 12:23 am UTC

I'm slightly confused about what you're trying to achieve. :/ A live example would let me give you much better advice than just guessing. It sounds like you may be overcomplicating things, but I can't tell right now.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4310
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Coding: Fleeting Thoughts

Postby Steax » Thu Mar 29, 2012 12:33 am UTC

Try making a Fiddle for us to see.

Positioning things with CSS is rather counterintuitive (stupid box models). So when you declare a width of 400px and a left padding of 60px, you're actually defining the element size as 460px. (To get around this, you can actually set a -webkit-box-sizing: border-box; rule, though I'm not sure how well-supported that is; there's also a -moz- version too, at least.)

So yes, what you're doing is, at least according to the specs, defining your element's content to be 400px wide, then you add 60px space to the left of that content, and the background image should span all of that, up to the borders. It can be quite confusing, yes. You'll get the hang of it. What you're doing is pretty much the "right" way.

@Xanthir: I think he's trying to place HTML text that's pushed slightly to the right, and overlaying that on top of an image. Like this. Presumably the background image involves something on the left of the text.
In Minecraft, I use the username Rirez.
User avatar
Steax
SecondTalon's Goon Squad
 
Posts: 3037
Joined: Sat Jan 12, 2008 12:18 pm UTC

PreviousNext

Return to Coding

Who is online

Users browsing this forum: No registered users and 8 guests