Coding: Fleeting Thoughts

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

Moderators: phlip, Moderators General, Prelates

Anonymously Famous
Posts: 242
Joined: Thu Nov 18, 2010 4:01 am UTC

Re: Coding: Fleeting Thoughts

Postby Anonymously Famous » Wed Aug 10, 2011 12:15 am UTC

userxp wrote:If I were creating a new programming language, I'd make it have built-in HTML output for quick and easy graphical interfacing. Not sure how easy that would be to implement (no Javascript of course, otherwise combining the two languages would be a mess).

Languages like PHP have HTML "built-in" as it were.

Also, if you're using Windows, you can create an HTML interface, add in some Javascript and/or VBscript, change the extension to ".hta" and voila! Instant GUI application!

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? » Wed Aug 10, 2011 12:30 am UTC

Didn't some forumite work on HTML output for haskell?
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

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

Re: Coding: Fleeting Thoughts

Postby EvanED » Wed Aug 10, 2011 12:32 am UTC

Anonymously Famous wrote:
userxp wrote:If I were creating a new programming language, I'd make it have built-in HTML output for quick and easy graphical interfacing. Not sure how easy that would be to implement (no Javascript of course, otherwise combining the two languages would be a mess).

Languages like PHP have HTML "built-in" as it were.

Also, if you're using Windows, you can create an HTML interface, add in some Javascript and/or VBscript, change the extension to ".hta" and voila! Instant GUI application!

That's only sort of true. For instance, unless there's something I don't know about, you can't grab an HTML snippet and put it into a variable except through the standard string-concatenation things you do.

Anonymously Famous
Posts: 242
Joined: Thu Nov 18, 2010 4:01 am UTC

Re: Coding: Fleeting Thoughts

Postby Anonymously Famous » Wed Aug 10, 2011 3:38 am UTC

EvanED wrote:That's only sort of true. For instance, unless there's something I don't know about, you can't grab an HTML snippet and put it into a variable except through the standard string-concatenation things you do.

Well, there is the innerHTML property, which can be used in either Javascript or VBscript. As long as you can access a given tag, you can grab all of the HTML within that tag. Unless you're talking about something else.

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

Re: Coding: Fleeting Thoughts

Postby phlip » Wed Aug 10, 2011 4:13 am UTC

I think Evan was replying to the PHP part of that post, not the Javascript part. Which is accurate... unless you're building your webpage with DOM or something similar, PHP doesn't really have much special HTML powers aside from the usual string manipulation and a couple of useful utility functions (like urlencode and htmlspecialchars). Only thing it has is the shorthand for output statements by putting text outside a PHP block... which isn't exactly unique to PHP anyway, between ASP and JSP and probably others working the same way.

Code: Select all

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

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Wed Aug 10, 2011 4:14 am UTC

I think he means that PHP has the ability to output HTML, but it's not able to actually read from HTML itself. I guess that could be useful for some things in certain ways. On the other hand, I believe PHP has output buffering, which lets you read HTML already rendered, which should theoretically allow you to pass it into the XML parser and extract whatever data you need.
In Minecraft, I use the username Rirez.

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

Re: Coding: Fleeting Thoughts

Postby EvanED » Wed Aug 10, 2011 5:57 am UTC

I mean something like

Code: Select all

var x = <p>Hello all of you folks, how are <em>you</em> doing?</p>
// now x has the DOM of that code, or something like that


You know, like the way LINQ embeds (mostly?) native SQL syntax in C# ;-)

Code: Select all

var results =  from c in SomeCollection
               where c.SomeProperty < someValue * 2
               select new {c.SomeProperty, c.OtherProperty};
foreach (var result in results) {
        Console.WriteLine(result);
}

(from Wikipedia.)

I'm not completely convinced on whether it would be worth it, but I'm not completely against the idea either. It does have benefits over the alternatives at the cost of increased language/compiler complexity.

Anonymously Famous
Posts: 242
Joined: Thu Nov 18, 2010 4:01 am UTC

Re: Coding: Fleeting Thoughts

Postby Anonymously Famous » Wed Aug 10, 2011 6:23 am UTC

EvanED wrote:You know, like the way LINQ embeds (mostly?) native SQL syntax in C# ;-)

And how VB.net can use XML (and thus, XHTML) literals?

Code: Select all

Dim contact1 As XElement =
    <contact>
      <name>Patrick Hines</name>
      <phone type="home">206-555-0144</phone>
      <phone type="work">425-555-0145</phone>
    </contact>

