|
edited out
Hammerite fucked around with this message at 20:22 on Jan 7, 2009 |
# ¿ Jan 7, 2009 19:46 |
|
|
# ¿ May 4, 2024 06:29 |
|
I know that many languages have first-class functions. What scripting languages have first-class types, in the sense that a function can return a type? So for example a function can return the type integer. (which is not nearly the same thing as returning an integer.) Example: suppose a scripting language allows you to use decimal types to carry out calculations to arbitrary (but obviously, finite) numbers of decimal places. So you might have a function decimal() taking one argument that returns a type representing decimals accurate to the number of decimal places represented by the argument. Then if I wanted to calculate the square root of 2 correct to 50 decimal places, I might write something like decimal(50)::sqrt(2); in which :: is meant to be the static member operator, with sqrt() being a static method of the type returned by decimal(). Are there any scripting languages that exhibit behaviour resembling what I describe? Or am I describing something that cannot work? (I say scripting language because I have in mind that this should be something that works through dynamic typing, which is something I perceive to be characteristic of scripting languages.) Hammerite fucked around with this message at 11:11 on Aug 9, 2011 |
# ¿ Aug 9, 2011 11:09 |
|
tef posted:Python OK, further question. A brief search shows that in Python, when you want to declare a function f you do so by writing code:
code:
code:
A similar consideration applies to declaring classes. Instead of writing code:
code:
|
# ¿ Aug 9, 2011 11:49 |
|
tef posted:MY CONSISTENCY This, but unironically. tef posted:python eschews anonymous definitions -- ask yourself how you would do this in a language without braces. I can't answer that question other than by noting that it can be interpreted as an argument in favour of braces.
|
# ¿ Aug 9, 2011 14:04 |
|
TasteMyHouse posted:A foolish consistency is the hobgoblin of little minds What this quote really says (to me, at least) is that if you have a good reason to be inconsistent then you should go ahead and be inconsistent. It seems to me that it's your job to show that there's good reason for inconsistency here. Or to put it another way, it's up to you to show that the consistency I am arguing for is indeed foolish.
|
# ¿ Aug 9, 2011 19:21 |
|
Perhaps I shall learn Lisp. It sounds enlightening.
|
# ¿ Aug 9, 2011 22:01 |
|
rolleyes posted:I refuse to get involved in cryptic messages when the author can't even manage to spell 'potato'. it looks like it is a cropped screenshot in which case the word may have been "potatoes"?
|
# ¿ Aug 21, 2011 20:26 |
|
I know that in languages with strict typing, you typically have to declare the types of all the parameters to a function, as well as the type of the return value. Like in C you might have int myfunction (int a, float b); (I may have made a syntax error somewhere, it's not crucial to the post.) Aside from maybe being necessary for low-level languages to work properly, this has the nice property that you've made a declaration to some extent of what properties you want your function's arguments to satisfy, which makes your job easier. In some dynamic languages (PHP I'm looking at you) you cannot declare that you want an argument to be an integer, so you either have to do some kind of check in the function, or throw your hands up and say gently caress it, I'm just going to assume whenever this function gets called it is by somebody who isn't retarded. Maybe that isn't so bad but it is kind of unsatisfying. But it seems like the capability of saying what type you want the argument to be is not going far enough. I should be able to say that I want the argument to be not just an integer, but an odd integer greater than 10, or that I want the return value not just to be a string, but that I want it to be a string precisely 8 characters in length. Seems to me the easiest way to achieve that is by saying: when you define your function, for each argument you should supply not a type, but a predicate that you want to return true or else the function has been called incorrectly and an error should occur. For convenience, names of types should also be usable as predicates that take a single argument and return true or false according as the argument is of the appropriate type. So something like the following should be doable (syntax is made up; assume that nonnegativeInteger is a predicate that already exists and behaves in the obvious way): code:
Tell me languages that behave in a similar way to what I just described.
|
# ¿ Sep 2, 2011 22:39 |
|
baquerd posted:
Just a quick note on this: The correct way to do associative arrays in JavaScript is using objects, not arrays. Reference
|
# ¿ Oct 12, 2011 19:21 |
|
GrumpyDoctor posted:I have a collection that includes points, lines, and planes (in 3-dimensional space). If I want to do neighbor queries on points (nearest neighbor, nearest k neighbors, whatever) I can use a k-d tree. Is there any technique for if I want to include the lines and the planes in the queries as well? i.e. "find me all the points, lines, and planes within an epsilon of this given point" If you have a point p and a line l then there is a unique point p2 on l that is closest to p. You could just calculate the distance between p and p2, which is then the same as the distance between p and l. The analogous statement also holds for a point and a plane. In the case where you have a point p and a plane q you calculate the normal l to q passing through p; the point p2 is the intersection of l with q. In the case where you have a point p and a line l, you express the line in terms of a parameter (t, say), and then express the square-distance s from p to a point on l in terms of t. Then you find the minimum value of ds/dt and calculate its square root to get the distance from p to l (you can also calculate the point p2 at this point, but you don't actually need to). If this is too inefficient an approach or otherwise impractical then don't mind me, I'm a programming novice.
|
# ¿ Dec 7, 2011 15:35 |
|
Mr.Hotkeys posted:Create every possible square where each row contains one of each number and then run over the results and cull out the invalid ones? I'm sure someone'll come in with some beautiful way to do it but honestly that just sounds like the easiest way to me, though I don't know if that's C or C++. Would probably use a huge amount of memory even for not very large n. Two observations: 1) You can fix the first row of the square, find all magic squares (let's say there are k of them) with that first row, and then generate the remaining squares by applying permutations of the integers 0 through n - 1. (This gives you n! × k squares in total.) 2) To generate those magic squares in the first place, you could take the approach of generating a tree of height n by filling in rows one by one, filtering out partial squares that have already failed to satisfy the requirement of having each number appear at most once in each column. Here is a partial illustration in the case n = 4:
|
# ¿ Jan 20, 2012 12:06 |
|
shrughes posted:FYI These are not magic squares. Oh yeah, I don't know what happened there. I was talking about Latin squares but saying "magic squares".
|
# ¿ Jan 20, 2012 12:20 |
|
Been doing some work in Maple the last few days. Maple has a thing I haven't seen elsewhere, where you can define "sequences" (comma-separated lists of Maple values) and assign a sequence to a variable. So you can writecode:
code:
Is there a name for this kind of behaviour?
|
# ¿ Jan 20, 2012 21:12 |
|
The way you do certain things in Maple is... idiosyncratic. It is entertaining from time to time. As well as sequences (comma-separated lists of values) you also have lists, which are sequences encased in a set of square brackets; and sets, which are sequences encased in a set of braces. So you can have code:
There is no built-in function to append an element to a list. You can do that as follows: code:
|
# ¿ Jan 21, 2012 00:09 |
|
The only web scripting language I know is PHP. PHP has a great many flaws, and I should like to learn another web scripting language. Probably Python or Ruby. There is one thing that keeps me from getting comfortable with the way other languages do things, though. When I invoke a PHP script I know exactly what is happening. PHP starts at the top of the script and executes the contents, in order, until it reaches the end of the script. I have seen forums poster tef refer to this as "CGI-style" scripting (or maybe I have misunderstood terms, but that is how I perceived it). This does not seem to be the way that other web scripting languages work, perhaps with the exception of Perl. They seem to typically involve installing things (you need to install such-and-such a "gem"...), declaring things (tell some program to start listening to requests or dealing with them using a specific workflow), configuring toolsets (for example, a templating engine) that are to be pieced together to form the backbone of the application, choosing the way something should communicate with a web server (python.org's introductory page on "how to use Python in the web" is mostly a load of incomprehensible bullshit about different methods for hooking Python code up to a webserver - what if I just want to write a script?), starting and stopping processes (why can't a request to a given script just invoke the necessary interpreter which then does its thing, like in PHP?), who knows what else. Please offer tips on how I can become more comfortable with these other web scripting languages' ways of approaching scripting. nb. I have shared web hosting, but I do not have shell access or any of that good stuff. I could spring for a cheap VPS, but it seems like it should not be necessary to do that just in order to do some tinkering.
|
# ¿ Apr 10, 2012 08:00 |
|
Look Around You posted:Most modern web frameworks use a Model-View-Controller (MVC) pattern. The three parts are as follows: a "Model", which contains the representation of the data and the rules for manipulating it, a "View" for displaying it to the user, and a "Controller" that decides what needs to be done and how to do it, basically mediating between the Model and the VIew. Thanks. In your estimation, how much extra hassle would it be to learn django using only shared hosting with no command line access, as opposed to getting a cheap VPS? edit: Also if I should get out and ask questions in the dedicated language megathreads instead, tell me. Hammerite fucked around with this message at 12:32 on Apr 10, 2012 |
# ¿ Apr 10, 2012 12:28 |
|
gwar3k1 posted:Thanks, I added a wait function (from a google hit) and changed my do a bit, but the performance is poo poo. I am not sure you understand how setting timeouts works. If you want to set something up to happen in 5 seconds, say, then you create a timeout using setTimeout (specifying a time of 5000 milliseconds) and then you allow your function (the function in which you used setTimeout) to run to completion. When the timeout has run its course, your function will get called, spontaneously, by the JavaScript engine. If you want a nice-looking, smooth animation on the other hand, I think it's easiest to use what jQuery offers you. I made this thing last year for an event I was involved in, it is more complex than is needed for an example but you might find it interesting to look at.
|
# ¿ Apr 19, 2012 23:08 |
|
gwar3k1 posted:Thanks! So are you effectively queuing up animation functions with doTimeout and incrementing animationStep? The timeoutHandler executes the necessary code after each timeout delay, but the original code from the button press has already completed. Yes. Depending on what stage in the animation the document is in. It's a while since I wrote it, but basically timeoutHandler() is the function that controls the state of the document and makes sure that things happen "in the right order". I just realised (and I don't know why I didn't realise it before, I'm honestly not trying to show off) that I actually have a much simpler example of the use of timeouts, that would have been much more appropriate to link you to: (albeit "intervals" rather than "timeouts") http://orderofthehammer.com/redirect.js This allows the creation of a page that redirects the user after a countdown. Every second the counter in the page body text and the counter in the page title are decremented, and when they reach zero a thing happens. redirect_begin() is supposed to be called once the page loads. See how the last thing that happens is that it calls setInterval(), and then it gives up control to the JavaScript engine. The JavaScript engine does its job and calls redirect_countdown() every second afterwards, until it is told to stop by code in the conditional block within redirect_countdown().
|
# ¿ Apr 21, 2012 17:20 |
|
What is a good strategy for creating tests for pieces of software that you have written? I created a script to test out the functionality of a small piece of software I wrote for my own use. In the process of writing and running the tests I actually found and fixed a few bugs that I did not know were in the code, as well as making one or two tweaks to functionality. This of course is quite gratifying, because it means that the code is closer to being free of bugs and that the time spent doing the testing has paid off, but the tests (now all passing) are just what I thought up, just a few experiments that seek to test that various possible eventualities are handled correctly. What if there are still loads of bugs I didn't think of?
|
# ¿ Apr 21, 2012 19:51 |
|
yaoi prophet posted:If you just want to test a single function, fuzz testing can be good. Like, if you want to test a sort() function, generate random lists, run them through sort(), and verify that they're sorted. It's a class. Although I made it for my own use, I uploaded it here.
|
# ¿ Apr 21, 2012 23:23 |
|
LittleBob posted:I'm probably being retarded, but how can I rename a set of files, keeping just the first three characters and deleting everything else? I don't know how to answer your question. But you have considered the possibility that the truncated names will include duplicates, right? For example two files might be named readme.txt and really-big-wieners.jpg. You might need to be more clear what you want to happen if a duplicate filename arises (do you want to destructively overwrite the old file, or...?)
|
# ¿ Apr 23, 2012 17:40 |
|
MEAT TREAT posted:
Yes, get the database to help you where it can. Use uniqueness constraints. Use foreign keys. Use transactions. If you are using MySQL, put it in traditional mode.
|
# ¿ Apr 23, 2012 21:28 |
|
Shaocaholica posted:So someone at work asked me if saving a jpeg over and over will introduce compounding compression artifacts and I said 'yes' without really thinking. I then decided to do a test where I open an image, save out at 50% jpeg quality, reopen the new image and save out a new copy with 50% quality so on and so forth for a few hundred iterations. I played the image sequence in motion and after the initial pop in quality from the original image to the first 50% quality image the artifacting didn't change at all for the hundreds of frames that followed. Is this normal for jpeg algorithms? Wiki says: "JPEG is also not well suited to files that will undergo multiple edits, as some image quality will usually be lost each time the image is decompressed and recompressed, particularly if the image is cropped or shifted, or if encoding parameters are changed – see digital generation loss for details. To avoid this..." Are you sure your procedure "decompressed and then recompressed" the JPEG after the first pass (in which you reduced the quality)? I am pretty sure that if you make actual changes to a JPEG, re-saving it as JPEG each time, the quality will get progressively worse.
|
# ¿ Apr 24, 2012 01:14 |
|
Where is a comment permitted in an HTML page? Can I have one before <html>? After </html>?
|
# ¿ Apr 26, 2012 22:07 |
|
Suppose I want to build a structure that looks like this: The top-level object is a list of objects, each of which can be either an atomic object or itself a list. The structure is meant to be operated upon by "workers" which can move backwards and forwards along lists, climb upwards (if they are not at the top level) and climb downwards (if the object they are positioned at is a sublist). If they climb upwards, they will then be pointing at the same list item that they were pointing at before they descended. Workers can insert elements in the list. Multiple workers may be operating on the same list. Each list has no reference to its parent element; so a particular list can be inserted by value or by reference in multiple locations (and manipulating the list in one of these locations causes the changes to be made everywhere else that a reference has been placed to the same list). Workers can create workers "constrained" to act within the current list (so the newly produced worker regards the current level as being the top level, whereas it may not be the top level as far as the original worker was concerned). Inserting a list item in such a way as to form a cycle might or might not be allowed. Or maybe when a sublist is inserted it should be marked as "unsafe" until a check has been made for cycles, or something. If deletion of list items is allowed, then deleting sublists might be problematic, because another worker might be working inside that sublist, and then it is not clear what should happen. Does a structure like this have a name?
|
# ¿ May 15, 2012 19:45 |
|
In the current version of my web app, users can select a set of pronouns they would like to be referred to by. They can elect to be referred to by "he", "she", or "it". I'm considering whether to maintain this in a future iteration of the app. I was considering adding the option of being referred to by "they". But I also allow translation into other languages, and other languages might have totally different sets of pronouns and so it might be impossible to translate the connotations behind one or more sets of pronouns, resulting in inferior translation. I'm not sure whether to just drop the option to select a set of pronouns entirely, and have everybody just referred to as "they" where necessary. I guess this is what most people would do? Obviously this is an aesthetic consideration and difficult to justify spending much time on.
|
# ¿ Jun 1, 2012 13:55 |
|
rjmccall posted:Localizing gender is a pain. So is not enforcing cisnormativity. Go with gender-neutral or be prepared for a long tail of work. I was considering in the choice selection, making the connotations of each set explicit. as in code:
The way I see it it's a nice thing to do to let people select the way they would like to be referred to, within reason. I don't care about cisnomativity or any stupid poo poo like that, if anyone bothers me with nonsense I'm happy to tell them to go screw themselves.
|
# ¿ Jun 1, 2012 19:30 |
|
yaoi prophet posted:
I figure asking them "what sex/what gender are you?" would be a far worse can of worms than merely asking them how they would like to be referred to. Not to mention people are more likely (I would assume) to see asking them "are you male or female" as a request for irrelevant information and so impertinent. Don't get me wrong, I do see that some languages might have arbitrarily different pronoun conventions than European languages. For languages where the "them, he, she, it" model is insufficient, it can fall back to use of gender-neutral text everywhere. That has the problem that users using those languages might not see the need to provide information that doesn't apply to how they view the website anyhow. So it should default to the "they" option. At the end of the day it is a primarily English-language web app by necessity because I am running it and I am English-speaking. Various issues might arise when attempt to facilitate translation, I'm not convinced that that's a reason to avoid offering features. When a given feature just isn't compatible with a certain language, shouldn't the thing "gracefully degrade"? That's a popular notion iirc. But all this said, I'm not really convinced it isn't all too much work to be worth it.
|
# ¿ Jun 2, 2012 11:00 |
|
rolleyes posted:Speaking as someone working for a company which offers our UIs in multiple languages (including non-latin ones) you really don't want to get into this if you don't have the resources to do a good job of it. We send our text to external translation companies and even they don't always get it exactly right, especially when going to logographic languages like Kanji which can be extremely subjective and context sensitive. My current implementation does take a "whole sentence" approach as you suggest. Does it ever work to write something like: ":subject-pronoun: updated :possessive-pronoun: account on:" I am aware, before you say anything, that in many languages a possessive pronoun (say) has to agree with the noun. So there might be different pronouns for masculine, feminine and neuter nouns and they might also vary according to whether the noun is pluralised. So in some language it might look more like ":subject-pronoun: updated :possessive-pronoun-masculine-singular: account on:" On the other hand, if a language isn't supported to that extent because it's just so alien OMG then it might end up as a sentence with no :...: placeholders at all, because there are no parameters to change.
|
# ¿ Jun 2, 2012 12:12 |
|
Well, it's been useful to explore the idea. I think I've heard enough to convince me to drop the feature and use uniformly gender-neutral phrasing for now. It's not like I couldn't add the feature in at a future date, defaulting to "they" for users already existing at that time. Incidentally, has there ever been a thread in CoC regarding internationalisation/localisation topics?
|
# ¿ Jun 2, 2012 13:41 |
|
When you have a website that requires login with username and password, what's the correct way to defeat repeated attempts to log in to an account by trying different passwords? You could lock a user's account for a fixed amount of time when a certain number of failed attempts have been made to log in - say when 3 failed attempts have been made within 15 minutes. But if you do this then one user could grief another by getting them locked out of their account. Alternatively, you could lock out users from a particular IP address from logging in if a certain number of failed attempts are made from that IP address. But a knowledgeable user can acquire a different IP address and carry on, so this wouldn't stop an attacker, would it? Or am I mistaken in thinking that users can rapidly change IP addresses? I guess that if several attempts were made to log in to a particular account from IP addresses not previously associated with that account, you could lock it down except for allowing logins from the IP addresses that have been used to successfully log in in the past. But some users might have frequently changing IP addresses through no fault of their own and then they would be out of luck. How do sites generally deal with this?
|
# ¿ Jun 11, 2012 01:16 |
|
Suppose you are creating a web application and you want users to be able to create accounts and choose usernames for them. You don't want to restrict the characters they can use without good reason, so you intend to allow any Unicode character unless there is a good reason not to allow it. What characters do you disallow, and how would you code a function to check whether a username is acceptable or not?
|
# ¿ Jun 17, 2012 22:26 |
|
nielsm posted:Go read a bit about Unicode normalisation forms, it's very relevant for things that have to not just be displayed but also compared and searched against. pseudorandom name posted:Also Unicode Character Classes, to filter out such things as U+1F4A9 PILE OF POO. Thanks, I find learning about Unicode to be actually very interesting, but it tends to seem very complex. As far as I'm understanding it you would probably want to make sure the user name was in NFC and then check that all the I see that there is also the option to be more "aggressive" about normalizing Unicode text by using NFKC, but I'm not sure when you might do that. I guess maybe you would use it to compare strings, but you would not necessarily store a string in NFKC, since you lose information by doing so?
|
# ¿ Jun 18, 2012 05:24 |
|
Zombywuf posted:http://www.regular-expressions.info/unicode.html will probably help. You probably want L, M, Zs and P (or maybe a subset). Normalisation I would leave up to whatever library I'm using to compare strings. Which I would then moan about if it didn't work. Would you say it would be reasonable to restrict to L, M, N, P, Zs and possibly some of S (for special snowflakes who enjoy having, erm, snowflakes in their name) but to apply additional rules, e.g. - remove Zs characters appearing at the start and end of the name (doesn't make sense for names to start or end with whitespace) - disallow M characters from appearing at the start of the name - require a minimum number of non-M, non-Zs characters
|
# ¿ Jun 18, 2012 11:43 |
|
Zombywuf posted:Well, it all depends on how far you're willing to bend to special snowflakes. There are times I've been tempted to change my name to something that has no valid normal form in unicode as a big gently caress you to the world. Trimming (and normalising) whitespace and disallowing combining chars where they don't belong is reasonable, however if you're allowing symbols you might as well allow as much punctuation as they want. I guess it depends on what the use case is if you want allow Zalgo usernames. Could you point me to an example or examples of Unicode strings that do not possess a normalisation form? What is the result of applying the normalisation algorithms to strings like that? Is there a collection anywhere of pathological examples of Unicode text? I hadn't considered the idea of letting users have separate login and display names (potentially with different restrictions applied). I guess that has its advantages and disadvantages. It also reached my attention that there are some category C characters that there might be reason to allow, such as ZERO WIDTH NON-JOINER Goat Bastard posted:The question I always ask myself when defining validation requirements is "what real problem am I trying to solve with this validation?". Although this is very reasonable and sensible advice, I am paying such inordinate attention to this in part because it is an opportunity for me to improve my understanding of Unicode and related topics.
|
# ¿ Jun 18, 2012 23:25 |
|
hayden. posted:Not sure if this is the best place for this, but does anyone have experience doing programming type jobs on Elance? I've been looking and applying to a few jobs for a few days now but it seems unlikely that I'll ever get hired since I don't have any work history on the site. Every listing also has about a dozen applicants from India or whatever and I have no idea if I could ever compete with them on a price basis. There's a recent thread about ELance and similar sites. It's partly ranting and partly advice iirc, you might find it interesting.
|
# ¿ Jun 24, 2012 17:07 |
|
Huragok posted:Which one of you bought this banner ad: "Come blog about apps and dev poo poo, my lord"
|
# ¿ Jul 2, 2012 12:10 |
|
Jose Cuervo posted:I am not sure if I can achieve what I want, so hopefully you all will be able to tell me if what I want to do is impossible. Yes, that is something that you could do reasonably straightforwardly with the scripting language of your choice. Do you have any experience using a scripting language like Python, Perl, Lua, etc etc.? I do not know how others would approach this (and I do not know anything about bibtex), but here is what I might do, assuming you do not want to go to the trouble of involving a relational database: - Make a master citations file with all of the citations in it, together with identifying names (for your use). You could do a citation on every line of the file, with name first then citation text separated by a tab. Or you could do it innumerable other ways. - If your papers are spread across a number of directories, then make another file that lists all of the directories to be searched and updated. - For each paper, make a file called something like "papername.mybib" that just has a list of the citations you want, identified by the name you used in the master citation file. - Now write your script. The script should read from the two master files. From the first one it builds up a list of identifiers and the citation text for each one. From the second one it reads a list of directories to search through. It goes through each directory in turn looking for .mybib files. For each one, it generates a .bib file. When reading the first master file, the script should be prepared to encounter blank lines and lines that are "comments" (say, lines starting with % or #), so that you can lay it out in a way that is pleasing and easy for you to read.
|
# ¿ Jul 3, 2012 21:42 |
|
stubblyhead posted:When you use POST as a html form submission method, what does the submitted document look like? Say your html page is like Someone will doubtless answer in more detail and/or fix inaccuracies in this, but something like the following: this assumes that the full URL to farts.php is your.subdomain.yoursite.com/path/to/farts.php, and that you entered "Some text about beans" in the text input, and submitted the form by clicking the submit button. code:
I am not sure whether a variable is sent for the submit button, because you didn't give it a name. I'm pretty sure that if you do give it a name, then it sends a variable for the submit button, and its value is the "value" attribute on the button (so in this case, "Toot") Bear in mind that anyone can craft any HTTP request they like (or even craft a malformed request) and send it to your script, so don't rely on requests looking the way they are supposed to look, and also there might be all sorts of different headers like a user-agent header, "accept" headers, etc. etc. Hammerite fucked around with this message at 23:31 on Aug 2, 2012 |
# ¿ Aug 2, 2012 23:26 |
|
|
# ¿ May 4, 2024 06:29 |
|
kedo posted:I'm trying to code the front end of a website running on Apache Wicket and it is horrible. According to the developers I'm working with, every time edits are made to the various page templates the only way to see the edits is for the server to grab the files from FTP, stick them into the system somehow, and then restart or reload the theme or something... frankly I have no idea. Here's what the developer said: I think most people will tell you more or less bluntly that you shouldn't be making live changes to the website you're working on, full stop. Ideally you would have a test or "development" version of the site that is convenient for testing changes out, where you can iron out any problems with changes you make rather than unintentionally causing problems on the live site. This could be local to your development machine or more of a centralised thing. But I am guessing there's little reason to make it easy and convenient to change the production site when in principle that's the final step in making any changes; frequent changes to test edits are what the development version would be for.
|
# ¿ Aug 15, 2012 23:33 |