It depends. If we're talking about someone's "sex" then I'd say their gentials. If we're talking about their gender then I think it could quite easily mean to be how they personally identify.
If I'm completely honest I am quite happy for people to identify however they like. I have no preference or agenda whatsoever. It's not something I give a huge amount of thought to really.
I just assume it's people not agreeing. The Leaf gets a bad rap, and a lot of hate. Nissan put a lot of great work into that car, and it doesn't get much recognition thanks to other developments in the recent years. They've been steadily increasing range (I think they're in the ~70mi range now), and have a much higher charging rate than others (Volt included, sadly).
If it wasn't for the guess-o-meter (range gauge) being so unreliable, and the degradation, I would have held on to my Leaf. But my range vehicle (an '08 Prius) was starting to need some more maintenance, and the Leaf became problematic if I needed to run any errands after work.
Toyota have traditionally built their reputation of quality by conservativly adopting new technology, especially when it comes to drivetrains.
I'm not aware of any Toyota vehicles sold in the U.K that have a turbocharger, except the Supra which shares the drivetrain, suspension, platform and some interior with the BMW Z4.
Heck, their Yaris GRMN uses the 1.8 supercharged engine that Toyota have been selling to Lotus for years.
I wonder how Toyota plan to transfer this to electric vehicles given how new the technology still is.
It's not only Toyota. I think this is an instance of you get what you measure. European car automakers jump into turbocharged engines, because it was easy to meet NDEC. Now WLTP makes it a way harder, hence mild hybridization.
I am bit thinking out loud, drive train becomes important if its a plug-in hybrid when you have to change from electric to gas (and vice-versa), but in electric it is meant to be simple, is drive train even an issue of innovation in Electric cars, after all there is only Drive and Reverse.
I would presume electric drive trains are quite complex.
You'd have independent electric motors on at least 2, perhaps all 4 wheels. You have to redesign entire platforms to fit batteries, ensure the batteries and the drivetrain have adequate cooling, ensure that the electric motors have a certain amount of longevity, and so on.
With the exception of a few niche vehicles, most EVs have only 1 (FWD/RWD) or 2 (AWD) motors. Though it's a new platform, electric motors aren't exactly a new technology and overall it's significantly fewer moving parts to fail. There's also the fact that many manufacturers come up with a single "skateboard" platform for multiple vehicles, which reduces the overall complexity of manufacturing EVs.
As far as I understand the current state of EVs, EVs have eliminated the engine and it's ancillaries.
However, EVs still have CV joints, differentials (dependent on the car, Tesla runs an open differential), independent suspension - all of which must be much stronger since electric motors produce far more torque than ICEs and also have the added weight penalty.
The power-train is everything from wheels to engine. Where as drive-train is the power-train minus the engine.
The transmission is the most complicated part of the drive-train and arguably more complicated than all of the other drive-train components combined. In current EVs there is no transmission, just a single reduction gearbox.
In an EV the engine is dramatically simplified compared to an ICE and there are significantly fewer parts and almost no moving parts in comparison.
Another thing to consider is that all internal combustion engines have multiple supplementary systems that are required to function such as cooling, fuel delivery, and ignition. At most an EV motor might require supplementary cooling but no commercial vehicle has one that I'm aware of.
Of course, ICE powertrains have lots of moving parts, but the comparison that EV cars are simple is just not an accurate representation of EV cars.
There are fewer moving parts, I agree. The architecture itself is simpler too, I agree. But the individual components are still massively complex and expensive. High density Lithion-ion is very complex, and also requires a number of supplementary systems to manage power, heat, cooling and monitor the array.
You could make the same argument about the exotic metallurgy used in ICE components. Just like with an ICE subsystem, most of those subsystems you mentioned aren't trade secrets and have far greater operating tolerances than in an ICE.
> I would presume electric drive trains are quite complex.
They're significantly less complicated than an ICE power-train and drive-train.
The Nissan Leaf has a single electric motor and a fixed reduction gear box. The only fluids to maintain are the wiper fluid and reduction gear box fluid, which is similar to automatic transmission fluid but requires less maintenance. The battery pack is air cooled and the only servicing is an annual inspection to maintain warranty.
The Tesla vehicles are all direct drive with no gearbox. They come in single or dual motor options. The batteries are cooled and the fluid is changed at 4 year intervals.
The maintenance schedule for an EV is annually changing the cabin filter, wiper blades, and doing a multi-point inspection.
>The Tesla vehicles are all direct drive with no gearbox.
This is wrong. They have a single electric motor (except the dual-motor ones) and a fixed reduction gear box, just like the Leaf. No one does direct-drive electric motors because it's a lot easier to make a faster-spinning motor and then use a reduction gear to get usable torque from it; a direct-drive motor would have to have a huge diameter.
>The maintenance schedule for an EV is annually changing the cabin filter, wiper blades, and doing a multi-point inspection.
You're forgetting the brakes. EVs still have regular hydraulic brake systems that need new pads and fluid, though not as much because they can use regenerative braking much of the time, avoiding use of the friction brakes, which are really for emergency stops and full stops.
You're right. I was mistaken, I thought I had read that the Roadster was the only Tesla with a gearbox but that it was eliminated with a free upgrade. There's still a gearbox but it's a fixed single reduction gear.
> You're forgetting the brakes.
I wasn't, I was touching on the differences between an EV and an ICE with regards to maintenance. Brakes are a consumable that are inspected and changed as needed rather than at regular interval like the belts or fluids in an ICE vehicle.
Brakes and brake fluid are part of the multi-point inspection that's done on all vehicles when they're serviced. As you pointed out, EVs use their brakes significantly less than ICE vehicles and so any maintenance of the brake system will be less frequent than an equivalent ICE vehicle.
Overall EVs require significantly less maintenance to their drive/power-train AND to some of their traditional systems (e.g. brakes).
I'd like to refute the point about brakes. A lot of it is based on the driver, not just the vehicle.
I've driven a manual all my life. I don't really enjoy automatics, and I've got to the point now where I've pretty much perfected rev matching and heel and toe so I can engine brake most of the time with minimal wear on my clutch and shock to my drive train.
To be perfectly honest, I don't think I wear my brakes any faster than if I drove an electric car. I'd love to do an experiment to see if this was the case, it sounds like as lot of fun!
However, I concede that most drivers are nowhere near as interested in the technicalities of driving and teaching learner drivers to rev match and heel and toe is probably too complex at that stage in their driving careers.
> However, I concede that most drivers are nowhere near as interested in the technicalities of driving and teaching learner drivers to rev match and heel and toe is probably too complex at that stage in their driving careers.
For every ICE driver like you, there are an equal number of EV drivers trying to optimize their driving habits as well. The difference between ICE and EV when it comes to brake wear is that it's an active effort for an ICE driver and passive for an EV driver.
The regenerative braking in an EV varies by make/model but the 1st gen. Nissan Leaf has by far the least aggressive system. With the Leaf, the brake engagement is based on a number of factors from how fast you're going to how hard you press on the brake. The Leaf will almost come to a complete halt simply by taking your foot off the accelerator and allowing the regen system to drag the car to a stop without ever depressing the brake. In stop-and-go traffic you rarely have to take your foot off the gas.
In the Leaf when you depress the brake pedal the regenerative system ramps up quickly and only after it has peaked do the mechanical brakes engage. When stopping it's not uncommon to hear the mechanical brakes engage just as the car comes to a rest to hold the car at a stand still, it's an audible thunk.
The Tesla Model 3's regenerative braking is quite aggressive compared to the Leaf and if you take your foot completely off the accelerator pedal you will lurch forward in your seat as the car quickly decelerates.
I personally find the Leaf to be a much easier, and a lot less fun, to drive than the Model 3 because of how the brake regen systems work. In my 2015 Leaf I can engage hill mode (aggressive regen) and eco mode (gummy pedal) and then only have to touch the brakes to come to a complete halt. I've yet to find a setting in the Model 3 that compares.
You should go test drive something like the Model 3 as it's a very different driving experience to an ICE in terms of braking.
>You should go test drive something like the Model 3 as it's a very different driving experience to an ICE in terms of braking.
You sound like you took one test drive of the Model 3 at one setting and have no idea that there are multiple settings. If you go through the menus, the aggressiveness of the regen braking is settable. You can make the car "creep" as if it has an automatic transmission, or you can make it not "creep", like cars with manual transmissions and clutches. You can set it for aggressive regen like a real EV, or you can set it for non-aggressive regen so it feels like driving a regular car with an auto trans.
The proper setting, IMO, is the full-EV mode with very aggressive regen. You're not supposed to use the accelerator as an accelerator, you're supposed to use it as a speed control pedal. So you don't take your foot off the pedal at all, unless you need to brake hard. The rest of the time, you keep your foot on the pedal and modulate it to control your speed. If that's a problem for you, it's because you learned bad driving habits with non-EV vehicles, and you need to learn better driving habits now.
Was this just an opportunity for you to insult me twice? Because you confirmed my claim that it's different by pointing out that it has settings to make it feel less different.
You made a claim about the car and how its regen braking works, implying that that was the only way it could work. You then said a different car had settings to change this, but you said nothing about the Model 3's settings, which in fact, let you change this thing that you're complaining about.
You make it very hard to discuss anything because you're aggressively looking for flaws in people's comments that you can object to (i.e. you like to argue) which intern means people are less likely to invest effort in responding because we're hear to have friendly discussions.
> implying that that was the only way it could work.
You're interpreting it how you want to and not taking what's being said in the context it's given.
The comment I was responding to remarked that they used engine braking as a means of reducing brake wear. They acknowledged to have never driven an EV and I was pointing out that by default an EV exhibits a behavior (i.e. regenerative braking) that is similar and, unlike engine braking, is not something you consciously have to perform. It's on by default.
You swoop in to tell me how I'm wrong (which I'm not) and that I'm complaining (which I wasn't).
> the Model 3's settings, which in fact, let you change this thing that you're complaining about.
First, I wasn't complaining about it at all, go back and reread what I said.
> I personally find the Leaf to be ... a lot less fun, to drive...
With both cars you have to keep constant pressure on the accelerator to coast, however the Model 3 requires you to maintain greater pressure which leads to fatigue faster (i.e. less fun). In the Leaf you can set Regenerative Braking to Normal and disable Eco Mode, which increases throttle response and reduces pedal weight, which allows you to coast at highway speeds with minimal pedal pressure. The Model 3's equivalent settings (i.e. Acceleration = Standard, Regenerative Braking = Low) require much more pedal pressure to coast at highway speeds.
Second, even when you set Regenerative Braking to Low in the Tesla, it is still not like driving an ICE vehicle. The Model 3's least aggressive Regenerative Braking setting is so aggressive that if you completely remove your foot from the accelerator it automatically illuminates your brake lights. Unless you're driving in a manual transmission vehicle and you downshift, you will never experience that kind of tug.
So no, in fact, you cannot change the settings in the Model 3 to be comparable to a conventional ICE vehicle. At best you can get a behavior that's akin to driving a manual transmission vehicle aggressively.
Again, I'm not complaining about the Model 3 or any EV.
I would love to, I'm not sure we will have the Model 3 in the U.K for quite some time still. I'll give it a go when they're available and hopefully report back on a future article!
Yes, you're wrong. Go back and read the line you wrote (I quoted it for you in the previous post). You said brakes are a consumable, and you kinda implied that EV brakes don't even have fluid(!). Now you're admitting that it does need to be changed, which is exactly what I pointed out you were wrong about. This isn't "pedantry", it's a pretty major operation that has to be done regularly (as you said, roughly every 3 years for most cars I think; brake systems are all about the same these days and use the same fluids. My Mazda has a very similar requirement as those you mentioned.) It's not a hard job, but it does take some time and shop labor is expensive so it's not an especially cheap job.
>The brake system on an Electric Vehicle will require the same or less maintenance than an equivalent Internal Combustion Engine vehicle.
This is correct. You don't need to change the pads/rotors nearly as often, but the fluid still needs maintenance.
>And Electric Vehicle will require less maintenance overall compared to the equivalent Internal Combustion Engine vehicle.
Yes, of course, I never said otherwise. But it's important to remember that "less maintenance" doesn't equal "no maintenance". A lot of the systems on an EV are the same as current cars, and maintenance/repair will be little different: wheels/tires/bearings, suspension/ball joints/struts, wipers/washers, brakes, HVAC.
I've seen claims by Tesla that their brakes never need service due to the fact they're barely used. Not sure how accurate that is, but it's sort of logical.
Sounds like BS. Even if you almost never use them, brake fluid has a finite life and needs to be replaced every few years. Brake systems are never perfectly hermetically sealed and brake fluid is hygroscopic.
Rust is usually rubbed off when the brakes are engaged. Buildup on any vehicle is only really an issue when the vehicle sits undriven for long periods of time.
In EVs the brakes are engaged, just less frequently and with less force. For example in a normal car when you depress the brake pedal gently to slow to a normal stop the brakes engage immediately. In an EV the regenerative braking force increases when you depress the brake pedal and only after it has hit 100% do the brakes engage.
So with an ICE vehicle the brakes are the primary stopping force most of the time where as with an EV they're the secondary stopping force most of the time.
I think he may be referring to rust inside the brake lines. I've seen it before on an older vehicle that probably never had its brake fluid changed. Over time, moisture gets into the system and corrodes the steel brake lines, causing rust to get into the fluid. It's why you have to change the fluid every so often: it's impossible to keep moisture out, and the fluid is hygroscopic.
Please stop getting involved in flamewars about brakes or otherwise. Tedious back and forths like https://news.ycombinator.com/item?id=19001513 are something we're trying to avoid here.
Please don't engage in nasty spats on HN. If you think someone's behaving abusively, let us know at hn@ycombinator.com, and avoid breaking the site guidelines yourself.
Electric drivetrains are just so simple compared to ICE that it seems hard to fuck up. I mean, I'm sure Toyota will think about it more than I have, but that's one of the major benefits of this shift towards battery vehicles.
Tesla is in an interesting position where they have a lot of apologists for various kinds of problems that no other automaker gets. I don't think their experience is necessarily indicative of how an entranched, reliable automaker's EV experience will shake out.
Perhaps, but it's not like there's a lot of other examples of battery EVs out there to compare with, just the Leaf and the Bolt really. There's also the motors in the Volt and Prius (which are both capable of running motor-only, and for the Volt the motor provides all the propulsion). But you have a point, none of those others have had any motor problems I've heard of. Thought to be fair, the Tesla motors are a lot more powerful than those in any of those other cars.
EVs are dramatically simplified in comparison to ICE vehicles and thus the power-train is much more reliable. For any automaker this increased reliability is only going to help their reputation.
This poses a problem for Toyota and others (e.g. Honda) who are known for having very reliable power-trains, not because their reliability will suffer but rather because other automaker's power-trains will get significantly better. That is assuming those other automakers don't find a way to screw up, I have no doubt some will.
I'm concerned like this a quite a blanket statement. Are all EVs that much simpler? There are simple EV drivetrains and there are complex EV drivetrains. Not all EV drivetrains are the same.
This also applies to ICE. Most ICE drivetrains that do not have forced induction tend to be quite simple. Forced induction makes the drivetrain much more complex and puts a lot more strain on the drivetrain, and is one of the reasons why Toyota has stayed away from forced induction.
Is the drive train in a Tesla Model X P100d much simpler than that in a 1.5 NA Yaris? I'm not sure, and would love to be proved incorrect on this.
Internal Combustion Engines have at a minimum a Combustion System, Ignition System, Fuel Delivery System, Exhaust System, and a Cooling System. These can vary in complexity but, apart from air cooling, any one of those systems will be more complex than an EV's electric power-train. On top of that, most of the parts of an ICE are mechanical moving parts where as most of the parts of an electric motor are stationary non-moving parts.
ICE vehicles almost universally have a transmission gear box that contains a configurable gear system to alter the gear ratio of the vehicle. All EVs on the market use a fixed gear box with a single reduction gear set.
> Is the drive train in a Tesla Model X P100d much simpler than that in a 1.5 NA Yaris?
Where are the complex EV drivetrains? It isn't remotely the same thing as ICE. Even the most reliable ICE drivetrains are extremely complex. Toyota just uses conservative and overbuilt ICE technology to achieve remarkable reliability. That's fine, but still has tons of moving parts compared to electric drivetrains.
Does Steve need an ad to remind him that he likes the BMW 3 series? No doubt one of the first steps he took after his promotion was look up the prices, or finance offers on BMW 3 series, perhaps create a spec and then talk to his partner about it if he has o e.
The thing is if there is something I want to buy, or own at some point in my life, I don't tend to forget about it or need some reminder from a targeted ad. If it's something I really want I'll usually think about it daily.
On the other hand, there could be something that I need, and have never searched for, that I have forgotten about such as going out and buying more toilet roll.
Maybe that'll give him a slight nudge toward buying the thing he was already going to buy, but how valuable is that nudge? BMW has a lot more to gain by providing that info to someone who isn't already into their cars.
You don't make these decisions in one go. One ad doesn't make someone who isn't into cars go out and buy a BMW. The money is in tipping someone who's been thinking about getting a BMW for a while over the edge.
I wasn't talking about people who aren't into cars at all. I was talking about people who aren't into BMWs in particular. If I'm about to spend a lot of money on a car, I'd think that BMW would want me to know about theirs.
One thing I don't like about Rust is how taking a slice of a string can cause a runtime panic if the start or end of the slice ends up intersecting a multi-byte UTF-8 char.
I would prefer it if this feature didn't exist at all rather than cause runtime panics.
It's not a problem in practice, because you'd use something like `.char_indices()` iterator, or result from a substring search, etc. to get correct offsets in the first place.
It's not useful to blindly read at random offsets in UTF-8 strings. If it didn't panic, you'd get garbage. If offsets were automatically moved to skip over garbage, you wouldn't know what you're getting, and your overall algorithm would likely end up with nonsense (duplicated or skipped chars).
For algorithms that don't care about characters or UTF-8 validity, there's zero-cost `.as_bytes()`.
Couldn't syntax like `a_string[..3]` be made to result in compilation errors in Rust? Since that'd almost always be a bug? (right?)
And in the rare cases, when it's not a bug, then one can just use `as_bytes` which would be good to do in any case, to indicate to other humans that this is not a bug.
B.t.w. I love the error message `[..3]` generates: "thread 'main' panicked at 'byte index 3 is not a char boundary; it is inside '早' (bytes 2..5) of `ab早`'" — I've never seen such easy to understand error messages in any language (except for in a few cases in Scala).
What does zero-cost mean in this context? It must cost something to run, no? Or is it basically a compiler hint instructing the next function to treat the data as pure bytes?
In this particular context, you can think of going from a `&str` to a `&[u8]` via `string.as_bytes()` as a safe cast. The in-memory representation remains the same, and the function call will almost certainly be inlined because its implementation is trivial.
It is a common pattern in Rust to use [] for things that cannot fail and will panic otherwise and a method for things that can fail and return Option or Result.
e.g. my_hashmap["foo"] will panic at runtime if the key "foo" is not present, or return the associated value if it is. But my_hashmap.get("foo") will return None if "foo" is not present and Some(value) if it is.
What's the point of the [] version then? It seems inherently more dangerous, and Rust emphasizes safety. I know it wants to be pragmatic as well as safe, but this seems like a strange default.
First of all, panics are perfectly safe. None of this has to do with safety guarantees.
Second, the [] syntax is controlled by the Index trait, which returns an &T, not an Option<&T>. It does this due to Rust's error handling philosophy. There's two kinds of errors: recoverable and unrecoverable errors. When something shouldn't fail, unless there's a bug, you shouldn't be using Option/Result, you should panic. When something may normally fail, and you want to be able to handle that explicitly, you should use Option/Result.
If [] always returned an Option, you'd be seeing tons and tons and tons of unwraps. It's not the right default here. However, that's why the .get method also exists: If you do think that this may fail, but not due to a bug, then you should use .get instead, which does give you an option.
TL;DR: everything is tradeoffs, and we picked a specific set of them, and that's how they all play out together.
Personal commentary: this is the kind of thing that's largely concerning until you actually use the language more, IMHO. Dealing with Options all the time here would feel really bad. Consider the other sub-thread about floats; it often feels like boilerplate for no good reason. That would introduce this for every single time you want to index something, which is a very common operation.
Does Rust support a monadic coding style (like Haskell "do" blocks or F# computation expressions)? That would allow you to work with Options without having to explicitly unwrap them.
Not generic monads, but it does have the `?` operator for Option (similar to Haskell Maybe) and Result (similar to Haskell Either) which would support a similar syntax to using `do` with the Maybe monad
Scala programmers would recognize this as the difference between () and .get(). I hope rust copied scalas syntax- its much cleaner, rather than trying to be nice to the established system languages (c/c++)
This would also free up the [] to be used for generics and avoid syntactical warts like ::<> parsin
This seems specious to me. The only way to get an invalid index in a string in any language is that you either have an array index arithmetic error or you are blindly operating on a string you haven't validated.
If you want all the data after a : character, you slice on the index of the :. The character after it is going to be the beginning of a UTF-8 character.
You do not under any circumstances guess that the colon is at position 6 in the string. That's not safe. Why are you going cowboy in a language that is so obsessed with safety?
I just realized that I have bug in my GPS driver. It operates on ASCII data, so [] operator is safe, BUT data can be corrupted (low chance, but non-zero), so it can form valid multibyte character, so my code will panic on it, trying to parse and validate NMEA message.
Truncating a string to fit in a fixed-size storage field is probably the most common reason to split at a particular byte position. If you’re throwing data away anyway, you probably don’t care too much about the little bit of corruption.
Granted, this is certainly incorrect but has little to do with safety, especially if the downstream code has to revalidate everything anyway.
String slicing using byte indices has to exist in some form, since it is the only thing that is efficient (O(1)). But, I guess it could have used syntax other than somestring[...].
That means one loses all the conveniences and guarantees of the string types and, in many cases, forces an immediate revalidation the byte slice as UTF-8 to get back to &str, which is O(n). Furthermore, this is also rather clunky.
I suppose one could have it return StrWithInvalidSurrounds, where just the first (at most) 3 and last (at most) 3 bytes might be invalid, which would then allow for O(1) revalidation to a &str, and even other operations like continuing to slice... But this is even more clunky for actual use!
I think a moderately less clunky API might have been to not use integers for byte indexing, but instead some ByteIndex wrapper type that string operations return, meaning one can't just write `s[..5]` in an attempt to get the first 5 characters of the string.
Does this bug exist because it would be too expensive to check every string before slicing? (Being Rust-ignorant), can you not type a binary as UTF-8? Are there 2 versions of string functions, fast ones that assume ASCII and slow ones that assume UTF-8?
Every string is checked. But UTF8 is a multi-byte encoding, and slicing works per bytes, so you if you slice in the middle of a multi-byte character, you may get nonsense. The error happens because of this checking, not in spite of it.
String always assumes full UTF-8. You could make an AsciiString type if you wanted, but it's not provided by the standard library.
The obvious follow up question would be: so why is slicing a string a byte-wise operation and not a character-wise operation? If a string is an array of characters, why does it let me refer to individual bytes without explicitly casting it to a byte array? How often comparatively do you want the nth byte compared to the nth character? I would suspect that's pretty rare.
> How often comparatively do you want the nth byte compared to the nth character? I would suspect that's pretty rare.
It's exactly the opposite of what you expect. Getting the nth codepoint is often (not always) semantically incorrect since a codepoint isn't necessarily one character. Multiple codepoints might combine to form one character. (In Unicode, these are called grapheme clusters.)
Byte offsets are used a ton because you might often have the index to a position in the string from some routine, like, say, a search[1].
I've been working on text related things in both Rust and Go for several years. Both languages got this part of their strings exactly right given that their representation in memory is always a sequence of bytes.
I still think that using the common [] operator for this is a mistake. Strings shouldn't offer [] at all, and instead should provide methods like codepoints(), bytes(), grapheme_clusters() etc for indexing, slicing, and iterating.
The reason being that the behavior of [] for string varies widely in different languages, and so this is something that's best made explicit, both to force the author of the code to consider whether their assumptions are valid and reasonable for what they're trying to do, and to give additional context to anyone else reading the code.
As it is, I suspect a common class of bugs for Rust will be with people assuming that [] slices codepoints, because it seems to work that way for ASCII.
I'm quite thankful that Rust has succinct notation for slicing strings. Do note that `string[n]` is not supported, so you'll stumble over an inconsistency in your mental model quite quickly if you think slicing is by codepoint.
The lack of direct indexing is a good point. But strings aren't sliced on byte boundaries all that often either - it's far more common to use higher-level APIs like split(), that deal with offsets under the hood, so that sugar mostly ends up being used in the implementation of such APIs. And, really, would something like s.slice_u8(x, y) be that unwieldy over s[x..y]?
How often do you actually want the nth character as opposed to the nth grapheme?
There is pretty much no case where indexing by character actually makes sense because it is almost always incorrect and it is always inefficient.
Indexing by byte is rarely useful, but it does have some usefulness since it can be used correctly and efficiently since you can easily find the next or previous character by searching a maximum of four bytes for the a byte that has a MSB of 0. If you want to do something like get a &str that would fit in a n-byte buffer, then byte indices will let you do that efficiently and correctly.
panics are safe. You expect the “I don’t have a bug” case to be fast.
You can, but it depends on what you mean by “character”, as that’s not a concept in Unicode. Every kind of thing you could mean has a method, specific to it, since they’re different things.
(char in Rust is a Unicode scalar value, and you can collect into a Vec<char> and then slice it, as an example of one of those things. And that’s still O(1) at the cost of using up to four times the memory.)
It's not clear to me what you're suggesting; is it that String shouldn't have supported indexing in the first place? That code does work, but you have a &[u8] not a &str.
But neither AsciiString. It has a as_str method, but it's still a kludge.
This example was basically a suggestion to throw0u1t: if they want to cut in the middle of the utf-sequence for whatever reason, they can [edit:] do it without extra crates.
What I don't understand is why slices are indexed in bytes and not in objects. If String has an ability to check that we're cutting in the middle of the character sequence, why doesn't it provide an ability to take 3 fully formed characters.
I think the rust designers want to keep the implicit contract that indexing into a string is fast and O(1).
If you want to find the one millionth codepoint of a UTF8-encoded string, you have to more or less (1) visit every byte of the string.
If, on the other hand, you want to find the codepoint that covers the millionth byte, on the other hand, you have to read at most four bytes (read the millionth byte, and there are three cases:
- it’s a full codepoint. If so, you‘re done.
- it is the first byte of a multi-byte codepoint. If so, read forwards in the string for up to 3 continuation characters.
- it is a continuation character. If so, search backwards in the string for the first byte, then, if necessary, read forwards to find more continuation characters.
So, that is O(1)
(1) you can skip continuation characters, but these typically are rare.
It does: `s.chars().take(3)`. It just does it with iterators rather than with indexes because that better communicates the performance characteristics.
I think he's suggesting that slicing on strings should be by character, and if you want to slice on bytes, you should explicitly ask to treat the string as a byte array. It makes more sense semantically, and it's safe.
That seems like taking it too far. It's like using pointer arithmetic to index a linked list on the assumption that the nodes happen to be allocated contiguously in memory. I mean, I guess the thinking is, indexing a Unicode string isn't cheap, but indexing strings used to be cheap once upon a time, when strings were encoded in fixed one-byte-per-character representations, so let's pretend that's still the case and panic if it doesn't work out.... That's weirdly antithetical to Rust's purported focus on safety.
Also, you can get the same performance from an operation that returns a byte array instead of a string. If that kind of performance is what you want, then a Unicode string is simply not the right type to use.
Indexing a Unicode string is cheap... if you have a byte index. If you want to count out some fixed number of codepoints, then of course you've just moved the cost to calculating the corresponding byte index. But counting codepoints is almost always the wrong thing to do anyway [1]. In practice, it's more common to obtain indices by inspecting the string itself, e.g. searching for a substring or regex match. In that case, it's faster for the search to just return a byte index; there's no benefit to having it return a codepoint index, and then having to do an O(n) lookup when you try to use the index. And byte indices obtained that way will always be valid character boundaries, so you can use [] without worrying about panics.
You suggest just using a byte array instead, but then you'd lose the guarantee that what you're working with is valid Unicode. Contrary to your assertion, it is useful to have a type that provides that guarantee, yet which can still be operated on efficiently.
Panics are not unsafe. Panic exists in Rust because they are safe. If you don't want a panic on index, just don't index.
Indexing into a UTF-8 string doesn't serve any reasonable consistent purpose anyway, because it is an abstraction of text that doesn't provide support to the notion that a "character" is more fundamental than a word or paragraph, etc. Rust's string slicing exists solely to make ASCII text easy to handle. If your text is not ASCII, then you shouldn't be slicing it at all. Thus the panic.
Indexing into a UTF-8 string doesn't serve any reasonable consistent purpose anyway
If that's true, isn't it the job of a type system to help avoid such nonsensical operations? If "slice" only makes sense for byte arrays and ASCII strings, it could be provided on those types without being defined on UTF-8 strings.
Panics are not unsafe. Panic exists in Rust because they are safe.
That's "safe" by a very limited definition of safety. It's one step up from undefined behavior, granted, but it's not a very high standard. In practice, in most programs, you'd want to ensure that such a panic would never happen, and personally I think the language's unhelpfulness in that regard is a wart.
>If that's true, isn't it the job of a type system to help avoid such nonsensical operations?
It's not strictly true, because there are situations where you want to slice UTF-8. For instance, if you already know where the code point boundaries are for newlines. But if you know that, then you've run something like a regex with >O(1) behavior and you certainly wouldn't want string slicing to do redundant work.
>hat's "safe" by a very limited definition of safety
That's the definition of safe that is used. Safety in the context of Rust means memory safety. (Division can panic, btw.) If you don't see why undefined behavior is so much worse than a panic, then do some research on it. If you want programs that never fail, you need a comprehensive plan that takes into account things like hardware failure. A programming language can't do that.
Go indexes bytes on strings, even though there's a builtin type called Rune which delimits utf-8 codepoints. This is yet another footgun. Is there a language that doesn't handle this poorly?
In Rust, you're supposed to use `unicode-segmentation`[1] if you need to split on logical character (grapheme cluster in the Unicode standard). Otherwise, the iterators `.bytes` emits raw bytes, and `.chars` emits UTF-8 codepoints.
Basically, string indexing is a lot harder than it seems at first glance, depending on what you want.
One nitpick: `.chars`[1] gives you an iterable[2] of `char`s[3], each of which is always a 4 byte representation of a valid unicode character. This means that `"asdf".chars().collect()` will have a different size to `"asdf"` and `"asdf".chars().as_str()`. `.chars()` will never give you an incomplete codepoint, but it will give you incomplete characters, as you could have many c̶̼̟̏ó̷̘̉n̴̖̞̏̇t̸̡̃ĭ̸̻̬n̴̯͉̂͑ṵ̴̑a̷̛̫̳ẗ̸͕́i̷̱̫̓̋ǫ̸̑ǹ̶̼̅s̸̩̾̌ to represent what visually are a single char.
UTF-8 is at odds with efficient array indexing. I like pythons approach where bytes and strings are distinct types, though I have no idea what it is doing under the hood.
Modern Python uses whatever representation is sufficient to ensure 1-unit-per-codepoint for a given string (which it can do on creation, since strings are immutable). So you get ASCII, UTF-16 sans surrogate pairs, or UTF-32.
This is great for high-level code, but painful to work with from native code, because it usually needs some specific encoding to call into other libraries, and it's usually UTF-8 - so you need to re-encode all the time.
I actually had to work with Python strings at the C level recently, and their approach is pretty clever. IIRC, the runtime can take any common form of Unicode, and will store it. When you access that string, the accessor requests a specific encoding, and the runtime will convert if need be, and then store it in the string object.
So it handles the (very) common case of needing the same encoding multiple times (e.g. for all file paths on Windows), while not introducing too much overhead in memory or speed.
I could be mistaken on exact details though, especially since I recall there being multiple implementations even within py3.x.
i'd happily pay up to $1200 for a high spec 4" phone.
i'm on an SE. i got this phone fairly late into its life cycle and it was a deliberate choice. my biggest regret is probably not getting a second one before they discontinued it because when my current SE fails i have no idea where to get a replacement.
I'm shocked Apple doesn't fill this market. Many of my friends prefer SE-sized phones. I have friends who aren't upgrading from the SE specifically because they can't get a comparably-sized phone.
I bought my wife the XS, not because it has a fancier display, but purely because it was the smallest model available - and it's still too big for her.
Look on eBay; there are a lot of SE's available for a good price. It's a great time to buy one and save it for when you need it. At some point the supply will get low enough that the price for a new one will noticeably increase, but we aren't at that point yet.
I haven’t understood why Apple doesn’t simply do this. They know from the laptop market that people are more than willing to pay different prices for different t sizes.
Instead of differentiating their phones based on features, they should simply differentiate them based on screen size. That would allow them to meet several price points without making their customers feel like they’re cheap.
I think it's highly likely we'll see the SE return (or it's spritual successor).
Remember, the SE was released outside of the usual iPhone release cycle in March 2016, so I think intent for a longer cycle was clear.
Lots of people predicted between 2 and 3 years before the SE got an update, so if March 2019 passes without an announcement, then who knows what's next.
Also, I think there's a high probability they're trying to work out the kinks in an SE-sized phone that is all screen. I'd be surprised if they released the SE2 and it has a home button.
I would argue that the iPhone 8 should not exist, but neither should the most recent iPhones. Apple seems to be locked in a system of releasing a new phone(s) every year, but they can't actually deliver something that justifies a new model. This isn't a problem exclusive to Apple, it's just very clear with their product line up.
With the solve down in new features and design Apple could have skipped the iPhone 8, XS and XR. Except of cause "the market" and their stockholders expects new phones, regardless of the need.
The obvious answer is size. It's not that I can't carry an iPhone 7 in my hands or anything, but I just have no use for the bigger screen, so the extra bulk is literally useless. I still feel like the iPhone SE is the perfect phone form factor, and it's sad that there are basically no options for those of us who want one.
Imagine SE screen size, but edge-to-edge. That thing would be gorgeous — it would almost be as small as the phones we used to have back before smartphones, when anything bigger than about 4" was derided as a 'brick'.
For me, it's the size and headphone jack. Android vs. iOS doesn't matter much, but Apple was the only company still offering a phone that fits my two criteria.
Now I have 3 SEs (one with a broken screen that I'll get fixed, one currently in use, one still in the box) that will hopefully last me a while - maybe the phone market returns to sensible sizes & features in a few years.
I’m not being funny. I treat every phone I’ve ever owned as the expensive devices they are. I buy a protective case, don’t put it in my back pocket where it can be bent or broken. I don’t use it while standing over the toilet so it can’t be dropped in. When I drink with friends, I don’t lay my phone on the bar where some drunk can spill beer on it.
It’s more than being able to have the use of a fully functioning device, at trade-in time my phone is worth more because I take of it.
I treat my phones the same, and I thought "I'll never drop this", until you do.
Both times I've dropped the phone getting in or out of the car. First time it landed face first on the garage floor and shattered the screen and the second time it landed on its side and just scratched the case a little.
Hard to know what will happen when you drop your phone.
> Hard to know what will happen when you drop your phone.
I find this is the real problem. I've had phones that I've dropped many, many times, onto hard surfaces, that have come away without a scratch. Then I dropped a Nokia 3 and the screen just flew apart.
The iPhone 6 and beyond are too big for my tastes. I reluctantly upgraded to an iPhone 7 after destroying my SE. Even after owning the 7 for over a year, I find it uncomfortably large at times.
I’ve had an SE for almost 3 years and would prefer a similarly sized and priced model for my next phone. I don’t want a giant phone or to pay $1000 for it.
Yes, but first one has to know that that this difference exists. Then, there may be other differences that are considered more important by a specific individual. That’s why I asked.
It is not my first time hearing that some individuals may prefer a smaller phone, and you’re correct. I don’t find that difficult to understand.
Unfortunately even last years models do not support LTE band 71, so they are a poor choice for T-Mobile US customers. No dual SIM support is another reason for many.
Technically I'm not supposed to reveal the exact questions they ask because they have candidates sign an NDA that covers the questions they ask during an interview. But it really shouldn't be too surprising the type of questions they ask, basically similar to stuff you see on sites like Leetcode or books like Cracking the Coding interview. Although very heavy on trees and graphs as opposed to the easier linked list/string/array type problems. Since it was an embedded position, there was on interview round where they asked some stuff about device drivers and Linux Kernel internals. Overall I thought it was a pretty bad interview for how "smart" Google is supposed to be. I thought Amazon actually did a much better job with interview questions, although they were still very algorithm-heavy.
It depends on the home. I use 2.4GHz and disable 5GHz because it causes a lot of issues.
The latest issue I have is where the phone I'm writing this on keeps switching from 2.4 to 5GHz when in the bedroom. However, when it switches from 2.4 to 5 it becomes unusuable due to the poor SNR ratio. I wish I could pin it to 2.4GHz, instead I keep having to wait for it to drop the connection and renegotiate on 2.4GHz.