Code taken from msdn.microsoft.com

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Wed Aug 10, 2011 6:43 am UTC

That's done like this with the simplexml (built-in) extension:

Code: Select all


$x 
= new SimpleXMLElement("<p>Hello all of you folks, how are <em>you</em> doing?</p>");

// get the emphasis
echo $x->p->em;

// if you had many paragraphs/ems you can also do
foreach($x->p->em as $emphasis){
    echo $emphasis;
}
 


You also have the usual abilities to add attributes and child nodes and so forth. At the end you can dump them as plain XML with the SimpleXMLElement::asXML function.

Now I wonder if anyone could write a PHP jQuery-esque wrapper for that function...
In Minecraft, I use the username Rirez.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Wed Aug 10, 2011 11:55 am UTC

You, sir, name? wrote:Didn't some forumite work on HTML output for haskell?

I made a library for myself that isn't even remotely ready to release. I recommend blaze-html.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

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

Re: Coding: Fleeting Thoughts

Postby EvanED » Wed Aug 10, 2011 5:12 pm UTC

Anonymously Famous wrote:
EvanED wrote:You know, like the way LINQ embeds (mostly?) native SQL syntax in C# ;-)

And how VB.net can use XML (and thus, XHTML) literals?

I thought I had seen something like that, but I didn't look for it very hard then. Thanks.

Steax wrote:That's done like this with the simplexml (built-in) extension:

Code: Select all


$x 
= new SimpleXMLElement("<p>Hello all of you folks, how are <em>you</em> doing?</p>"); 

So for an interpreted language like PHP, this distinction doesn't apply so much, but there are benefits to having that be first-class syntax instead of a function call (which is what I suspect that is).

First, this hypothetical compiler can do well-formedness (and perhaps even validity) checks at compile time.

Second, it can properly quote things. What will the following code do?

Code: Select all

$expression = "1 < 2 is true, and 1 > 2 is false";
$x = new SimpleXMLElement("<p>The expression says<em>" + $expression + "</em></p>")

Now, I'm not a PHP programmer, but I'd bet $20 that what it won't do is give you a DOM where the contents of the <em> node is "1 &lt; is true, and 1 &gt; 2 is false".

However, in our hypothetical language, this could:

Code: Select all

$expression = ...
$x = <p>The expression says that <em>$expression</em></p>

and in fact I feel very strongly that is the correct behavior in a language that would support a feature like that.

No, it's not hard to put in an htmlEscape call (or whatever they call that function) in the version above -- but it is one more thing you have to remember. (How many SQL injections still happen today, despite it being an very widely-known problem?) If you don't have to do it in the first place, then you can't forget.

Worth the complexity? I dunno. But from a standpoint of what the language does for you, I stand by my statement that it's better.

bittyx
Posts: 194
Joined: Tue Sep 25, 2007 9:10 pm UTC
Location: Belgrade, Serbia

Re: Coding: Fleeting Thoughts

Postby bittyx » Wed Aug 10, 2011 5:51 pm UTC

Steax wrote:That's done like this with the simplexml (built-in) extension:

Code: Select all


$x 
= new SimpleXMLElement("<p>Hello all of you folks, how are <em>you</em> doing?</p>");

// get the emphasis
echo $x->p->em;

// if you had many paragraphs/ems you can also do
foreach($x->p->em as $emphasis){
    echo $emphasis;
}
 


You also have the usual abilities to add attributes and child nodes and so forth. At the end you can dump them as plain XML with the SimpleXMLElement::asXML function.

Now I wonder if anyone could write a PHP jQuery-esque wrapper for that function...


SimpleXML is actually not the "recommended" choice for manipulating XML data, DOM is the preferred option among most of the PHP devs I know. Here's a fun link for you: phpQuery.

@EvanED:
You are correct that PHP's string concatenation (which is done by the "." operator in PHP - I understand you don't use the language, just thought I'd mention it) won't automatically escape the "<" and ">" into HTML entities, but, for me at least, that's the way I like it - I don't really want my language to do that sort of stuff because it would have unexpected consequences. If I say I want a "<" in my string, I don't want it changed until I say so. Same goes for any other "automatic" processes (like the awful magic_quotes option PHP had for some time, which automatically escaped all quotes from GET and POST data, and that was finally deprecated because it was just gruesome). The syntax you've used is also not something I'd like to have in my language of choice - I really just prefer it like this - using HTML as strings. If you really want, you could easily code a class with chainable calls to do something like that, but I don't see the need for that. (You can check out the phpQuery link, it basically does something like that)

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Wed Aug 10, 2011 6:21 pm UTC

HOLY----

/goes off to read phpquery

And yes EvanED, it's not as smooth or integrated as it could be. PHP is a giant mess anyway. I'm just pointing out how it possibly could work.
In Minecraft, I use the username Rirez.

userxp
Posts: 436
Joined: Thu Jul 09, 2009 12:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby userxp » Wed Aug 10, 2011 9:01 pm UTC

I think it'd be easy to implement in Python without having to modify the core of the language, just adding a few classes and functions:

Code: Select all

from datetime import datetime

showPage(HTML("""
<form action="mainForm" method="get">
   <p>Please enter your name: <input type="text" name="name"></p>
   <p>and your age: <input type="number" name="age" min="1" max="130" step="1"> </p><!-- Hey that's an HTML5 form!-->
   <input type="submit" value="Submit" />
</form>
"""))
#showPage receives an HTML object and displays it in a new window.
#It doesn't need to be a full HTML page, so you can omit the <head> <title> </title> <body> tags.
#For convenience, HTML("<abc>") could be replaced with some syntactic sugar like {<abc>}.

formdata=getForm("mainForm") #getForm blocks execution until form is submitted. Alternatively you could bind a function to it and continue execution.

closeAllPages()
showPage(HTML("<p>Hello, "+formdata.field("name")+" you were born in "+str(datetime.now().year - formdata.field("age")+ ", right? </p>"))

I hope I didn't make any obvious mistakes writing this.

Alternatively you could do the opposite and just use GTK with Javascript.
Last edited by userxp on Thu Aug 11, 2011 8:04 pm UTC, edited 1 time in total.

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Wed Aug 10, 2011 11:20 pm UTC

You can also write Qt-like applications in C++ that generate HTML at runtime.

It uses neither DOM objects nor string concatenation- instead, you work with high-level widgets and let the library generate the HTML code.
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

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

Re: Coding: Fleeting Thoughts

Postby EvanED » Wed Aug 10, 2011 11:25 pm UTC

userxp wrote:I think it'd be easy to implement in Python without having to modify the core of the language, just adding a few classes and functions:

Code: Select all

showPage(HTML("<p>Hello, "+formdata.field("name")+" you were born in "+str(datetime.now().year - formdata.field("age")+ ", right? </p>"))

I know you brought this up originally and all, but IMO if you're concatenating text strings to get your HTML, you're missing the point of why you might want to separate them. Text and HTML fragments are different types from a conceptual perspective; the suggestion is to make it easier to treat them as such. (Just like LINQ treats "text" and "query" as different types.)

Now, it seems that your original idea is to allow yourself to write a full program that displays multiple pages to the user, instead of a bunch of little programs. That's quite different, and in some sense a pretty cool idea. I'm not sure if I know of any languages or libraries that support that directly.. though it sounds vaguely familiar. Maybe something like that is something worked into Arc or something.

Alternatively you could do the opposite and just use GTK with Javascript.

That sounds like a match made in Hell. ;-)

userxp
Posts: 436
Joined: Thu Jul 09, 2009 12:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby userxp » Thu Aug 11, 2011 9:29 pm UTC

EvanED wrote:
userxp wrote:I think it'd be easy to implement in Python without having to modify the core of the language, just adding a few classes and functions:

Code: Select all

showPage(HTML("<p>Hello, "+formdata.field("name")+" you were born in "+str(datetime.now().year - formdata.field("age")+ ", right? </p>"))

I know you brought this up originally and all, but IMO if you're concatenating text strings to get your HTML, you're missing the point of why you might want to separate them. Text and HTML fragments are different types from a conceptual perspective; the suggestion is to make it easier to treat them as such. (Just like LINQ treats "text" and "query" as different types.)


Hmm, I don't see it. Before you can create an HTML fragment, you necessarily have to have it as a string (in Python at least). Isn't the easiest way to generate the result you want to output first, and then convert into HTML? You mean I should have done something like this?

Code: Select all

resultText = "Hello, "+formdata.field("name")+" you were born in "+str(datetime.now().year - formdata.field("age")+ ", right?"
page = HTML("")
textNode=page.createTextNode(result)  #I don't know much HTML DOM, but it seems that you have to create a text node before you can append it.
page.getElementsByTagName("p")[0].appendChild(textNode)
showPage(page)


Or you mean I should not use strings to represent HTML? Because that's why I suggested you could use {whatever} instead of HTML("whatever"), so it wouldn't look like a string, even though internally it would be one. But now I realize that there would be no way to tell variables and functions apart from text...

Or should we "Pythonize" the HTML?

Code: Select all

page = body(h1("This is the header"), p("hello "+ name + "!"))

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

Re: Coding: Fleeting Thoughts

Postby EvanED » Fri Aug 12, 2011 4:18 am UTC

userxp wrote:Hmm, I don't see it. Before you can create an HTML fragment, you necessarily have to have it as a string (in Python at least). Isn't the easiest way to generate the result you want to output first, and then convert into HTML? You mean I should have done something like this?

Or you can create it through the DOM. But that's sort of beside the point... we're not talking about any specific language, were're talking about a hypothetical language. You're the one who said "if I were to create a new programming language"... and there's nothing to prevent you from having "HTML literals" (or general XML literals, as in Anonymously Famous's VB.net example) in such a case.

So it's not "you should have done this", it's "I'm talking about what could be done in a hypothetical language".

Or should we "Pythonize" the HTML?

Code: Select all

page = body(h1("This is the header"), p("hello "+ name + "!"))

That would be one way...

If I was doing any programming where I wanted to store HTML fragments in variables, that's how I'd do it -- even if I had to write that library.

User avatar
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Fri Aug 12, 2011 4:53 am UTC

EvanED wrote:If I was doing any programming where I wanted to store HTML fragments in variables, that's how I'd do it -- even if I had to write that library.


I actually already have that library... it's a single-file python library we've used internally for a few projects at my work; we call it taglib. It's pretty simple - positional arguments are inserted as inner text for the element; keyword arguments become attributes for the tags (keyword argument names that end in underscores automatically have them removed - that way you can pass things like classes [since 'class' is a reserved word in python, so you'd do p(class_="foo") instead].).
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!

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

Re: Coding: Fleeting Thoughts

Postby EvanED » Fri Aug 12, 2011 5:09 am UTC

Aaeriele wrote:
EvanED wrote:If I was doing any programming where I wanted to store HTML fragments in variables, that's how I'd do it -- even if I had to write that library.


I actually already have that library... it's a single-file python library we've used internally for a few projects at my work; we call it taglib. It's pretty simple - positional arguments are inserted as inner text for the element; keyword arguments become attributes for the tags (keyword argument names that end in underscores automatically have them removed - that way you can pass things like classes [since 'class' is a reserved word in python, so you'd do p(class_="foo") instead].).

What I think would be really cool is to automatically generate a library like that from a schema. You could have runtime checks in a language like Python, which is kind of neat, but you could have compile-time checks if you have types, which is even cooler.

The DTD language is actually pretty simple, so it seems quite realistic to do it with that.

userxp
Posts: 436
Joined: Thu Jul 09, 2009 12:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby userxp » Fri Aug 12, 2011 12:58 pm UTC

EvanED wrote:Or you can create it through the DOM. But that's sort of beside the point... we're not talking about any specific language, were're talking about a hypothetical language. You're the one who said "if I were to create a new programming language"... and there's nothing to prevent you from having "HTML literals" (or general XML literals, as in Anonymously Famous's VB.net example) in such a case.

So it's not "you should have done this", it's "I'm talking about what could be done in a hypothetical language".

True, sorry, my mind just shifted to thinking about how it could be implemented in Python.

User avatar
cemper93
Posts: 209
Joined: Sun Feb 20, 2011 2:35 pm UTC
Location: `pwd`

Re: Coding: Fleeting Thoughts

Postby cemper93 » Fri Aug 12, 2011 9:28 pm UTC

Code: Select all

def initely(there, were):
    if not None:
        atLeast = not "many"
    who.made("my heart")
    "beat as", you.do(_,_)
    return your.smile
warm = "ly"

try:
    toKeep = "it" + warm
    while walkingHome: pass
    ing(emptyWindows)
except:ionally = "sad"
finally: it = "'s over"

your = not any([1, "to me"]) or "just my toy" and \
type("",(), {"youWere": "more"} )()

your.smile = "kept me"
_ = warm in "these days"

but, you = "were failed by", your #love: me

if _: only(I)
hadKnown, you.were = "innocent as a", lambda \
young, blueEyed: \
[("but ", "the retribution") for myMisdoings #comes
in "time"]

sometimes, you.do = ("make me", #think of who
you.were)
""in "another story"

I, who = "I've been", your#'s
"sit" in "my room"
"look"in"g at" #old photographs
#relentlessly remembering
the, love = you.do, "give to me"
who.made = all #these mistakes

"Had thought" + it + "would go"
on = "inf"+initely(
"Oh!, the", "fool I've") #been
regretting = all("my errors") #today

love, is_ = the, "thing I" #miss forever
iTake = "my camera"
go = "out to have"
new, photos = "to look", _ #at

print ("them" if _ #they're dull
else "they make" + "me think of" + love("lost"))

It was supposed to give the message: TypeError: love() takes exactly 2 arguments (1 given), but it didn't work because love is an anonymous function and the error message won't print the name :(

And if someone notices that I crossposted this from Stackexchange Codegolf: Yes, I did, because the SE question went to the 2nd page so rapidly noone could have possibly read my answer, which is also why this remark is pointless, because consequently noone could have possibly noticed that I crossposted this from Stackexchange Codegolf.

This is a literary thread now.

User avatar
MHD
Posts: 630
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Re: Coding: Fleeting Thoughts

Postby MHD » Mon Aug 15, 2011 8:46 pm UTC

Making a good syntax for macro definition in C-likes is haaaaaaaaaaaard.

(The syntax in this language idea is Cobra and Google Go's illegitimate child.)

I have been thinking of adding compile time pragma-comments and maybe having a separate meta language for defining them.
The idea is basically to be able to define ones own code-blocks like this:

Code: Select all

myForLoop(var, low, high):
    var is declaration
    low is number, high is number
    code:
        var
        var.name = low
        loop:
            if var.name > high: break
            block
            var.name++


and then the code would look like:

Code: Select all

mForLoop var x, 1, 6:
    print(x)

and generate:

Code: Select all

var x
x = 1
loop:
    if x > 6: break
    print(x)


But that syntax is bullshit and full of conceptual holes and inconsistencies with the actual language.
AAARGH
EvanED wrote:be aware that when most people say "regular expression" they really mean "something that is almost, but not quite, entirely unlike a regular expression"

User avatar
Xanthir
My HERO!!!
Posts: 5413
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Tue Aug 16, 2011 12:10 am UTC

Switch to a homo-iconic language, and use the language as its own macro-language.

Then realize you've just built another Lisp-family language.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Tue Aug 16, 2011 6:33 am UTC

FT: Turns out my matrix template isn't as messed up as I thought it was. My scene graph, on the other hand...

Code: Select all

    void
    Object
::set_rotation(VectorP rotation)
    {
      this->matrix.set_position(rotation);
    } 
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
RoadieRich
The Black Hand
Posts: 1037
Joined: Tue Feb 12, 2008 11:40 am UTC
Location: Behind you

Re: Coding: Fleeting Thoughts

Postby RoadieRich » Tue Aug 16, 2011 6:27 pm UTC

73, de KE8BSL loc EN26.

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

Re: Coding: Fleeting Thoughts

Postby EvanED » Tue Aug 16, 2011 8:39 pm UTC

How can I make the unicode → symbol appear not at the baseline (in HTML)? Or is it just a font issue?

Anonymously Famous
Posts: 242
Joined: Thu Nov 18, 2010 4:01 am UTC

Re: Coding: Fleeting Thoughts

Postby Anonymously Famous » Tue Aug 16, 2011 9:12 pm UTC

EvanED wrote:How can I make the unicode → symbol appear not at the baseline (in HTML)? Or is it just a font issue?

Do you have an example or a bit of the HTML code? Or a screenshot?

Edit: If it helps, this is your question in HTML, as seen in my browser's "View Source" option:

Code: Select all

<div class="content">How can I make the unicode → symbol appear not at the baseline (in HTML)? Or is it just a font issue?</div>

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Tue Aug 16, 2011 9:22 pm UTC

EvanED wrote:How can I make the unicode → symbol appear not at the baseline (in HTML)? Or is it just a font issue?


HTML shouldn't be meddling with font rendering, so it's your font. That said, the end of the arrow does seem to be a couple pixels above the baseline on my computer. You might want to use SVG if you want better control over that.
In Minecraft, I use the username Rirez.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Tue Aug 16, 2011 9:32 pm UTC

Steax wrote:
EvanED wrote:How can I make the unicode → symbol appear not at the baseline (in HTML)? Or is it just a font issue?


HTML shouldn't be meddling with font rendering, so it's your font. That said, the end of the arrow does seem to be a couple pixels above the baseline on my computer. You might want to use SVG if you want better control over that.

Or include a font with the page that you know works. Google will know more about embedding fonts and what quirks it has in each browser.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

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

Re: Coding: Fleeting Thoughts

Postby EvanED » Tue Aug 16, 2011 9:36 pm UTC

Hmm, looks like it is something fontwise. Chrome renders it basically at the baseline; Firefox shows it much closer to the "right" place, even on the same computer. I'll put that on my list of things to do and experiment with font choices in a while.

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

Re: Coding: Fleeting Thoughts

Postby phlip » Wed Aug 17, 2011 7:13 am UTC

For the record, for me, in both Fx and Chrome, in Linux, with the fonts I have installed... in EvanED's post it appears in a reasonable position, vertically lined up with the horizontal part of the "e" in the word "unicode" it's right next to. However, in the code block in Anon's post, it's on the baseline, again in both. I suspect because the monospace font I'm using doesn't have that symbol, so it has to pull it from another font, and mixing and matching fonts rarely works right.

Code: Select all

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

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? » Wed Aug 17, 2011 9:15 am UTC

In windows 7 firefox, I get a single pixel offset on some font sizes.

Image
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

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

Re: Coding: Fleeting Thoughts

Postby EvanED » Wed Aug 17, 2011 4:41 pm UTC

phlip wrote:For the record, for me, in both Fx and Chrome, in Linux, with the fonts I have installed... in EvanED's post it appears in a reasonable position, vertically lined up with the horizontal part of the "e" in the word "unicode" it's right next to. However, in the code block in Anon's post, it's on the baseline, again in both. I suspect because the monospace font I'm using doesn't have that symbol, so it has to pull it from another font, and mixing and matching fonts rarely works right.

That's a reasonable guess. It shows up for me on the baseline in both cases; here's the one in proportional fonts:

Image Image

The monospace version is basically the same. (This is in Chrome in an old, old Linux.)

User avatar
Xanthir
My HERO!!!
Posts: 5413
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Wed Aug 17, 2011 5:15 pm UTC

It is entirely a property of the font in question. Where a glyph is placed, relative to the baseline, is specified in the font's data for that character. Switch to a different font until you find one with a good answer. Try the Google Webfonts Directory if you want a bunch of free fonts to use on the web.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: Coding: Fleeting Thoughts

Postby Cosmologicon » Wed Aug 17, 2011 5:27 pm UTC

Xanthir wrote:Try the Google Webfonts Directory if you want a bunch of free fonts to use on the web.

I browsed through the first 100 or so fonts that came up and I didn't see a single one that rendered the → symbol. It showed up as a gray x. Is there some way to filter on fonts that support symbols like that? Or am I doing it wrong? I just tried pasting the → into the Preview Text box.

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 Aug 18, 2011 5:42 pm UTC

So I got called in for a programming-related job interview next week. Do you programming guys have any tips? Emphasis will apparently be on my C++ and Java skills.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Dason
Posts: 1311
Joined: Wed Dec 02, 2009 7:06 am UTC
Location: ~/

Re: Coding: Fleeting Thoughts

Postby Dason » Thu Aug 18, 2011 5:51 pm UTC

Make a web page for them to view. Make sure you use lots of frames, marquees, and blinking text (and background music!)

Read this as: No... I don't really have anything valuable to say.
double epsilon = -.0000001;

Anonymously Famous
Posts: 242
Joined: Thu Nov 18, 2010 4:01 am UTC

Re: Coding: Fleeting Thoughts

Postby Anonymously Famous » Thu Aug 18, 2011 6:26 pm UTC

I have no advice other than "Brush up on your C++ and Java skills."

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Fri Aug 19, 2011 3:33 am UTC

A good idea I've found is to catch up on the latest news on the subjects they'll interview with, even if they're not very relevant (at least know what they are). If your interviewer is savvy enough, they might casually toss out some questions about your opinions/thoughts on stuff. It's better to say "yeah, I've heard about them, I think..." rather than give a blank expression. I've had this happen to me practically every time I sit down with a serious (savvy) client.

Programming wise, know the current best practices and trends. I don't really know what those are for C++/Java though.
In Minecraft, I use the username Rirez.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 16 guests